root / plugins / zeo / zeomonitor @ 189c81ee
Historique | Voir | Annoter | Télécharger (1,1 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
|
| 3 |
def safe(s): |
| 4 |
s = s.replace("-", "_")
|
| 5 |
s = s.replace(" ", "_")
|
| 6 |
s = s.replace(".", "_")
|
| 7 |
return s |
| 8 |
|
| 9 |
def config(data): |
| 10 |
for i in data: |
| 11 |
print "%s.label %s"%(safe(i[0]), i[0]) |
| 12 |
if i[0].startswith("Clients"):
|
| 13 |
pass |
| 14 |
else: |
| 15 |
print "%s.type DERIVE"%safe(i[0]) |
| 16 |
print "graph_title zeo %s per minute"%i[0] |
| 17 |
print "graph_args -l 0" |
| 18 |
print "graph_vlabel n" |
| 19 |
print "graph_period minute" |
| 20 |
print "graph_category ZEO" |
| 21 |
|
| 22 |
def get_data(): |
| 23 |
import sys |
| 24 |
from socket import socket, AF_INET, SOCK_STREAM |
| 25 |
field = sys.argv[0].split("_",1)[1]
|
| 26 |
s=socket(AF_INET, SOCK_STREAM) |
| 27 |
s.connect(("localhost", 8101))
|
| 28 |
data=s.recv(2048).split("\n")
|
| 29 |
s.close() |
| 30 |
data = [d.split(": ") for d in data [5:-2]]
|
| 31 |
if field: |
| 32 |
data = [ d for d in data if safe(d[0]) == field] |
| 33 |
return data |
| 34 |
|
| 35 |
def sample(data): |
| 36 |
for i in data: |
| 37 |
print "%s.value %s"%(i[0].replace(" ","_"),i[1])
|
| 38 |
|
| 39 |
def main(): |
| 40 |
import sys |
| 41 |
data = get_data() |
| 42 |
if 'config' in sys.argv: |
| 43 |
return config(data) |
| 44 |
sample(data) |
| 45 |
|
| 46 |
if __name__ == '__main__': |
| 47 |
main() |
