First you change your collectd.conf file in ubuntu located at /etc/collectd/collectd.conf
uncomment these lines
<LoadPlugin python>
Globals true
</LoadPlugin>
Next uncomment these lines
<Plugin python> ModulePath "path to module" Import "file name" <Module file name> Test "This" </Module></Plugin>
Then add your python plugin file path to path to module and give your file name in import.
Then just write your python plugin
Then just write your python plugin
There are some main function you have to call in your python file to work with Collectd.
Example of python code:
If you want to write data in rrd format you have to use Collectd built in functions
Here is an example how to write data in rrd format
def reader(input_data=None):
Example of python code:
import collectd
def configer(confObj):
collectd.info('config called')
def init_fun():
collectd.info('my py module init called')
def reader(input_data=None):
collectd.info('reader called')
collectd.register_config(configer)
collectd.register_init(init_fun)
collectd.register_read(reader)
You see what ever string you give in collectd.info() in logs of CollectdIf you want to write data in rrd format you have to use Collectd built in functions
Here is an example how to write data in rrd format
def reader(input_data=None):
metric = collectd.Values()
metric.plugin = "Plugin Name"
metric.host = "localhost"
metric.interval = 10 //Time interval after which data saved
metric.type = "Type of data" //folder generate in rrd/hostname folder get this name
metric.values = [value] //value to write in rrd file
metric.dispatch() //in last use this method to dispatch and write you current entry in rrd file
0 comments:
Post a Comment