Projet

Général

Profil

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

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

Historique | Voir | Annoter | Télécharger (790 octets)

1
#include <stdio.h>
2
#include <string.h>
3
#include <stdlib.h>
4
#include "common.h"
5

    
6
#define PROC_LOADAVG "/proc/loadavg"
7

    
8
int load(int argc, char **argv) {
9
        FILE *f;
10
        float val;
11
        if(argc > 1) {
12
                if(!strcmp(argv[1], "config")) {
13
                        puts("graph_title Load average\n"
14
                                "graph_args --base 1000 -l 0\n"
15
                                "graph_vlabel load\n"
16
                                "graph_scale no\n"
17
                                "graph_category system\n"
18
                                "load.label load");
19
                        print_warncrit("load");
20
                        return 0;
21
                }
22
                if(!strcmp(argv[1], "autoconf"))
23
                        return writeyes();
24
        }
25
        if(!(f=fopen(PROC_LOADAVG, "r"))) {
26
                fputs("cannot open " PROC_LOADAVG "\n", stderr);
27
                return 1;
28
        }
29
        if(1 != fscanf(f, "%*f %f", &val)) {
30
                fputs("cannot read from " PROC_LOADAVG "\n", stderr);
31
                fclose(f);
32
                return 1;
33
        }
34
        fclose(f);
35
        printf("load.value %.2f\n", val);
36
        return 0;
37
}