Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / tools / munin-plugins-busybox / interrupts.c @ cbfa6b45

Historique | Voir | Annoter | Télécharger (1,64 ko)

1 20993707 Helmut Grohne
#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 cbfa6b45 Helmut Grohne
                        print_warncrit("intr");
27
                        print_warncrit("ctx");
28 20993707 Helmut Grohne
                        return 0;
29
                }
30
                if(!strcmp(argv[1], "autoconf")) {
31 339b8f43 Helmut Grohne
                        if(0 == access(PROC_STAT, R_OK))
32 20993707 Helmut Grohne
                                return writeyes();
33
                        else
34 339b8f43 Helmut Grohne
                                return writeno(PROC_STAT " not readable");
35 20993707 Helmut Grohne
                }
36
        }
37 339b8f43 Helmut Grohne
        if(!(f=fopen(PROC_STAT, "r"))) {
38
                fputs("cannot open " PROC_STAT "\n", stderr);
39 20993707 Helmut Grohne
                return 1;
40
        }
41
        while(fgets(buff, 256, f)) {
42 1956b4dd Helmut Grohne
                if(!strncmp(buff, "intr ", 5)) {
43
                        buff[5 + strcspn(buff + 5, " \t\n")] = '\0';
44
                        printf("intr.value %s\n", buff+5);
45
                } else if(!strncmp(buff, "ctxt ", 5)) {
46
                        buff[5 + strcspn(buff + 5, " \t\n")] = '\0';
47
                        printf("ctx.value %s\n", buff+5);
48
                }
49 20993707 Helmut Grohne
        }
50
        fclose(f);
51
        return 0;
52
}