Skip to content
5 changes: 3 additions & 2 deletions common.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
MANCENTER="Munin C Documentation"

%.1:%.pod
.pod.1:
$(AM_V_GEN)pod2man --section=1 --release=$(VERSION) --center=$(MANCENTER) $< > $@
sed -i -e 's#@@pkglibexecdir@@#$(pkglibexecdir)#' -e 's#@@CONFDIR@@#$(sysconfdir)#' $@
sed -i '' -e 's#@@pkglibexecdir@@#$(pkglibexecdir)#' -e 's#@@CONFDIR@@#$(sysconfdir)#' $@

SUFFIXES = .1 .pod

# vim:ft=make
63 changes: 63 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,69 @@ AM_INIT_AUTOMAKE([foreign subdir-objects])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AM_MAINTAINER_MODE([enable])

AC_CANONICAL_HOST
case $host in
*bsd* )
SYS_API='bsd'

DF_API='bsd'
ENTROPY_API='unsupported'
FW_PACKETS_API='unsupported'
IF_ERR_API='unsupported'
INTERRUPTS_API='unsupported'
IOSTAT_API='unsupported'
LOAD_API='bsd'
OPEN_INODES_API='unsupported'

LDFLAGS='-lkvm'
;;

*darwin* )
SYS_API='darwin'

# macOS (Darwin/XNU) is mostly-BSD-compatible, but has some deviations.
DF_API='bsd'
ENTROPY_API='unsupported'
FW_PACKETS_API='darwin'
IF_ERR_API='darwin'
INTERRUPTS_API='unsupported'
IOSTAT_API='darwin'
LOAD_API='bsd'
OPEN_INODES_API='unsupported'

LDFLAGS='-framework CoreFoundation -framework IOKit'
;;

*)
SYS_API='proc'

# Linux takes APIs from a variety of sources.
DF_API='sunos'
ENTROPY_API='proc'
FW_PACKETS_API='proc'
IF_ERR_API='proc'
INTERRUPTS_API='proc'
IOSTAT_API='proc'
LOAD_API='proc'
OPEN_INODES_API='proc'

LDFLAGS=''
;;
esac

AC_SUBST([SYS_API])

AC_SUBST([DF_API])
AC_SUBST([ENTROPY_API])
AC_SUBST([FW_PACKETS_API])
AC_SUBST([IF_ERR_API])
AC_SUBST([INTERRUPTS_API])
AC_SUBST([IOSTAT_API])
AC_SUBST([LOAD_API])
AC_SUBST([OPEN_INODES_API])

AC_SUBST([LDFLAGS])

AC_PROG_CC
AC_PROG_CC_C_O

Expand Down
7 changes: 7 additions & 0 deletions src/common/xctype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* put here extended versions of <ctype.h>
* Only use #define tricks to avoid the overhead of func call
*/

/* Defined by the ctype(3) in NetBSD */
#define xisdigit(x) isdigit((int)(unsigned char) (x))
#define xisspace(x) isspace((int)(unsigned char) (x))
2 changes: 1 addition & 1 deletion src/node/inetd.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <unistd.h>
#include <signal.h>

#if !(defined(HAVE_WORKING_VFORK) || defined(S_SPLINT_S))
#if !(defined(HAVE_WORKING_VFORK) || defined(S_SPLINT_S)) || defined(__APPLE__)
#define vfork fork
#endif

Expand Down
33 changes: 17 additions & 16 deletions src/plugins/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ munin_plugins_c_SOURCES = \
common.c \
common.h \
plugins.h \
p/cpu.c \
p/df.c \
p/entropy.c \
p/cpu-$(SYS_API).c \
p/df-$(DF_API).c \
p/entropy-$(ENTROPY_API).c \
p/external_.c \
p/forks.c \
p/fw_packets.c \
p/if_err_.c \
p/interrupts.c \
p/iostat.c \
p/load.c \
p/open_files.c \
p/open_inodes.c \
p/processes.c \
p/swap.c \
p/threads.c \
p/memory.c \
p/uptime.c \
p/forks-$(SYS_API).c \
p/fw_packets-$(FW_PACKETS_API).c \
p/if_err_-$(IF_ERR_API).c \
p/interrupts-$(INTERRUPTS_API).c \
p/iostat-$(IOSTAT_API).c \
p/load-$(LOAD_API).c \
p/memory-$(SYS_API).c \
p/open_files-$(SYS_API).c \
p/open_inodes-$(INTERRUPTS_API).c \
p/processes-$(SYS_API).c \
p/swap-$(SYS_API).c \
p/threads-$(SYS_API).c \
p/uptime-$(SYS_API).c \
main.c
munin_plugins_c_LDADD = $(LDFLAGS)
man_MANS = munin-plugins-c.1
CLEANFILES = $(man_MANS)
EXTRA_DIST = munin-plugins-c.pod
10 changes: 10 additions & 0 deletions src/plugins/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ int writeyes(void)
return 0;
}

