root / tools / munin-plugins-busybox / interrupts.c @ 20993707
Historique | Voir | Annoter | Télécharger (1,49 ko)
| 1 |
#include <string.h> |
|---|---|
| 2 |
#include <stdio.h> |
| 3 |
#include <unistd.h> |
| 4 |
#include "common.h" |
| 5 |
|
| 6 |
int interrupts(int argc, char **argv) { |
| 7 |
FILE *f; |
| 8 |
char buff[256]; |
| 9 |
if(argc > 1) { |
| 10 |
if(!strcmp(argv[1], "config")) { |
| 11 |
puts("graph_title Interrupts & context switches\n"
|
| 12 |
"graph_args --base 1000 -l 0\n"
|
| 13 |
"graph_vlabel interrupts & ctx switches / ${graph_period}\n"
|
| 14 |
"graph_category system\n"
|
| 15 |
"graph_info This graph shows the number of interrupts and context switches on the system. These are typically high on a busy system.\n"
|
| 16 |
"intr.info Interrupts are events that alter sequence of instructions executed by a processor. They can come from either hardware (exceptions, NMI, IRQ) or software.");
|
| 17 |
puts("ctx.info A context switch occurs when a multitasking operatings system suspends the currently running process, and starts executing another.\n"
|
| 18 |
"intr.label interrupts\n"
|
| 19 |
"ctx.label context switches\n"
|
| 20 |
"intr.type DERIVE\n"
|
| 21 |
"ctx.type DERIVE\n"
|
| 22 |
"intr.max 100000\n"
|
| 23 |
"ctx.max 100000\n"
|
| 24 |
"intr.min 0\n"
|
| 25 |
"ctx.min 0");
|
| 26 |
return 0; |
| 27 |
} |
| 28 |
if(!strcmp(argv[1], "autoconf")) { |
| 29 |
if(0 == access("/proc/stat", R_OK)) |
| 30 |
return writeyes();
|
| 31 |
else
|
| 32 |
return writeno("/proc/stat not readable"); |
| 33 |
} |
| 34 |
} |
| 35 |
if(!(f=fopen("/proc/stat", "r"))) { |
| 36 |
fputs("cannot open /proc/stat\n", stderr);
|
| 37 |
return 1; |
| 38 |
} |
| 39 |
while(fgets(buff, 256, f)) { |
| 40 |
if(!strncmp(buff, "intr ", 5)) |
| 41 |
printf("intr.value %s", buff+5); |
| 42 |
else if(!strncmp(buff, "ctxt ", 5)) |
| 43 |
printf("ctx.value %s", buff+5); |
| 44 |
} |
| 45 |
fclose(f); |
| 46 |
return 0; |
| 47 |
} |
