mirror of
https://github.com/librenms/librenms-agent.git
synced 2024-05-09 09:54:52 +00:00
Make this script Python 3 compatible (#311)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# Copyright (C) 2015 Mark Schouten <mark@tuxis.nl>
|
# Copyright (C) 2015 Mark Schouten <mark@tuxis.nl>
|
||||||
#
|
#
|
||||||
@@ -18,12 +18,12 @@ from subprocess import check_output
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
def cephversion():
|
def cephversion():
|
||||||
cephv = check_output(["/usr/bin/ceph", "version"]).replace('ceph version ', '')
|
cephv = check_output(["/usr/bin/ceph", "version"]).decode("utf-8").replace('ceph version ', '')
|
||||||
major, minor = cephv.split('.')[0:2]
|
major, minor = cephv.split('.')[0:2]
|
||||||
return [int(major), int(minor)]
|
return [int(major), int(minor)]
|
||||||
|
|
||||||
def cephdf():
|
def cephdf():
|
||||||
cephdf = check_output(["/usr/bin/ceph", "-f", "json", "df"]).replace('-inf', '0')
|
cephdf = check_output(["/usr/bin/ceph", "-f", "json", "df"]).decode("utf-8").replace('-inf', '0')
|
||||||
|
|
||||||
s = json.loads(cephdf)
|
s = json.loads(cephdf)
|
||||||
try:
|
try:
|
||||||
@@ -50,7 +50,7 @@ def cephdf():
|
|||||||
|
|
||||||
def osdperf():
|
def osdperf():
|
||||||
global major
|
global major
|
||||||
osdperf = check_output(["/usr/bin/ceph", "-f", "json", "osd", "perf"]).replace('-inf', '0')
|
osdperf = check_output(["/usr/bin/ceph", "-f", "json", "osd", "perf"]).decode("utf-8").replace('-inf', '0')
|
||||||
|
|
||||||
if major > 13:
|
if major > 13:
|
||||||
for o in json.loads(osdperf)['osdstats']['osd_perf_infos']:
|
for o in json.loads(osdperf)['osdstats']['osd_perf_infos']:
|
||||||
@@ -61,33 +61,33 @@ def osdperf():
|
|||||||
|
|
||||||
def poolstats():
|
def poolstats():
|
||||||
global major
|
global major
|
||||||
poolstats = check_output(["/usr/bin/ceph", "-f", "json", "osd", "pool", "stats"]).replace('-inf', '0')
|
poolstats = check_output(["/usr/bin/ceph", "-f", "json", "osd", "pool", "stats"]).decode("utf-8").replace('-inf', '0')
|
||||||
|
|
||||||
for p in json.loads(poolstats):
|
for p in json.loads(poolstats):
|
||||||
try:
|
try:
|
||||||
r = p['client_io_rate']['read_bytes_sec']
|
r = p['client_io_rate']['read_bytes_sec']
|
||||||
except:
|
except:
|
||||||
r = 0
|
r = 0
|
||||||
try:
|
try:
|
||||||
w = p['client_io_rate']['write_bytes_sec']
|
w = p['client_io_rate']['write_bytes_sec']
|
||||||
except:
|
except:
|
||||||
w = 0
|
w = 0
|
||||||
try:
|
try:
|
||||||
if major > 11:
|
if major > 11:
|
||||||
o = p['client_io_rate']['read_op_per_sec'] + p['client_io_rate']['write_op_per_sec']
|
o = p['client_io_rate']['read_op_per_sec'] + p['client_io_rate']['write_op_per_sec']
|
||||||
else:
|
else:
|
||||||
o = p['client_io_rate']['op_per_sec']
|
o = p['client_io_rate']['op_per_sec']
|
||||||
except:
|
except:
|
||||||
o = 0
|
o = 0
|
||||||
|
|
||||||
print("%s:%i:%i:%i" % (p['pool_name'], o, w, r))
|
print("%s:%i:%i:%i" % (p['pool_name'], o, w, r))
|
||||||
|
|
||||||
major, minor = cephversion()
|
major, minor = cephversion()
|
||||||
|
|
||||||
print "<<<app-ceph>>>"
|
print ("<<<app-ceph>>>")
|
||||||
print "<poolstats>"
|
print ("<poolstats>")
|
||||||
poolstats()
|
poolstats()
|
||||||
print "<osdperformance>"
|
print ("<osdperformance>")
|
||||||
osdperf()
|
osdperf()
|
||||||
print "<df>"
|
print ("<df>")
|
||||||
cephdf()
|
cephdf()
|
||||||
|
|||||||
Reference in New Issue
Block a user