2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

added #define PROC_STAT "/proc/stat"

This commit is contained in:
Helmut Grohne 2009-01-23 12:48:30 +00:00 committed by Steve Schnepp
parent bdf2dd257a
commit 339b8f43a9
5 changed files with 26 additions and 23 deletions

View File

@ -1,6 +1,8 @@
#ifndef COMMON_H
#define COMMON_H
#define PROC_STAT "/proc/stat"
int writeyes(void);
int writeno(const char *);

View File

@ -19,8 +19,8 @@ int cpu(int argc, char **argv) {
if(s && !strcmp(s, "yes"))
scaleto100=1;
if(!(f=fopen("/proc/stat", "r"))) {
fputs("cannot open /proc/stat\n", stderr);
if(!(f=fopen(PROC_STAT, "r"))) {
fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {
@ -37,7 +37,7 @@ int cpu(int argc, char **argv) {
fclose(f);
if(ncpu < 1 || extinfo < 4) {
fputs("cannot parse /proc/stat\n", stderr);
fputs("cannot parse " PROC_STAT "\n", stderr);
return 1;
}
@ -114,14 +114,14 @@ int cpu(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
if(0 == access("/proc/stat", R_OK))
if(0 == access(PROC_STAT, R_OK))
return writeyes();
else
return writeno("/proc/stat not readable");
return writeno(PROC_STAT " not readable");
}
}
if(!(f=fopen("/proc/stat", "r"))) {
fputs("cannot open /proc/stat\n", stderr);
if(!(f=fopen(PROC_STAT, "r"))) {
fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {
@ -152,6 +152,6 @@ int cpu(int argc, char **argv) {
}
}
fclose(f);
fputs("no cpu line found in /proc/stat\n", stderr);
fputs("no cpu line found in " PROC_STAT "\n", stderr);
return 1;
}

View File

@ -21,14 +21,14 @@ int forks(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
if(0 == access("/proc/stat", R_OK))
if(0 == access(PROC_STAT, R_OK))
return writeyes();
else
return writeno("/proc/stat not readable");
return writeno(PROC_STAT " not readable");
}
}
if(!(f=fopen("/proc/stat", "r"))) {
fputs("cannot open /proc/stat\n", stderr);
if(!(f=fopen(PROC_STAT, "r"))) {
fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {
@ -39,6 +39,6 @@ int forks(int argc, char **argv) {
}
}
fclose(f);
fputs("no processes line found in /proc/stat\n", stderr);
fputs("no processes line found in " PROC_STAT "\n", stderr);
return 1;
}

View File

@ -26,14 +26,14 @@ int interrupts(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
if(0 == access("/proc/stat", R_OK))
if(0 == access(PROC_STAT, R_OK))
return writeyes();
else
return writeno("/proc/stat not readable");
return writeno(PROC_STAT " not readable");
}
}
if(!(f=fopen("/proc/stat", "r"))) {
fputs("cannot open /proc/stat\n", stderr);
if(!(f=fopen(PROC_STAT, "r"))) {
fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {

View File

@ -27,10 +27,10 @@ int swap(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
if(0 == access("/proc/stat", R_OK))
if(0 == access(PROC_STAT, R_OK))
return writeyes();
else
return writeno("/proc/stat not readable");
return writeno(PROC_STAT " not readable");
}
}
if(!access("/proc/vmstat", F_OK)) {
@ -56,15 +56,16 @@ int swap(int argc, char **argv) {
}
return 0;
} else {
if(!(f=fopen("/proc/stat", "r"))) {
fputs("cannot open /proc/stat\n", stderr);
if(!(f=fopen(PROC_STAT, "r"))) {
fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {
if(!strncmp(buff, "swap ", 5)) {
fclose(f);
if(2 != sscanf(buff+5, "%d %d", &in, &out)) {
fputs("bad data on /proc/stat\n", stderr);
fputs("bad data on " PROC_STAT "\n",
stderr);
return 1;
}
printf("swap_in.value %d\nswap_out.value %d\n", in, out);
@ -72,7 +73,7 @@ int swap(int argc, char **argv) {
}
}
fclose(f);
fputs("no swap line found in /proc/stat\n", stderr);
fputs("no swap line found in " PROC_STAT "\n", stderr);
return 1;
}
}