mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
mpb: add threads.c plugin
This commit is contained in:
parent
05a642549d
commit
4337b550a0
@ -1,9 +1,10 @@
|
||||
CC=gcc
|
||||
CFLAGS=-W -Wall -pedantic -Wextra -g -O2
|
||||
OBJS=main.o common.o cpu.o entropy.o forks.o fw_packets.o interrupts.o \
|
||||
if_err_.o load.o open_files.o open_inodes.o processes.o swap.o uptime.o
|
||||
if_err_.o load.o open_files.o open_inodes.o processes.o swap.o threads.o \
|
||||
uptime.o
|
||||
LINKS=cpu entropy forks fw_packets interrupts if_err_eth0 load open_files \
|
||||
open_inodes processes swap uptime
|
||||
open_inodes processes swap threads uptime
|
||||
|
||||
%.o:%.c
|
||||
${CC} ${CFLAGS} -c $< -o $@
|
||||
|
@ -14,6 +14,7 @@ int open_files(int argc, char **argv);
|
||||
int open_inodes(int argc, char **argv);
|
||||
int processes(int argc, char **argv);
|
||||
int swap(int argc, char **argv);
|
||||
int threads(int argc, char **argv);
|
||||
int uptime(int argc, char **argv);
|
||||
|
||||
int busybox(int argc, char **argv) {
|
||||
@ -72,6 +73,10 @@ int main(int argc, char **argv) {
|
||||
if(!strcmp(progname+1, "wap"))
|
||||
return swap(argc, argv);
|
||||
break;
|
||||
case 't':
|
||||
if(!strcmp(progname+1, "hreads"))
|
||||
return threads(argc, argv);
|
||||
break;
|
||||
case 'u':
|
||||
if(!strcmp(progname+1, "ptime"))
|
||||
return uptime(argc, argv);
|
||||
|
70
tools/munin-plugins-busybox/threads.c
Normal file
70
tools/munin-plugins-busybox/threads.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "common.h"
|
||||
|
||||
int threads(int argc, char **argv) {
|
||||
FILE *f;
|
||||
char buff[256];
|
||||
const char *s;
|
||||
int i, sum;
|
||||
DIR *d;
|
||||
struct dirent *e;
|
||||
|
||||
if(argc > 1) {
|
||||
if(!strcmp(argv[1], "autoconf")) {
|
||||
i = getpid();
|
||||
sprintf(buff, "/proc/%d/status", i);
|
||||
if(NULL == (f = fopen(buff, "r")))
|
||||
return fail("failed to open /proc/$$/status");
|
||||
while(fgets(buff, 256, f))
|
||||
if(!strncmp(buff, "Threads:", 8)) {
|
||||
fclose(f);
|
||||
return writeyes();
|
||||
}
|
||||
fclose(f);
|
||||
puts("no");
|
||||
return 0;
|
||||
}
|
||||
if(!strcmp(argv[1], "config")) {
|
||||
puts("graph_title Number of threads\n"
|
||||
"graph_vlabel number of threads\n"
|
||||
"graph_category processes\n"
|
||||
"graph_info This graph shows the number of threads.\n"
|
||||
"threads.label threads\n"
|
||||
"threads.info The current number of threads.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(NULL == (d = opendir("/proc")))
|
||||
return fail("cannot open /proc");
|
||||
sum = 0;
|
||||
while((e = readdir(d))) {
|
||||
for(s=e->d_name;*s;++s)
|
||||
if(!isdigit(*s))
|
||||
break;
|
||||
if(*s) /* non-digit found */
|
||||
continue;
|
||||
snprintf(buff, 256, "/proc/%s/status", e->d_name);
|
||||
if(!(f = fopen(buff, "r")))
|
||||
continue; /* process has vanished */
|
||||
while(fgets(buff, 256, f)) {
|
||||
if(strncmp(buff, "Threads:", 8))
|
||||
continue;
|
||||
if(1 != sscanf(buff+8, "%d", &i)) {
|
||||
fclose(f);
|
||||
closedir(d);
|
||||
return fail("failed to parse "
|
||||
"/proc/somepid/status");
|
||||
}
|
||||
sum += i;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
closedir(d);
|
||||
printf("threads.value %d\n", sum);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user