]>
git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/processor.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 import multiprocessing
26 from ..colours
import *
27 from ..constants
import *
29 class GraphTemplateProcessor(base
.GraphTemplate
):
34 _
= self
.locale
.translate
37 # Add all used CPU cycles
38 "CDEF:usage=user,nice,+,sys,+,wait,+,irq,+,sirq,+,steal,+,guest,+,guest_nice,+",
40 # Add idle to get the total number of cycles
41 "CDEF:total=usage,idle,+",
44 "COMMENT:%s" % EMPTY_LABEL
,
45 "COMMENT:%s" % (COLUMN
% _("Current")),
46 "COMMENT:%s" % (COLUMN
% _("Average")),
47 "COMMENT:%s" % (COLUMN
% _("Minimum")),
48 "COMMENT:%s\\j" % (COLUMN
% _("Maximum")),
50 "CDEF:usage_p=100,usage,*,total,/",
51 "COMMENT: %s" % (LABEL
% _("Total")),
52 "GPRINT:usage_p_cur:%s" % PERCENTAGE
,
53 "GPRINT:usage_p_avg:%s" % PERCENTAGE
,
54 "GPRINT:usage_p_min:%s" % PERCENTAGE
,
55 "GPRINT:usage_p_max:%s\\j" % PERCENTAGE
,
59 "CDEF:user_p=100,user,*,total,/",
60 "AREA:user_p%s:%s" % (CPU_USER
, LABEL
% _("User")),
61 "GPRINT:user_p_cur:%s" % PERCENTAGE
,
62 "GPRINT:user_p_avg:%s" % PERCENTAGE
,
63 "GPRINT:user_p_min:%s" % PERCENTAGE
,
64 "GPRINT:user_p_max:%s\\j" % PERCENTAGE
,
66 "CDEF:nice_p=100,nice,*,total,/",
67 "STACK:nice_p%s:%s" % (CPU_NICE
, LABEL
% _("Nice")),
68 "GPRINT:nice_p_cur:%s" % PERCENTAGE
,
69 "GPRINT:nice_p_avg:%s" % PERCENTAGE
,
70 "GPRINT:nice_p_min:%s" % PERCENTAGE
,
71 "GPRINT:nice_p_max:%s\\j" % PERCENTAGE
,
73 "CDEF:sys_p=100,sys,*,total,/",
74 "STACK:sys_p%s:%s" % (CPU_SYS
, LABEL
% _("System")),
75 "GPRINT:sys_p_cur:%s" % PERCENTAGE
,
76 "GPRINT:sys_p_avg:%s" % PERCENTAGE
,
77 "GPRINT:sys_p_min:%s" % PERCENTAGE
,
78 "GPRINT:sys_p_max:%s\\j" % PERCENTAGE
,
80 "CDEF:wait_p=100,wait,*,total,/",
81 "STACK:wait_p%s:%s" % (CPU_WAIT
, LABEL
% _("Wait")),
82 "GPRINT:wait_p_cur:%s" % PERCENTAGE
,
83 "GPRINT:wait_p_avg:%s" % PERCENTAGE
,
84 "GPRINT:wait_p_min:%s" % PERCENTAGE
,
85 "GPRINT:wait_p_max:%s\\j" % PERCENTAGE
,
87 "CDEF:irq_p=100,irq,*,total,/",
88 "STACK:irq_p%s:%s" % (CPU_IRQ
, LABEL
% _("Interrupt")),
89 "GPRINT:irq_p_cur:%s" % PERCENTAGE
,
90 "GPRINT:irq_p_avg:%s" % PERCENTAGE
,
91 "GPRINT:irq_p_min:%s" % PERCENTAGE
,
92 "GPRINT:irq_p_max:%s\\j" % PERCENTAGE
,
94 "CDEF:sirq_p=100,sirq,*,total,/",
95 "STACK:sirq_p%s:%s" % (CPU_SIRQ
, LABEL
% _("Soft Interrupt")),
96 "GPRINT:sirq_p_cur:%s" % PERCENTAGE
,
97 "GPRINT:sirq_p_avg:%s" % PERCENTAGE
,
98 "GPRINT:sirq_p_min:%s" % PERCENTAGE
,
99 "GPRINT:sirq_p_max:%s\\j" % PERCENTAGE
,
101 "CDEF:steal_p=100,steal,*,total,/",
102 "STACK:steal_p%s:%s" % (CPU_STEAL
, LABEL
% _("Steal")),
103 "GPRINT:steal_p_cur:%s" % PERCENTAGE
,
104 "GPRINT:steal_p_avg:%s" % PERCENTAGE
,
105 "GPRINT:steal_p_min:%s" % PERCENTAGE
,
106 "GPRINT:steal_p_max:%s\\j" % PERCENTAGE
,
108 "CDEF:guest_p=100,guest,*,total,/",
109 "STACK:guest_p%s:%s" % (CPU_GUEST
, LABEL
% _("Guest")),
110 "GPRINT:guest_p_cur:%s" % PERCENTAGE
,
111 "GPRINT:guest_p_avg:%s" % PERCENTAGE
,
112 "GPRINT:guest_p_min:%s" % PERCENTAGE
,
113 "GPRINT:guest_p_max:%s\\j" % PERCENTAGE
,
115 "CDEF:guest_nice_p=100,guest_nice,*,total,/",
116 "STACK:guest_nice_p%s:%s" % (CPU_GUEST_NICE
, LABEL
% _("Guest Nice")),
117 "GPRINT:guest_nice_p_cur:%s" % PERCENTAGE
,
118 "GPRINT:guest_nice_p_avg:%s" % PERCENTAGE
,
119 "GPRINT:guest_nice_p_min:%s" % PERCENTAGE
,
120 "GPRINT:guest_nice_p_max:%s\\j" % PERCENTAGE
,
122 "CDEF:idle_p=100,idle,*,total,/",
123 "STACK:idle_p%s" % CPU_IDLE
,
130 def graph_title(self
):
131 _
= self
.locale
.translate
132 return _("Processor Usage")
135 def graph_vertical_label(self
):
136 _
= self
.locale
.translate
140 class ProcessorObject(base
.Object
):
142 "DS:user:DERIVE:0:U",
143 "DS:nice:DERIVE:0:U",
145 "DS:idle:DERIVE:0:U",
146 "DS:wait:DERIVE:0:U",
148 "DS:sirq:DERIVE:0:U",
149 "DS:steal:DERIVE:0:U",
150 "DS:guest:DERIVE:0:U",
151 "DS:guest_nice:DERIVE:0:U",
154 def init(self
, cpu_id
=None):
159 if self
.cpu_id
is not None:
160 return "%s" % self
.cpu_id
168 stat
= self
.read_proc_stat()
170 if self
.cpu_id
is None:
171 values
= stat
.get("cpu")
173 values
= stat
.get("cpu%s" % self
.cpu_id
)
175 # Convert values into a list
176 values
= values
.split()
178 if not len(values
) == len(self
.rrd_schema
):
179 raise ValueError("Received unexpected output from /proc/stat: %s" % values
)
184 class ProcessorPlugin(base
.Plugin
):
186 description
= "Processor Usage Plugin"
188 templates
= [GraphTemplateProcessor
]
192 yield ProcessorObject(self
)
194 num
= multiprocessing
.cpu_count()
196 yield ProcessorObject(self
, cpu_id
=i
)