]>
Commit | Line | Data |
---|---|---|
27f02dbd MT |
1 | #!/usr/bin/python3 |
2 | ############################################################################### | |
3 | # # | |
4 | # collecty - A system statistics collection daemon for IPFire # | |
5 | # Copyright (C) 2015 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 | ||
22 | import re | |
23 | ||
24 | from . import base | |
25 | ||
03ba5630 | 26 | from ..colours import * |
77a7f6fd | 27 | from ..constants import * |
72fc5ca5 | 28 | from ..i18n import _ |
27f02dbd MT |
29 | |
30 | class GraphTemplateContextSwitches(base.GraphTemplate): | |
31 | name = "context-switches" | |
32 | ||
33 | @property | |
34 | def rrd_graph(self): | |
27f02dbd | 35 | return [ |
d542dec5 MT |
36 | "COMMENT:%s" % EMPTY_LABEL, |
37 | "COMMENT:%s" % (COLUMN % _("Current")), | |
38 | "COMMENT:%s" % (COLUMN % _("Average")), | |
39 | "COMMENT:%s" % (COLUMN % _("Minimum")), | |
40 | "COMMENT:%s\\j" % (COLUMN % _("Maximum")), | |
77a7f6fd MT |
41 | |
42 | "AREA:ctxt%s:%s" % ( | |
42ea528a | 43 | transparency(PRIMARY, AREA_OPACITY), |
77a7f6fd | 44 | LABEL % _("Context Switches"), |
03ba5630 | 45 | ), |
77a7f6fd MT |
46 | "GPRINT:ctxt_cur:%s" % INTEGER, |
47 | "GPRINT:ctxt_avg:%s" % INTEGER, | |
48 | "GPRINT:ctxt_min:%s" % INTEGER, | |
49 | "GPRINT:ctxt_max:%s" % INTEGER, | |
d542dec5 MT |
50 | |
51 | "LINE1:ctxt%s" % PRIMARY, | |
27f02dbd MT |
52 | ] |
53 | ||
54 | lower_limit = 0 | |
55 | ||
56 | @property | |
57 | def graph_title(self): | |
27f02dbd MT |
58 | return _("Context Switches") |
59 | ||
60 | @property | |
61 | def graph_vertical_label(self): | |
27f02dbd MT |
62 | return _("Context Switches/s") |
63 | ||
64 | ||
65 | class ContextSwitchesObject(base.Object): | |
66 | rrd_schema = [ | |
67 | "DS:ctxt:DERIVE:0:U", | |
68 | ] | |
69 | ||
70 | @property | |
71 | def id(self): | |
72 | return "default" | |
73 | ||
74 | def collect(self): | |
aa0c868a | 75 | expr = r"^ctxt (\d+)$" |
27f02dbd MT |
76 | |
77 | with open("/proc/stat") as f: | |
78 | for line in f.readlines(): | |
79 | m = re.match(expr, line) | |
80 | if m: | |
81 | return m.group(1) | |
82 | ||
83 | ||
84 | class ContextSwitchesPlugin(base.Plugin): | |
85 | name = "context-switches" | |
86 | description = "Context Switches Plugin" | |
87 | ||
88 | templates = [GraphTemplateContextSwitches] | |
89 | ||
90 | @property | |
91 | def objects(self): | |
92 | yield ContextSwitchesObject(self) |