]>
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 ###############################################################################
24 from ..colours
import *
27 class GraphTemplateProcessor(base
.GraphTemplate
):
32 _
= self
.locale
.translate
35 "CDEF:total=user,nice,+,sys,+,wait,+,irq,+,sirq,+,idle,+",
37 "CDEF:user_p=100,user,*,total,/",
38 "AREA:user_p%s:%-15s" % (CPU_USER
, _("User")),
39 "GPRINT:user_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
40 "GPRINT:user_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
41 "GPRINT:user_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
43 "CDEF:nice_p=100,nice,*,total,/",
44 "STACK:nice_p%s:%-15s" % (CPU_NICE
, _("Nice")),
45 "GPRINT:nice_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
46 "GPRINT:nice_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
47 "GPRINT:nice_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
49 "CDEF:sys_p=100,sys,*,total,/",
50 "STACK:sys_p%s:%-15s" % (CPU_SYS
, _("System")),
51 "GPRINT:sys_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
52 "GPRINT:sys_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
53 "GPRINT:sys_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
55 "CDEF:wait_p=100,wait,*,total,/",
56 "STACK:wait_p%s:%-15s" % (CPU_WAIT
, _("Wait")),
57 "GPRINT:wait_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
58 "GPRINT:wait_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
59 "GPRINT:wait_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
61 "CDEF:irq_p=100,irq,*,total,/",
62 "STACK:irq_p%s:%-15s" % (CPU_IRQ
, _("Interrupt")),
63 "GPRINT:irq_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
64 "GPRINT:irq_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
65 "GPRINT:irq_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
67 "CDEF:sirq_p=100,sirq,*,total,/",
68 "STACK:sirq_p%s:%-15s" % (CPU_SIRQ
, _("Soft Interrupt")),
69 "GPRINT:sirq_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
70 "GPRINT:sirq_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
71 "GPRINT:sirq_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
73 "CDEF:idle_p=100,idle,*,total,/",
74 "STACK:idle_p%s:%-15s" % (CPU_IDLE
, _("Idle")),
75 "GPRINT:idle_p_max:%12s\:" % _("Maximum") + " %6.2lf%%",
76 "GPRINT:idle_p_min:%12s\:" % _("Minimum") + " %6.2lf%%",
77 "GPRINT:idle_p_avg:%12s\:" % _("Average") + " %6.2lf%%\\n",
84 def graph_title(self
):
85 _
= self
.locale
.translate
86 return _("Processor Usage")
89 def graph_vertical_label(self
):
90 _
= self
.locale
.translate
94 class ProcessorObject(base
.Object
):
100 "DS:wait:DERIVE:0:U",
102 "DS:sirq:DERIVE:0:U",
116 f
= open("/proc/stat")
118 for line
in f
.readlines():
119 if not line
.startswith("cpu"):
122 columns
= line
.split()
140 class ProcessorPlugin(base
.Plugin
):
142 description
= "Processor Usage Plugin"
144 templates
= [GraphTemplateProcessor
]
148 yield ProcessorObject(self
)