int unsupported(int argc, char **argv)
{
if (argc > 1) {
if (!strcmp(argv[1], "autoconf"))
puts("no");
}

return 0;
}

int autoconf_check_readable(const char *path)
{
if (0 == access(path, R_OK))
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* @returns a success state to be passed on as the return value from main */
int writeyes(void);

/** Indicates that the plugin cannot produce output on the current platform. */
int unsupported(int argc, char **argv);

/** Answer an autoconf request by checking the readability of the given file.
*/
int autoconf_check_readable(const char *);
Expand Down
72 changes: 72 additions & 0 deletions src/plugins/p/cpu-bsd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2015 Steve Schnepp <[email protected]> - All rights reserved.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2 or v.3.
*/

#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <unistd.h>
#include "common.h"
#include "plugins.h"

int cpu(int argc, char **argv) {
if(argc > 1) {
if(!strcmp(argv[1], "config")) {
puts("graph_title CPU usage\n"
"graph_args --base 1000 -r --lower-limit 0 --upper-limit 100\n"
"graph_vlabel %\n"
"graph_scale no\n"
"graph_info This graph shows how CPU time is spent.\n"
"graph_category system\n"
"graph_period second\n"

"intr.label intr\n"
"intr.type DERIVE\n"
"intr.draw AREA\n"
"intr.info CPU time spent by the kernel in interrupt handlers\n"

"system.label system\n"
"system.type DERIVE\n"
"system.draw AREA\n"
"system.info CPU time spent by the kernel in system activities\n"

"user.label user\n"
"user.type DERIVE\n"
"user.draw STACK\n"
"user.info CPU time spent by normal programs and daemons\n"

"nice.label nice\n"
"nice.type DERIVE\n"
"nice.draw STACK\n"
"nice.info CPU time spent by nice(1)d programs\n"

"idle.label idle\n"
"idle.type DERIVE\n"
"idle.draw STACK\n"
"idle.info Idle CPU time");

return 0;
}
if(!strcmp(argv[1], "autoconf"))
return writeyes();
}

long cputicks[CPUSTATES];
size_t len = sizeof(cputicks);
if (sysctlbyname("kern.cp_time", &cputicks, &len, NULL, 0) < 0) {
return fail("sysctlbyname");
}

printf("intr.value %lu\n", cputicks[CP_INTR]);
printf("system.value %lu\n", cputicks[CP_SYS]);
printf("user.value %lu\n", cputicks[CP_USER]);
printf("nice.value %lu\n", cputicks[CP_NICE]);
printf("idle.value %lu\n", cputicks[CP_IDLE]);

return 0;
}
76 changes: 76 additions & 0 deletions src/plugins/p/cpu-darwin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2015 Steve Schnepp <[email protected]> - All rights reserved.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2 or v.3.
*/

#include <mach/mach_host.h>
#include <string.h>
#include <stdio.h>
#include <sys/sysctl.h>
#include "common.h"
#include "plugins.h"

int cpu(int argc, char **argv) {
if(argc > 1) {
if(!strcmp(argv[1], "config")) {
puts("graph_title CPU usage\n"
"graph_args --base 1000 -r --lower-limit 0 --upper-limit 100\n"
"graph_vlabel %\n"
"graph_scale no\n"
"graph_info This graph shows how CPU time is spent.\n"
"graph_category system\n"
"graph_period second\n"

"system.label system\n"
"system.min 0\n"
"system.type DERIVE\n"
"system.draw AREA\n"
"system.info CPU time spent by the kernel in system activities\n"

"user.label user\n"
"user.min 0\n"
"user.type DERIVE\n"
"user.draw STACK\n"
"user.info CPU time spent by normal programs and daemons\n"

"nice.label nice\n"
"nice.min 0\n"
"nice.type DERIVE\n"
"nice.draw STACK\n"
"nice.info CPU time spent by nice(1)d programs\n"

"idle.label idle\n"
"idle.min 0\n"
"idle.type DERIVE\n"
"idle.draw STACK\n"
"idle.info Idle CPU time");

return 0;
}
if(!strcmp(argv[1], "autoconf"))
return writeyes();
}

unsigned int cpuCount;
size_t len = sizeof(cpuCount);
if (sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0) < 0) {
return fail("sysctlbyname");
}

host_t host = mach_host_self();
host_cpu_load_info_data_t li;
mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT;
if (host_statistics(host, HOST_CPU_LOAD_INFO, (host_info_t)&li, &count) != KERN_SUCCESS) {
return fail("host_statistics");
}

printf("system.value %lu\n", li.cpu_ticks[CPU_STATE_SYSTEM] / cpuCount);
printf("user.value %lu\n", li.cpu_ticks[CPU_STATE_USER] / cpuCount);
printf("nice.value %lu\n", li.cpu_ticks[CPU_STATE_NICE] / cpuCount);
printf("idle.value %lu\n", li.cpu_ticks[CPU_STATE_IDLE] / cpuCount);

return 0;
}
File renamed without changes.
Loading