Git Product home page Git Product logo

snap-plugin-lib-py's Introduction

DISCONTINUATION OF PROJECT.

This project will no longer be maintained by Intel.

This project has been identified as having known security escapes.

Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project.

Intel no longer accepts patches to this project.

Snap Plugin Library for Python

This is a library for writing plugins in Python for the Snap telemetry framework.


  1. Brief overview of Snap architecture
  2. Writing a plugin
  3. Example plugins
  4. Plugin diagnostics

Brief overview of Snap architecture

For an overview of Snap checkout: http://snap-telemetry.io/

Snap is an open and modular telemetry framework designed to simplify the collection, processing and publishing of data through a single HTTP based API. Plugins provide the functionality of collection, processing and publishing and can be loaded/unloaded, upgraded and swapped without requiring a restart of the Snap daemon.

A Snap plugin is a program that responds to a set of well defined gRPC services with parameters and return types specified as protocol buffer messages (see plugin.proto). The Snap daemon handshakes with the plugin over stdout and then communicates over gRPC.

Writing a plugin

For reference on authoring plugins see library's documentation.

Before writing a Snap plugin

If you do decide to write a plugin, open a new issue following the plugin wishlist guidelines and let us know you are working on one!

Example plugins

You will find example plugins that cover the basics for writing collector, processor, and publisher plugins in the examples folder.

Plugin diagnostics

Snap collector plugins using lib-py can be run independent of Snap to show their current running diagnostics.

To run diagnostic simply execute your plugin (just make sure all dependencies are met in your environment).

Diagnostic information includes:

  • Runtime details
    • Plugin name and version
    • RPC type and version
    • OS, architecture
    • Python version
  • Config policy
    • Warning if config items required and not provided
  • Collectible metrics and their current values
  • How long it took to run each of these diagnostics

Custom config

While running diagnostic you might (or must, if plugin requires it) specify additional config for plugin.

To do so you can run your plugin with --config flag and provide valid JSON argument. For example:

./myplugin.py --config '{"key": "value", "answer": "42"}'

Custom flags

You can also specify your own CLI flags to change behaviour of your plugin while running diagnostics.

Flag format

Flag uses following format: (name, type, description, (optional) default value):

name: name of your flag under which it will be accessible to use

Note: To access values of flags with names containing hyphens - you need to replace them with underscore _.

type: value of enum snap_plugin.v1.plugin.FlagType which indicate if your flag should act as a bool toggle, or store value

description: description for your flag visible while using --help option

default value: default value for your flag, which will be available if user doesn't specify any value

Adding flags

Flags must be added in your plugin's constructor, after calling superclass constructor.

To add your flag you can use methods add and add_multiple of object self._flags:

import snap_plugin.v1 as snap

class MyPlugin(snap.Collector):
    def __init__(self, *args, **kwargs):
        super(MyPlugin, self).__init__(*args, **kwargs)
        self._flags.add('require-config', snap.plugin.FlagType.toggle, 'require additional config')
        self._flags.add_multiple([('stand-alone', snap.plugin.FlagType.toggle, 'enable stand alone mode'), ('port', FlagType.value, 'port to run on', 8080)])

Accessing flag values

Flag values can be accessed at self._args object:

if self._args.require_config:
    # note changing hyphen to underscore in flag name when accessing it
    pass

As always, if you have any questions, please reach out to the Snap team via Slack or by opening an issue in Github.

snap-plugin-lib-py's People

Contributors

jcooklin avatar kdembler avatar mathmonsterx avatar nguyenddn avatar patrykmatyjasek avatar rdower avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snap-plugin-lib-py's Issues

Unable to add dynamic namespace element

I tried adding a dynamic namespace element to the example collector (rand.py):

                namespace=[
                    snap.NamespaceElement(value="random"),
                    snap.NamespaceElement(name="gen",description='a dynamic element'),
                    snap.NamespaceElement(value=key)
                ],

and get the following when trying to load it:
A static element should not define name gen for namespace /random//float64

Printing metric.config fails

Trying to print metric.config fails:

  File "/tmp/149768434/rootfs/.venv/lib/python3.5/site-packages/snap_plugin/v1/config_map.py", line 85, in __repr__  _module=plugin-exec io=stderr plugin=jolokia
    self._pb.FloatMap.items() + self._pb.BoolMap.items())  _module=plugin-exec io=stderr plugin=jolokia
TypeError: unsupported operand type(s) for +: 'ItemsView' and 'ItemsView'  _module=plugin-exec io=stderr plugin=jolokia

This sum in repr method is incorrect:
https://github.com/intelsdi-x/snap-plugin-lib-py/blob/master/snap_plugin/v1/config_map.py#L84

The health monitor doesn't work

2016-11-18 20:18:45,977 - snap_plugin.v1.plugin - DEBUG - plugin start called..
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Users/jrcookli/.pyenv/versions/3.5.2/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/Users/jrcookli/.pyenv/versions/3.5.2/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
TypeError: _monitor() missing 1 required positional argument: 'shutting_down'

        {"Type": 0, "ErrorMessage": null, "ListenAddress": "127.0.0.1:64301", "State": 0, "PublicKey": null, "Meta": {"Type": 0, "Name
        ": "rand-py", "Unsecure": true, "RoutingStrategy": 0, "Exclusive": false, "RPCType": 2, "CacheTTL": null, "ConcurrencyCount":
        5, "RPCVersion": 1, "Version": 1}, "Token": null}
        (snap35)

Setting a timestamp doesn't work

metric.timestamp = time.time() doesn't work as expected. For instance, doing this in a collect doesn't result in the timestamp being updated throughout the rest of the workflow.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.