1
0
mirror of https://github.com/librenms/librenms-agent.git synced 2024-05-09 09:54:52 +00:00

131 lines
3.3 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
2015-11-10 10:58:24 +01:00
# Copyright (C) 2015 Mark Schouten <mark@tuxis.nl>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# See http://www.gnu.org/licenses/gpl.txt for the full license
import json
from subprocess import check_output
2015-11-10 10:58:24 +01:00
def cephversion():
cephv = (
check_output(["/usr/bin/ceph", "version"])
.decode("utf-8")
.replace("ceph version ", "")
)
major, minor = cephv.split(".")[0:2]
return [int(major), int(minor)]
2015-11-10 10:58:24 +01:00
def cephdf():
cephdf = (
check_output(["/usr/bin/ceph", "-f", "json", "df"])
.decode("utf-8")
.replace("-inf", "0")
)
2015-11-10 10:58:24 +01:00
s = json.loads(cephdf)
try:
ts = s["stats"]["total_bytes"]
except KeyError:
ts = s["stats"]["total_space"]
try:
tu = s["stats"]["total_used_bytes"]
except KeyError:
tu = s["stats"]["total_used"]
try:
ta = s["stats"]["total_avail_bytes"]
except KeyError:
ta = s["stats"]["total_avail"]
print("c:%i:%i:%i" % (ts, tu, ta))
2015-11-10 10:58:24 +01:00
for p in s["pools"]:
b = p["stats"]["bytes_used"]
a = p["stats"]["max_avail"]
o = p["stats"]["objects"]
print("%s:%i:%i:%i" % (p["name"], a, b, o))
2015-11-10 10:58:24 +01:00
def osdperf():
global major
osdperf = (
check_output(["/usr/bin/ceph", "-f", "json", "osd", "perf"])
.decode("utf-8")
.replace("-inf", "0")
)
2015-11-10 10:58:24 +01:00
if major > 13:
for o in json.loads(osdperf)["osdstats"]["osd_perf_infos"]:
print(
"osd.%s:%i:%i"
% (
o["id"],
o["perf_stats"]["apply_latency_ms"],
o["perf_stats"]["commit_latency_ms"],
)
)
else:
for o in json.loads(osdperf)["osd_perf_infos"]:
print(
"osd.%s:%i:%i"
% (
o["id"],
o["perf_stats"]["apply_latency_ms"],
o["perf_stats"]["commit_latency_ms"],
)
)
2015-11-10 10:58:24 +01:00
def poolstats():
global major
poolstats = (
check_output(["/usr/bin/ceph", "-f", "json", "osd", "pool", "stats"])
.decode("utf-8")
.replace("-inf", "0")
)
2015-11-10 10:58:24 +01:00
for p in json.loads(poolstats):
try:
r = p["client_io_rate"]["read_bytes_sec"]
except KeyError:
2015-11-10 10:58:24 +01:00
r = 0
try:
w = p["client_io_rate"]["write_bytes_sec"]
except KeyError:
2015-11-10 10:58:24 +01:00
w = 0
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 KeyError:
2015-11-10 10:58:24 +01:00
o = 0
print("%s:%i:%i:%i" % (p["pool_name"], o, w, r))
2015-11-10 10:58:24 +01:00
major, minor = cephversion()
print("<<<app-ceph>>>")
print("<poolstats>")
2015-11-10 10:58:24 +01:00
poolstats()
print("<osdperformance>")
2015-11-10 10:58:24 +01:00
osdperf()
print("<df>")
2015-11-10 10:58:24 +01:00
cephdf()