]>
git.ipfire.org Git - collecty.git/blob - src/collecty/plugins/processor.py
5eeb93c0f1207abc35d78c17a9bb78b9f28ed6bd
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 *
28 class GraphTemplateProcessor(base
.GraphTemplate
):
33 _
= self
.locale
.translate
36 # Add all used CPU cycles
37 "CDEF:usage=user,nice,+,sys,+,wait,+,irq,+,sirq,+,steal,+,guest,+,guest_nice,+",
39 # Add idle to get the total number of cycles
40 "CDEF:total=usage,idle,+",
42 "CDEF:user_p=100,user,*,total,/",
43 "AREA:user_p%s:%-15s" % (CPU_USER
, _("User")),
44 "GPRINT:user_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
45 "GPRINT:user_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
46 "GPRINT:user_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
48 "CDEF:nice_p=100,nice,*,total,/",
49 "STACK:nice_p%s:%-15s" % (CPU_NICE
, _("Nice")),
50 "GPRINT:nice_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
51 "GPRINT:nice_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
52 "GPRINT:nice_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
54 "CDEF:sys_p=100,sys,*,total,/",
55 "STACK:sys_p%s:%-15s" % (CPU_SYS
, _("System")),
56 "GPRINT:sys_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
57 "GPRINT:sys_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
58 "GPRINT:sys_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
60 "CDEF:wait_p=100,wait,*,total,/",
61 "STACK:wait_p%s:%-15s" % (CPU_WAIT
, _("Wait")),
62 "GPRINT:wait_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
63 "GPRINT:wait_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
64 "GPRINT:wait_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
66 "CDEF:irq_p=100,irq,*,total,/",
67 "STACK:irq_p%s:%-15s" % (CPU_IRQ
, _("Interrupt")),
68 "GPRINT:irq_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
69 "GPRINT:irq_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
70 "GPRINT:irq_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
72 "CDEF:sirq_p=100,sirq,*,total,/",
73 "STACK:sirq_p%s:%-15s" % (CPU_SIRQ
, _("Soft Interrupt")),
74 "GPRINT:sirq_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
75 "GPRINT:sirq_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
76 "GPRINT:sirq_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
78 "CDEF:steal_p=100,steal,*,total,/",
79 "STACK:steal_p%s:%-15s" % (CPU_STEAL
, _("Steal")),
80 "GPRINT:steal_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
81 "GPRINT:steal_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
82 "GPRINT:steal_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
84 "CDEF:guest_p=100,guest,*,total,/",
85 "STACK:guest_p%s:%-15s" % (CPU_GUEST
, _("Guest")),
86 "GPRINT:guest_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
87 "GPRINT:guest_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
88 "GPRINT:guest_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
90 "CDEF:guest_nice_p=100,guest_nice,*,total,/",
91 "STACK:guest_nice_p%s:%-15s" % (CPU_GUEST_NICE
, _("Guest Nice")),
92 "GPRINT:guest_nice_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
93 "GPRINT:guest_nice_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
94 "GPRINT:guest_nice_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
96 "CDEF:usage_p=100,usage,*,total,/",
97 "COMMENT: %-15s" % _("Usage"),
98 "GPRINT:usage_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
99 "GPRINT:usage_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
100 "GPRINT:usage_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
102 "CDEF:idle_p=100,idle,*,total,/",
103 "STACK:idle_p%s:%-15s" % (CPU_IDLE
, _("Idle")),
104 "GPRINT:idle_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
105 "GPRINT:idle_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
106 "GPRINT:idle_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
113 def graph_title(self
):
114 _
= self
.locale
.translate
115 return _("Processor Usage")
118 def graph_vertical_label(self
):
119 _
= self
.locale
.translate
123 class ProcessorObject(base
.Object
):
125 "DS:user:DERIVE:0:U",
126 "DS:nice:DERIVE:0:U",
128 "DS:idle:DERIVE:0:U",
129 "DS:wait:DERIVE:0:U",
131 "DS:sirq:DERIVE:0:U",
132 "DS:steal:DERIVE:0:U",
133 "DS:guest:DERIVE:0:U",
134 "DS:guest_nice:DERIVE:0:U",
137 def init(self
, cpu_id
=None):
142 if self
.cpu_id
is not None:
143 return "%s" % self
.cpu_id
151 stat
= self
.read_proc_stat()
153 if self
.cpu_id
is None:
154 values
= stat
.get("cpu")
156 values
= stat
.get("cpu%s" % self
.cpu_id
)
158 # Convert values into a list
159 values
= values
.split()
161 if not len(values
) == len(self
.rrd_schema
):
162 raise ValueError("Received unexpected output from /proc/stat: %s" % values
)
167 class ProcessorPlugin(base
.Plugin
):
169 description
= "Processor Usage Plugin"
171 templates
= [GraphTemplateProcessor
]
175 yield ProcessorObject(self
)
177 num
= multiprocessing
.cpu_count()
179 yield ProcessorObject(self
, cpu_id
=i
)