892489acd7
This is the primary update that introduces collectd monitoring and sample storage into the influxdb database. Two new packages are introduced by this update - collectd-extensions package which includes - newly developed collectd platform memory, cpu and filesystem plugins - note that the example, ntpq and interface plugins are not complete and are not enabled by this update. - pmond process monitoring / recovery support for collectd - updated service file for pidfile management ; needed by pmond - influxdb-extensions package which includes - pmond process monitoring / recovery support for influxdb - updated service file for pidfile management ; needed by pmond - log rotate support for influxdb Change-Id: I06511fecb781781ed5491c926ad4b1273a1bc23b Signed-off-by: Jack Ding <jack.ding@windriver.com>
76 lines
1.6 KiB
Python
Executable File
76 lines
1.6 KiB
Python
Executable File
#
|
|
# Copyright (c) 2018 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
import os
|
|
import random
|
|
import collectd
|
|
|
|
PLUGIN = 'random number plugin'
|
|
|
|
# static variables
|
|
|
|
|
|
# define a class here that will persist over read calls
|
|
class ExampleObject:
|
|
hostname = ""
|
|
plugin_data = ['1', '100']
|
|
|
|
|
|
obj = ExampleObject()
|
|
|
|
|
|
# The config function - called once on collectd process startup
|
|
def config_func(config):
|
|
"""
|
|
Configure the plugin
|
|
"""
|
|
|
|
for node in config.children:
|
|
key = node.key.lower()
|
|
val = node.values[0]
|
|
|
|
if key == 'data':
|
|
obj.plugin_data = str(val).split(' ')
|
|
collectd.info("%s configured data '%d:%d'" %
|
|
(PLUGIN,
|
|
int(obj.plugin_data[0]),
|
|
int(obj.plugin_data[1])))
|
|
return 0
|
|
|
|
collectd.info('%s config function' % PLUGIN)
|
|
return 0
|
|
|
|
|
|
# The init function - called once on collectd process startup
|
|
def init_func():
|
|
|
|
# get current hostname
|
|
obj.hostname = os.uname()[1]
|
|
return 0
|
|
|
|
|
|
# The sample read function - called on every audit interval
|
|
def read_func():
|
|
|
|
# do the work to create the sample
|
|
low = int(obj.plugin_data[0])
|
|
high = int(obj.plugin_data[1])
|
|
sample = random.randint(low, high)
|
|
|
|
# Dispatch usage value to collectd
|
|
val = collectd.Values(host=obj.hostname)
|
|
val.plugin = 'example'
|
|
val.type = 'percent'
|
|
val.type_instance = 'used'
|
|
val.dispatch(values=[sample])
|
|
return 0
|
|
|
|
|
|
# register the config, init and read functions
|
|
collectd.register_config(config_func)
|
|
collectd.register_init(init_func)
|
|
collectd.register_read(read_func)
|