Created
January 14, 2017 19:21
-
-
Save descilla/1541f295aef05e4cec433804a04b5818 to your computer and use it in GitHub Desktop.
Script for getting isc-kea stats from control-socket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import socket,os,json | |
BUFF_SIZE = 1024 | |
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
s.connect("/var/kea/control.sock") | |
s.send('{"command":"statistic-get-all","arguments":{}}') | |
result = "" | |
part = s.recv(BUFF_SIZE) | |
while len(part) == BUFF_SIZE: | |
result += part | |
part = s.recv(1024) | |
result += part | |
json = json.loads(result) | |
resDict = {} | |
resDict[u'all_interfaces'] = dict([('total-addresses',0),('assigned-addresses',0),('declined-addresses',0),('declined-reclaimed-addresses',0),('reclaimed-leases',0),('reclaimed-declined-addresses',0)]) | |
for k,v in json["arguments"].iteritems(): | |
k = k.split('.') | |
interface = k[0].replace('subnet[','bat').replace(']','') | |
if len(k) != 2: | |
continue | |
if interface not in resDict: | |
resDict[interface] = dict() | |
resDict[interface][k[1]] = v[0][0] | |
resDict['all_interfaces'][k[1]] += v[0][0] | |
for k,v in resDict.iteritems(): | |
print(k,v) | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! This saved me a ton of time trying to get a proof of concept to work from.
I created a quick&dirty PHP script to convert statistics to graphite format, maybe others will find it useful. Doesn't reset counters or actually send to graphite, but that's easy enough to add on.
https://gist.github.com/tmalkowski/4f2d8f37dd5ab40fd4c6fcab75dbc2d0