]> git.ipfire.org Git - collecty.git/blame - src/collecty/plugins/processor.py
Introduce a colour scheme and fix design of the graphs
[collecty.git] / src / collecty / plugins / processor.py
CommitLineData
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
f37913e8 22from . import base
eed405de 23
03ba5630 24from ..colours import *
eed405de
MT
25from ..i18n import _
26
c968f6d9
MT
27class GraphTemplateProcessor(base.GraphTemplate):
28 name = "processor"
eed405de 29
eb1ab05c
MT
30 @property
31 def rrd_graph(self):
32 _ = self.locale.translate
33
34 return [
03ba5630 35 "AREA:user%s:%-15s" % (CPU_USER, _("User")),
cd8bba0b
MT
36 "GPRINT:user_max:%12s\:" % _("Maximum") + " %6.2lf" ,
37 "GPRINT:user_min:%12s\:" % _("Minimum") + " %6.2lf",
38 "GPRINT:user_avg:%12s\:" % _("Average") + " %6.2lf\\n",
eb1ab05c 39
03ba5630 40 "STACK:nice%s:%-15s" % (CPU_NICE, _("Nice")),
cd8bba0b
MT
41 "GPRINT:nice_max:%12s\:" % _("Maximum") + " %6.2lf" ,
42 "GPRINT:nice_min:%12s\:" % _("Minimum") + " %6.2lf",
43 "GPRINT:nice_avg:%12s\:" % _("Average") + " %6.2lf\\n",
eb1ab05c 44
03ba5630 45 "STACK:sys%s:%-15s" % (CPU_SYS, _("System")),
cd8bba0b
MT
46 "GPRINT:sys_max:%12s\:" % _("Maximum") + " %6.2lf" ,
47 "GPRINT:sys_min:%12s\:" % _("Minimum") + " %6.2lf",
48 "GPRINT:sys_avg:%12s\:" % _("Average") + " %6.2lf\\n",
eb1ab05c 49
03ba5630 50 "STACK:wait%s:%-15s" % (CPU_WAIT, _("Wait")),
cd8bba0b
MT
51 "GPRINT:wait_max:%12s\:" % _("Maximum") + " %6.2lf" ,
52 "GPRINT:wait_min:%12s\:" % _("Minimum") + " %6.2lf",
53 "GPRINT:wait_avg:%12s\:" % _("Average") + " %6.2lf\\n",
eb1ab05c 54
03ba5630 55 "STACK:irq%s:%-15s" % (CPU_IRQ, _("Interrupt")),
cd8bba0b
MT
56 "GPRINT:irq_max:%12s\:" % _("Maximum") + " %6.2lf" ,
57 "GPRINT:irq_min:%12s\:" % _("Minimum") + " %6.2lf",
58 "GPRINT:irq_avg:%12s\:" % _("Average") + " %6.2lf\\n",
eb1ab05c 59
03ba5630 60 "STACK:sirq%s:%-15s" % (CPU_SIRQ, _("Soft Interrupt")),
cd8bba0b
MT
61 "GPRINT:sirq_max:%12s\:" % _("Maximum") + " %6.2lf" ,
62 "GPRINT:sirq_min:%12s\:" % _("Minimum") + " %6.2lf",
63 "GPRINT:sirq_avg:%12s\:" % _("Average") + " %6.2lf\\n",
eb1ab05c 64
03ba5630 65 "STACK:idle%s:%-15s" % (CPU_IDLE, _("Idle")),
cd8bba0b
MT
66 "GPRINT:idle_max:%12s\:" % _("Maximum") + " %6.2lf" ,
67 "GPRINT:idle_min:%12s\:" % _("Minimum") + " %6.2lf",
68 "GPRINT:idle_avg:%12s\:" % _("Average") + " %6.2lf\\n",
eb1ab05c 69 ]
73db5226 70
f181246a 71 lower_limit = 0
73db5226 72
f181246a
MT
73 @property
74 def graph_title(self):
eb1ab05c 75 _ = self.locale.translate
39fe7862 76 return _("Processor Usage")
f181246a
MT
77
78 @property
79 def graph_vertical_label(self):
eb1ab05c 80 _ = self.locale.translate
f181246a 81 return _("Jiffies")
eed405de 82
b1ea4956 83
72364063 84class ProcessorObject(base.Object):
b1ea4956 85 rrd_schema = [
de090041
MT
86 "DS:user:DERIVE:0:U",
87 "DS:nice:DERIVE:0:U",
88 "DS:sys:DERIVE:0:U",
89 "DS:idle:DERIVE:0:U",
90 "DS:wait:DERIVE:0:U",
91 "DS:irq:DERIVE:0:U",
92 "DS:sirq:DERIVE:0:U",
b1ea4956
MT
93 ]
94
72364063
MT
95 @property
96 def id(self):
97 return "default"
a116f2fb 98
72364063 99 def collect(self):
cc19aed8 100 """
a116f2fb 101 Reads the CPU usage.
cc19aed8
MT
102 """
103 f = None
eed405de 104
cc19aed8
MT
105 try:
106 f = open("/proc/stat")
eed405de 107
cc19aed8
MT
108 for line in f.readlines():
109 if not line.startswith("cpu"):
110 continue
eed405de 111
cc19aed8
MT
112 columns = line.split()
113 if len(columns) < 8:
114 continue
eed405de 115
f648421a 116 return (
cc19aed8
MT
117 columns[1], # user
118 columns[2], # nice
119 columns[3], # sys
120 columns[4], # idle
121 columns[5], # wait
122 columns[6], # irq
123 columns[7], # sirq
f648421a 124 )
cc19aed8
MT
125 finally:
126 if f:
127 f.close()
72364063
MT
128
129
130class ProcessorPlugin(base.Plugin):
131 name = "processor"
132 description = "Processor Usage Plugin"
133
c968f6d9 134 templates = [GraphTemplateProcessor]
72364063 135
72364063
MT
136 @property
137 def objects(self):
138 yield ProcessorObject(self)