Projet

Général

Profil

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

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

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

1 20993707 Helmut Grohne
#include <string.h>
2
#include <stdio.h>
3
#include <unistd.h>
4
#include "common.h"
5
6 611bfb05 Helmut Grohne
#define FS_INODE_NR "/proc/sys/fs/inode-nr"
7
8 20993707 Helmut Grohne
int open_inodes(int argc, char **argv) {
9
        FILE *f;
10
        int nr, freen;
11
        if(argc > 1) {
12
                if(!strcmp(argv[1], "config")) {
13
                        puts("graph_title Inode table usage\n"
14
                                "graph_args --base 1000 -l 0\n"
15
                                "graph_vlabel number of open inodes\n"
16
                                "graph_category system\n"
17
                                "graph_info This graph monitors the Linux open inode table.\n"
18
                                "used.label open inodes\n"
19
                                "used.info The number of currently open inodes.\n"
20
                                "max.label inode table size\n"
21
                                "max.info The size of the system inode table. This is dynamically adjusted by the kernel.");
22 cbfa6b45 Helmut Grohne
                        print_warncrit("used");
23
                        print_warncrit("max");
24 20993707 Helmut Grohne
                        return 0;
25
                }
26
                if(!strcmp(argv[1], "autoconf")) {
27 611bfb05 Helmut Grohne
                        if(0 == access(FS_INODE_NR, R_OK))
28 20993707 Helmut Grohne
                                return writeyes();
29
                        else
30 611bfb05 Helmut Grohne
                                return writeno(FS_INODE_NR " not readable");
31 20993707 Helmut Grohne
                }
32
        }
33 611bfb05 Helmut Grohne
        if(!(f=fopen(FS_INODE_NR, "r"))) {
34
                fputs("cannot open " FS_INODE_NR "\n", stderr);
35 20993707 Helmut Grohne
                return 1;
36
        }
37
        if(2 != fscanf(f, "%d %d", &nr, &freen)) {
38
                fclose(f);
39 611bfb05 Helmut Grohne
                fputs("cannot read from " FS_INODE_NR "\n", stderr);
40 20993707 Helmut Grohne
                return 1;
41
        }
42
        fclose(f);
43
        printf("used.value %d\nmax.value %d\n", nr-freen, nr);
44
        return 0;
45
}