3 * Copyright (C) 2007 Peter Holik
4 * Copyright (C) 2011 Florian Forster
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Peter Holik <peter at holik.at>
27 #include "configfile.h"
28 #include "utils_ignorelist.h"
31 # error "No applicable input method."
35 * (Module-)Global variables
37 static const char *config_keys[] =
42 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
44 static ignorelist_t *ignorelist = NULL;
49 static int irq_config (const char *key, const char *value)
51 if (ignorelist == NULL)
52 ignorelist = ignorelist_create (/* invert = */ 1);
54 if (strcasecmp (key, "Irq") == 0)
56 ignorelist_add (ignorelist, value);
58 else if (strcasecmp (key, "IgnoreSelected") == 0)
63 ignorelist_set_invert (ignorelist, invert);
73 static void irq_submit (const char *irq_name, derive_t value)
76 value_list_t vl = VALUE_LIST_INIT;
78 if (ignorelist_match (ignorelist, irq_name) != 0)
81 values[0].derive = value;
85 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
86 sstrncpy (vl.plugin, "irq", sizeof (vl.plugin));
87 sstrncpy (vl.type, "irq", sizeof (vl.type));
88 sstrncpy (vl.type_instance, irq_name, sizeof (vl.type_instance));
90 plugin_dispatch_values (&vl);
91 } /* void irq_submit */
93 static int irq_read (void)
98 fh = fopen ("/proc/interrupts", "r");
102 ERROR ("irq plugin: fopen (/proc/interrupts): %s",
103 sstrerror (errno, errbuf, sizeof (errbuf)));
107 while (fgets (buffer, sizeof (buffer), fh) != NULL)
117 fields_num = strsplit (buffer, fields, 64);
121 irq_name = fields[0];
122 irq_name_len = strlen (irq_name);
123 if (irq_name_len < 2)
126 /* Check if irq name ends with colon.
127 * Otherwise it's a header. */
128 if (irq_name[irq_name_len - 1] != ':')
131 irq_name[irq_name_len - 1] = 0;
135 for (i = 1; i < fields_num; i++)
141 status = parse_value (fields[i], &v, DS_TYPE_DERIVE);
145 irq_value += v.derive;
148 /* No valid fields -> do not submit anything. */
152 irq_submit (irq_name, irq_value);
160 void module_register (void)
162 plugin_register_config ("irq", irq_config,
163 config_keys, config_keys_num);
164 plugin_register_read ("irq", irq_read);
165 } /* void module_register */