/
loadavg
executable file
·44 lines (36 loc) · 1.31 KB
/
loadavg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
"""
Load average plugin for Munin.
Based on the default "load" plugin in Munin
First tries reading from /proc/loadavg if it exists. Otherwise, execute
`uptime` and parse out the load average.
"""
import os
from munin import MuninPlugin
class LoadAVGPlugin(MuninPlugin):
title = "Load average"
args = "--base 1000 -l 0"
vlabel = "load"
scale = False
category = "system"
@property
def fields(self):
warning = os.environ.get('load_warn', 10)
critical = os.environ.get('load_crit', 120)
return [("load", dict(
label = "load",
info = 'The load average of the machine describes how many processes are in the run-queue (scheduled to run "immediately").',
type = "GAUGE",
min = "0",
warning = str(warning),
critical = str(critical)))]
def execute(self):
if os.path.exists("/proc/loadavg"):
loadavg = open("/proc/loadavg", "r").read().strip().split(' ')
else:
from subprocess import Popen, PIPE
output = Popen(["uptime"], stdout=PIPE).communicate()[0]
loadavg = output.rsplit(':', 1)[1].strip().split(' ')[:3]
return dict(load=loadavg[1])
if __name__ == "__main__":
LoadAVGPlugin().run()