转载请说明出处:http://blog.csdn.net/cywosp/article/details/39701245
#!/usr/bin/env python # -*- coding: utf-8 -*- import random import time descriptors = list() def random_number_1(name): return int(random.uniform(5, 100)) + 10 def random_number_2(name): return int(random.randrange(50, 500)) def metric_init(params): global descriptors random.seed() print params d1 = { 'name': 'random_number_1', 'call_back': random_number_1, 'time_max': 90, 'value_type': 'uint', 'units': 'C', 'slope': 'both', 'format': '%u', 'description': 'Random a number', 'groups': 'example random' } d2 = { 'name': 'random_number_2', 'call_back': random_number_2, 'time_max': 90, 'value_type': 'uint', 'units': 'C', 'slope': 'both', 'format': '%u', 'description': 'Random a number', 'groups': 'example random' } descriptors = [d1, d2] return descriptors def metric_cleanup(): pass #This code is for debugging and unit testing if __name__ == '__main__': metric_init({}) while True: for d in descriptors: v = d['call_back'](d['name']) print ('value for %s is '+d['format']) % (d['name'], v) time.sleep(5)
modules {module {#这里的name值一定要与/usr/lib64/ganglia/python_modules/random_number.py的文件名保持一致,否则将无法正确运行name = "random_number"language = "python"}}
collection_group {collect_every = 2time_threshold = 90
metric {#这里的name值要与random_number.py中的d1里的name保持一致name = "random_number_1"title = "random number 1"value_threshold = 0}
metric {#这里的name值要与random_number.py中的d2里的name保持一致name = "random_number_2"title = "random number 2"value_threshold = 0}}
service gmond restartservice gmetad restartservice httpd restart
原文:http://blog.csdn.net/cywosp/article/details/39701245