Last active
December 24, 2015 11:15
-
-
Save C-Otto/a9e4864dff1a2b167761 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/env python | |
import os | |
import sys | |
import time | |
import socket | |
import subprocess | |
import json | |
hostname = os.environ['COLLECTD_HOSTNAME'] if 'COLLECTD_HOSTNAME' in os.environ else socket.getfqdn() | |
interval = float(os.environ['COLLECTD_INTERVAL']) if 'COLLECTD_INTERVAL' in os.environ else 5 | |
def main(): | |
while True: | |
try: | |
function = "getnettotals" | |
jsonString = getJson(function) | |
for subkey in ["totalbytesrecv", "totalbytessent"]: | |
value = json.loads(jsonString)[subkey] | |
printValue("counter", function, subkey, value) | |
function = "getnetworkinfo" | |
jsonString = getJson(function) | |
subkey = "connections" | |
value = json.loads(jsonString)[subkey] | |
printValue("gauge", function, subkey, value) | |
except: | |
pass | |
sys.stdout.flush() | |
time.sleep(interval) | |
def getJson(function): | |
command = ["/usr/bin/bitcoinxt-cli", "-conf=/etc/bitcoinxt/bitcoin.conf", "-datadir=/var/lib/bitcoinxt", function] | |
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
value = proc.communicate()[0] | |
return value | |
def printValue(dstype, function, subkey, value): | |
print('PUTVAL "%s/bitcoin-bitcoin/%s-%s_%s" interval=%s N:%s' % (hostname, dstype, function, subkey, interval, value)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment