]>
git.ipfire.org Git - collecty.git/blob - collecty/plugins/cpu.py
2 ###############################################################################
4 # collecty - A system statistics collection daemon for IPFire #
5 # Copyright (C) 2012 IPFire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 from __future__
import division
28 class PluginCPU(base
.Plugin
):
30 description
= "CPU Usage Plugin"
33 "DS:user:GAUGE:120:0:U",
34 "DS:nice:GAUGE:120:0:U",
35 "DS:sys:GAUGE:120:0:U",
36 "DS:idle:GAUGE:120:0:U",
37 "DS:wait:GAUGE:120:0:U",
38 "DS:irq:GAUGE:120:0:U",
39 "DS:sirq:GAUGE:120:0:U",
40 "RRA:AVERAGE:0.5:1:2160",
41 "RRA:AVERAGE:0.5:5:2016",
42 "RRA:AVERAGE:0.5:15:2880",
43 "RRA:AVERAGE:0.5:60:8760",
46 _graph
= [ "DEF:user=%(file)s:user:AVERAGE",
47 "DEF:nice=%(file)s:nice:AVERAGE",
48 "DEF:sys=%(file)s:sys:AVERAGE",
49 "DEF:idle=%(file)s:idle:AVERAGE",
50 "DEF:wait=%(file)s:wait:AVERAGE",
51 "DEF:interrupt=%(file)s:interrupt:AVERAGE",
52 "AREA:user#ff0000:%-15s" % _("User"),
53 "VDEF:usermin=user,MINIMUM",
54 "VDEF:usermax=user,MAXIMUM",
55 "VDEF:useravg=user,AVERAGE",
56 "GPRINT:usermax:%12s\:" % _("Maximum") + " %6.2lf" ,
57 "GPRINT:usermin:%12s\:" % _("Minimum") + " %6.2lf",
58 "GPRINT:useravg:%12s\:" % _("Average") + " %6.2lf\\n",
59 "STACK:nice#ff3300:%-15s" % _("Nice"),
60 "VDEF:nicemin=nice,MINIMUM",
61 "VDEF:nicemax=nice,MAXIMUM",
62 "VDEF:niceavg=nice,AVERAGE",
63 "GPRINT:nicemax:%12s\:" % _("Maximum") + " %6.2lf" ,
64 "GPRINT:nicemin:%12s\:" % _("Minimum") + " %6.2lf",
65 "GPRINT:niceavg:%12s\:" % _("Average") + " %6.2lf\\n",
66 "STACK:sys#ff6600:%-15s" % _("System"),
67 "VDEF:sysmin=sys,MINIMUM",
68 "VDEF:sysmax=sys,MAXIMUM",
69 "VDEF:sysavg=sys,AVERAGE",
70 "GPRINT:sysmax:%12s\:" % _("Maximum") + " %6.2lf" ,
71 "GPRINT:sysmin:%12s\:" % _("Minimum") + " %6.2lf",
72 "GPRINT:sysavg:%12s\:" % _("Average") + " %6.2lf\\n",
73 "STACK:wait#ff9900:%-15s" % _("Wait"),
74 "VDEF:waitmin=wait,MINIMUM",
75 "VDEF:waitmax=wait,MAXIMUM",
76 "VDEF:waitavg=wait,AVERAGE",
77 "GPRINT:waitmax:%12s\:" % _("Maximum") + " %6.2lf" ,
78 "GPRINT:waitmin:%12s\:" % _("Minimum") + " %6.2lf",
79 "GPRINT:waitavg:%12s\:" % _("Average") + " %6.2lf\\n",
80 "STACK:interrupt#ffcc00:%-15s" % _("Interrupt"),
81 "VDEF:interruptmin=interrupt,MINIMUM",
82 "VDEF:interruptmax=interrupt,MAXIMUM",
83 "VDEF:interruptavg=interrupt,AVERAGE",
84 "GPRINT:interruptmax:%12s\:" % _("Maximum") + " %6.2lf" ,
85 "GPRINT:interruptmin:%12s\:" % _("Minimum") + " %6.2lf",
86 "GPRINT:interruptavg:%12s\:" % _("Average") + " %6.2lf\\n",
87 "STACK:idle#ffff00:%-15s" % _("Idle"),
88 "VDEF:idlemin=idle,MINIMUM",
89 "VDEF:idlemax=idle,MAXIMUM",
90 "VDEF:idleavg=idle,AVERAGE",
91 "GPRINT:idlemax:%12s\:" % _("Maximum") + " %6.2lf" ,
92 "GPRINT:idlemin:%12s\:" % _("Minimum") + " %6.2lf",
93 "GPRINT:idleavg:%12s\:" % _("Average") + " %6.2lf\\n", ]
96 def autocreate(cls
, collecty
, **kwargs
):
97 # Every system has got at least one CPU.
98 return cls(collecty
, **kwargs
)
107 f
= open("/proc/stat")
109 for line
in f
.readlines():
110 if not line
.startswith("cpu"):
113 columns
= line
.split()
127 full
= sum([int(e
) for e
in entry
])
129 for i
in range(len(entry
)):
130 entry
[i
] = int(entry
[i
]) * 100
131 entry
[i
] = "%s" % (entry
[i
] / full
)
133 entry
.insert(0, "%s" % self
.now
)
135 self
.data
.append(":".join(entry
))