3 * Copyright (C) 2007 Peter Holik
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Peter Holik <peter at holik.at>
26 #include "configfile.h"
28 #define MODULE_NAME "irq"
31 # define IRQ_HAVE_READ 1
33 # define IRQ_HAVE_READ 0
39 * (Module-)Global variables
41 static data_source_t dsrc_irq[1] =
43 {"value", DS_TYPE_COUNTER, 0, 65535.0}
46 static data_set_t ds_irq =
52 static const char *config_keys[] =
57 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
59 static unsigned int *irq_list;
60 static unsigned int irq_list_num;
64 * 0 => default is to collect selected irqs
65 * 1 => ignore selcted irqs
67 static int irq_list_action;
69 static int irq_config (const char *key, const char *value)
71 if (strcasecmp (key, "Irq") == 0)
77 temp = (unsigned int *) realloc (irq_list, (irq_list_num + 1) * sizeof (unsigned int *));
80 fprintf (stderr, "irq plugin: Cannot allocate more memory.\n");
81 ERROR ("irq plugin: Cannot allocate more memory.");
86 /* Clear errno, because we need it to see if an error occured. */
89 irq = strtol(value, &endptr, 10);
90 if ((endptr == value) || (errno != 0))
92 fprintf (stderr, "irq plugin: Irq value is not a "
93 "number: `%s'\n", value);
94 ERROR ("irq plugin: Irq value is not a "
95 "number: `%s'", value);
98 irq_list[irq_list_num] = irq;
101 else if (strcasecmp (key, "IgnoreSelected") == 0)
103 if ((strcasecmp (value, "True") == 0)
104 || (strcasecmp (value, "Yes") == 0)
105 || (strcasecmp (value, "On") == 0))
118 * Check if this interface/instance should be ignored. This is called from
119 * both, `submit' and `write' to give client and server the ability to
120 * ignore certain stuff..
122 static int check_ignore_irq (const unsigned int irq)
126 if (irq_list_num < 1)
129 for (i = 0; i < irq_list_num; i++)
130 if (irq == irq_list[i])
131 return (irq_list_action);
133 return (1 - irq_list_action);
136 static void irq_submit (unsigned int irq, counter_t value)
139 value_list_t vl = VALUE_LIST_INIT;
142 if (check_ignore_irq (irq))
145 values[0].counter = value;
149 vl.time = time (NULL);
150 strcpy (vl.host, hostname_g);
151 strcpy (vl.plugin, "irq");
153 status = snprintf (vl.type_instance, sizeof (vl.type_instance),
155 if ((status < 1) || (status >= sizeof (vl.type_instance)))
158 plugin_dispatch_values ("irq", &vl);
159 } /* void irq_submit */
161 static int irq_read (void)
169 char buffer[BUFSIZE];
171 unsigned int irq_value;
179 if ((fh = fopen ("/proc/interrupts", "r")) == NULL)
182 WARNING ("irq plugin: fopen (/proc/interrupts): %s",
183 sstrerror (errno, errbuf, sizeof (errbuf)));
186 while (fgets (buffer, BUFSIZE, fh) != NULL)
188 fields_num = strsplit (buffer, fields, 64);
192 errno = 0; /* To distinguish success/failure after call */
193 irq = strtol (fields[0], &endptr, 10);
195 if ((endptr == fields[0]) || (errno != 0) || (*endptr != ':'))
199 for (i = 1; i < fields_num; i++)
202 value = strtol (fields[i], &endptr, 10);
204 if ((*endptr != '\0') || (errno != 0))
210 irq_submit (irq, irq_value);
213 #endif /* KERNEL_LINUX */
217 #endif /* IRQ_HAVE_READ */
219 void module_register (void)
221 plugin_register_data_set (&ds_irq);
224 plugin_register_config ("irq", irq_config,
225 config_keys, config_keys_num);
226 plugin_register_read ("irq", irq_read);
227 #endif /* IRQ_HAVE_READ */