]>
Commit | Line | Data |
---|---|---|
f37913e8 | 1 | #!/usr/bin/python3 |
eed405de MT |
2 | ############################################################################### |
3 | # # | |
4 | # collecty - A system statistics collection daemon for IPFire # | |
5 | # Copyright (C) 2012 IPFire development team # | |
6 | # # | |
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. # | |
11 | # # | |
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. # | |
16 | # # | |
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/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
a116f2fb | 22 | |
f37913e8 MT |
23 | |
24 | from . import base | |
eed405de MT |
25 | |
26 | from ..i18n import _ | |
27 | ||
c968f6d9 MT |
28 | class GraphTemplateProcessor(base.GraphTemplate): |
29 | name = "processor" | |
eed405de | 30 | |
eb1ab05c MT |
31 | @property |
32 | def rrd_graph(self): | |
33 | _ = self.locale.translate | |
34 | ||
35 | return [ | |
36 | "DEF:user=%(file)s:user:AVERAGE", | |
37 | "DEF:nice=%(file)s:nice:AVERAGE", | |
38 | "DEF:sys=%(file)s:sys:AVERAGE", | |
39 | "DEF:idle=%(file)s:idle:AVERAGE", | |
40 | "DEF:wait=%(file)s:wait:AVERAGE", | |
41 | "DEF:irq=%(file)s:irq:AVERAGE", | |
42 | "DEF:sirq=%(file)s:sirq:AVERAGE", | |
43 | ||
44 | "AREA:user#90EE90:%-15s" % _("User"), | |
45 | "VDEF:usermin=user,MINIMUM", | |
46 | "VDEF:usermax=user,MAXIMUM", | |
47 | "VDEF:useravg=user,AVERAGE", | |
48 | "GPRINT:usermax:%12s\:" % _("Maximum") + " %6.2lf" , | |
49 | "GPRINT:usermin:%12s\:" % _("Minimum") + " %6.2lf", | |
50 | "GPRINT:useravg:%12s\:" % _("Average") + " %6.2lf\\n", | |
51 | ||
52 | "STACK:nice#4169E1:%-15s" % _("Nice"), | |
53 | "VDEF:nicemin=nice,MINIMUM", | |
54 | "VDEF:nicemax=nice,MAXIMUM", | |
55 | "VDEF:niceavg=nice,AVERAGE", | |
56 | "GPRINT:nicemax:%12s\:" % _("Maximum") + " %6.2lf" , | |
57 | "GPRINT:nicemin:%12s\:" % _("Minimum") + " %6.2lf", | |
58 | "GPRINT:niceavg:%12s\:" % _("Average") + " %6.2lf\\n", | |
59 | ||
60 | "STACK:sys#DC143C:%-15s" % _("System"), | |
61 | "VDEF:sysmin=sys,MINIMUM", | |
62 | "VDEF:sysmax=sys,MAXIMUM", | |
63 | "VDEF:sysavg=sys,AVERAGE", | |
64 | "GPRINT:sysmax:%12s\:" % _("Maximum") + " %6.2lf" , | |
65 | "GPRINT:sysmin:%12s\:" % _("Minimum") + " %6.2lf", | |
66 | "GPRINT:sysavg:%12s\:" % _("Average") + " %6.2lf\\n", | |
67 | ||
68 | "STACK:wait#483D8B:%-15s" % _("Wait"), | |
69 | "VDEF:waitmin=wait,MINIMUM", | |
70 | "VDEF:waitmax=wait,MAXIMUM", | |
71 | "VDEF:waitavg=wait,AVERAGE", | |
72 | "GPRINT:waitmax:%12s\:" % _("Maximum") + " %6.2lf" , | |
73 | "GPRINT:waitmin:%12s\:" % _("Minimum") + " %6.2lf", | |
74 | "GPRINT:waitavg:%12s\:" % _("Average") + " %6.2lf\\n", | |
75 | ||
76 | "STACK:irq#DAA520:%-15s" % _("Interrupt"), | |
77 | "VDEF:irqmin=irq,MINIMUM", | |
78 | "VDEF:irqmax=irq,MAXIMUM", | |
79 | "VDEF:irqavg=irq,AVERAGE", | |
80 | "GPRINT:irqmax:%12s\:" % _("Maximum") + " %6.2lf" , | |
81 | "GPRINT:irqmin:%12s\:" % _("Minimum") + " %6.2lf", | |
82 | "GPRINT:irqavg:%12s\:" % _("Average") + " %6.2lf\\n", | |
83 | ||
84 | "STACK:sirq#FFD700:%-15s" % _("Soft interrupt"), | |
85 | "VDEF:sirqmin=sirq,MINIMUM", | |
86 | "VDEF:sirqmax=sirq,MAXIMUM", | |
87 | "VDEF:sirqavg=sirq,AVERAGE", | |
88 | "GPRINT:sirqmax:%12s\:" % _("Maximum") + " %6.2lf" , | |
89 | "GPRINT:sirqmin:%12s\:" % _("Minimum") + " %6.2lf", | |
90 | "GPRINT:sirqavg:%12s\:" % _("Average") + " %6.2lf\\n", | |
91 | ||
92 | "STACK:idle#EFEFEF:%-15s" % _("Idle"), | |
93 | "VDEF:idlemin=idle,MINIMUM", | |
94 | "VDEF:idlemax=idle,MAXIMUM", | |
95 | "VDEF:idleavg=idle,AVERAGE", | |
96 | "GPRINT:idlemax:%12s\:" % _("Maximum") + " %6.2lf" , | |
97 | "GPRINT:idlemin:%12s\:" % _("Minimum") + " %6.2lf", | |
98 | "GPRINT:idleavg:%12s\:" % _("Average") + " %6.2lf\\n", | |
99 | ] | |
73db5226 | 100 | |
f181246a | 101 | lower_limit = 0 |
73db5226 | 102 | |
f181246a MT |
103 | @property |
104 | def graph_title(self): | |
eb1ab05c | 105 | _ = self.locale.translate |
39fe7862 | 106 | return _("Processor Usage") |
f181246a MT |
107 | |
108 | @property | |
109 | def graph_vertical_label(self): | |
eb1ab05c | 110 | _ = self.locale.translate |
f181246a | 111 | return _("Jiffies") |
eed405de | 112 | |
b1ea4956 | 113 | |
72364063 | 114 | class ProcessorObject(base.Object): |
b1ea4956 | 115 | rrd_schema = [ |
de090041 MT |
116 | "DS:user:DERIVE:0:U", |
117 | "DS:nice:DERIVE:0:U", | |
118 | "DS:sys:DERIVE:0:U", | |
119 | "DS:idle:DERIVE:0:U", | |
120 | "DS:wait:DERIVE:0:U", | |
121 | "DS:irq:DERIVE:0:U", | |
122 | "DS:sirq:DERIVE:0:U", | |
b1ea4956 MT |
123 | ] |
124 | ||
72364063 MT |
125 | @property |
126 | def id(self): | |
127 | return "default" | |
a116f2fb | 128 | |
72364063 | 129 | def collect(self): |
cc19aed8 | 130 | """ |
a116f2fb | 131 | Reads the CPU usage. |
cc19aed8 MT |
132 | """ |
133 | f = None | |
eed405de | 134 | |
cc19aed8 MT |
135 | try: |
136 | f = open("/proc/stat") | |
eed405de | 137 | |
cc19aed8 MT |
138 | for line in f.readlines(): |
139 | if not line.startswith("cpu"): | |
140 | continue | |
eed405de | 141 | |
cc19aed8 MT |
142 | columns = line.split() |
143 | if len(columns) < 8: | |
144 | continue | |
eed405de | 145 | |
f648421a | 146 | return ( |
cc19aed8 MT |
147 | columns[1], # user |
148 | columns[2], # nice | |
149 | columns[3], # sys | |
150 | columns[4], # idle | |
151 | columns[5], # wait | |
152 | columns[6], # irq | |
153 | columns[7], # sirq | |
f648421a | 154 | ) |
cc19aed8 MT |
155 | finally: |
156 | if f: | |
157 | f.close() | |
72364063 MT |
158 | |
159 | ||
160 | class ProcessorPlugin(base.Plugin): | |
161 | name = "processor" | |
162 | description = "Processor Usage Plugin" | |
163 | ||
c968f6d9 | 164 | templates = [GraphTemplateProcessor] |
72364063 | 165 | |
72364063 MT |
166 | @property |
167 | def objects(self): | |
168 | yield ProcessorObject(self) |