bundles/sshmon: better cpu check
This commit is contained in:
parent
2564f416c2
commit
7b6d811128
2 changed files with 16 additions and 11 deletions
|
@ -4,27 +4,30 @@ from re import findall
|
||||||
from subprocess import check_output
|
from subprocess import check_output
|
||||||
from sys import exit
|
from sys import exit
|
||||||
|
|
||||||
|
ITERATIONS = 10
|
||||||
|
|
||||||
try:
|
try:
|
||||||
top_output = None
|
top_output = None
|
||||||
|
|
||||||
for line in check_output(['top', '-b', '-n1', '-d1']).decode('UTF-8').splitlines():
|
top_output = check_output(rf"top -b -n{ITERATIONS} -d1 | grep -i '^%cpu'", shell=True).decode('UTF-8')
|
||||||
if line.lower().strip().startswith('%cpu'):
|
|
||||||
top_output = line.lower().split(':', 2)[1]
|
|
||||||
break
|
|
||||||
|
|
||||||
if not top_output:
|
|
||||||
print('%cpu not found in top output')
|
|
||||||
exit(3)
|
|
||||||
|
|
||||||
cpu_usage = {}
|
cpu_usage = {}
|
||||||
for value, identifier in findall('([0-9\.\,]{3,5}) ([a-z]{2})', top_output):
|
for value, identifier in findall('([0-9\.\,]{3,5}) ([a-z]{2})', top_output):
|
||||||
cpu_usage[identifier] = float(value.replace(',', '.'))
|
if identifier not in cpu_usage:
|
||||||
|
cpu_usage[identifier] = 0.0
|
||||||
|
cpu_usage[identifier] += float(value.replace(',', '.'))
|
||||||
|
|
||||||
|
output = []
|
||||||
|
for identifier, value_added in cpu_usage.items():
|
||||||
|
value = value_added / ITERATIONS
|
||||||
|
output.append(f"{value:.2f} {identifier}")
|
||||||
|
cpu_usage[identifier] = value
|
||||||
|
|
||||||
|
print(f"Average over {ITERATIONS} seconds: " + ", ".join(output))
|
||||||
|
|
||||||
warn = set()
|
warn = set()
|
||||||
crit = set()
|
crit = set()
|
||||||
|
|
||||||
print(top_output)
|
|
||||||
|
|
||||||
# steal
|
# steal
|
||||||
if cpu_usage['st'] > 10:
|
if cpu_usage['st'] > 10:
|
||||||
crit.add('CPU steal is {}% (>10%)'.format(cpu_usage['st']))
|
crit.add('CPU steal is {}% (>10%)'.format(cpu_usage['st']))
|
||||||
|
|
|
@ -19,6 +19,8 @@ defaults = {
|
||||||
'services': {
|
'services': {
|
||||||
'CPU': {
|
'CPU': {
|
||||||
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_cpu_stats',
|
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_cpu_stats',
|
||||||
|
# takes samples over 10 seconds
|
||||||
|
'vars.sshmon_timeout': 20
|
||||||
},
|
},
|
||||||
'LOAD': {
|
'LOAD': {
|
||||||
'command_on_monitored_host': '/usr/lib/nagios/plugins/check_load -r -w 4,2,1 -c 8,4,2',
|
'command_on_monitored_host': '/usr/lib/nagios/plugins/check_load -r -w 4,2,1 -c 8,4,2',
|
||||||
|
|
Loading…
Reference in a new issue