Skip to content

Instantly share code, notes, and snippets.

@ftnk
Created April 14, 2013 21:41
Show Gist options
  • Save ftnk/5384347 to your computer and use it in GitHub Desktop.
Save ftnk/5384347 to your computer and use it in GitHub Desktop.
python-munin (http://samuelks.com/python-munin/) を使って、 munin plugin を書いてみた
#!/usr/bin/python
# python-munin (http://samuelks.com/python-munin/) を使って、
# cpu 使用率の plugin を書いてみた
import commands
from munin import MuninPlugin
class CPUPlugin(MuninPlugin):
title = "cpu usage (test)"
args = "--base 1000 -l 0"
vlabel = "cpu usage"
scale = False
category = "system"
@property
def fields(self):
return [
("kernel", dict(
label = "system",
draw = "AREA",
min = "0",
type = "DERIVE",
)),
("user", dict(
label = "user",
draw = "STACK",
min = "0",
type = "DERIVE",
)),
("wait", dict(
label = "wait",
draw = "STACK",
min = "0",
type = "DERIVE",
)),
("idle", dict(
label = "idle",
draw = "STACK",
min = "0",
type = "DERIVE",
)),
]
def execute(self):
stats = commands.getoutput(
"kstat -p -c misc -m cpu_stat -s '/^(user|kernel|wait|idle)$/'")
values = {'idle':0, 'kernel':0, 'user':0, 'wait':0 }
for i in stats.splitlines():
key, value = i.split(':')[-1].split('\t')
values[key] += int(value)
return values
if __name__ == "__main__":
CPUPlugin().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment