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>
|
||||
#
|
||||
@@ -18,12 +18,12 @@ from subprocess import check_output
|
||||
import json
|
||||
|
||||
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]
|
||||
return [int(major), int(minor)]
|
||||
|
||||
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)
|
||||
try:
|
||||
@@ -50,7 +50,7 @@ def cephdf():
|
||||
|
||||
def osdperf():
|
||||
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:
|
||||
for o in json.loads(osdperf)['osdstats']['osd_perf_infos']:
|
||||
@@ -61,33 +61,33 @@ def osdperf():
|
||||
|
||||
def poolstats():
|
||||
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):
|
||||
try:
|
||||
try:
|
||||
r = p['client_io_rate']['read_bytes_sec']
|
||||
except:
|
||||
r = 0
|
||||
try:
|
||||
try:
|
||||
w = p['client_io_rate']['write_bytes_sec']
|
||||
except:
|
||||
w = 0
|
||||
try:
|
||||
try:
|
||||
if major > 11:
|
||||
o = p['client_io_rate']['read_op_per_sec'] + p['client_io_rate']['write_op_per_sec']
|
||||
else:
|
||||
o = p['client_io_rate']['op_per_sec']
|
||||
except:
|
||||
o = 0
|
||||
|
||||
|
||||
print("%s:%i:%i:%i" % (p['pool_name'], o, w, r))
|
||||
|
||||
major, minor = cephversion()
|
||||
|
||||
print "<<<app-ceph>>>"
|
||||
print "<poolstats>"
|
||||
print ("<<<app-ceph>>>")
|
||||
print ("<poolstats>")
|
||||
poolstats()
|
||||
print "<osdperformance>"
|
||||
print ("<osdperformance>")
|
||||
osdperf()
|
||||
print "<df>"
|
||||
print ("<df>")
|
||||
cephdf()
|
||||
|
||||
Reference in New Issue
Block a user