forked from evoila/collectsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
63 lines (46 loc) · 1.92 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
"""
This script is used to execute the collectd plugin from the command line
without collectd. It uses the mock of the collectd framework in collectd.py to
initialize the plugin as collectd would.
"""
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
import sys
import time
import collectsphere
from collectd import Conf
def main():
""" The plugin is initialized and executed once. This is intended for test
and dev and measures execution times. """
# This mocks the configuration of collectd. A proper example of a
# configuration file can be found in collectsphere.conf
children = []
children.append(Conf('Name', ('NAME',)))
children.append(Conf('Host', ('FQDN',)))
children.append(Conf('Port', ('443',)))
children.append(Conf('Username', ('USERNAME',)))
children.append(Conf('Password', ('PASSWORD',)))
children.append(Conf('Verbose', (True,)))
children.append(Conf('VerifyCertificate', (False,)))
children.append(Conf('UseFriendlyName', (False,)))
children.append(Conf('Host_Counters', ['cpu.usage,mem.usage,disk.usage',]))
children.append(Conf('VM_Counters', ['cpu.usage,mem.usage',]))
children.append(Conf('Inventory_Refresh_Interval', ('600',)))
conf = Conf(None, None, children)
# Configure and initialize the plugin
start_time = time.time()
collectsphere.configure_callback(conf)
collectsphere.init_callback()
elapsed_time = time.time() - start_time
sys.stderr.write("Conf/Init Time: " + str(elapsed_time) + "\n")
# sleep 10sec to give the inventory watch dog some time to refresh the inventory tree
time.sleep(10)
while True:
# Execute the plugin once
start_time = time.time()
collectsphere.read_callback()
elapsed_time = time.time() - start_time
sys.stderr.write("Read Time: " + str(elapsed_time) + "\n")
time.sleep(60)
if __name__ == "__main__":
main()