1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Plugin-Gallery: Get better 2nd level headings

Review of category "system"
This commit is contained in:
dipohl 2017-02-24 23:54:53 +01:00
parent 54a91c13a4
commit 7fdb4741fe
27 changed files with 18 additions and 12 deletions

View file

@ -1,273 +0,0 @@
/*
* if1sec C plugin
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <inttypes.h>
#include <fcntl.h>
#include <time.h>
#include <sys/file.h>
#define PROC_STAT "/proc/net/dev"
#define PLUGIN_NAME "if1sec-c"
int fail(char* msg) {
perror(msg);
return 1;
}
/* Returns the ifname from a /proc/net/dev line
* It will return an inside pointer to line, and modifiy the end with a \0
*/
char* get_ifname_from_procstatline(char* line) {
char *ifname;
for (ifname = line; (*ifname) == ' '; ifname ++);
char *ifname_end;
for (ifname_end = ifname; (*ifname_end) != ':'; ifname_end ++);
(*ifname_end) = '\0';
return ifname;
}
int config() {
/* Get the number of if */
int f;
if ( !(f=open(PROC_STAT, O_RDONLY)) ) {
return fail("cannot open " PROC_STAT);
}
// Starting with -2, since the 2 lines on top are header lines
int nif = -2;
const int buffer_size = 64 * 1024;
char buffer[buffer_size];
// whole /proc/stat can be read in 1 syscall
if (read(f, buffer, buffer_size) <= 0) {
return fail("cannot read " PROC_STAT);
}
// tokenization per-line
char* line; char *saveptr;
char* newl = "\n";
for (line = strtok_r(buffer, newl, &saveptr); line; line = strtok_r(NULL, newl, &saveptr)) {
// Skip the header lines
if (nif ++ < 0) { continue; }
char* if_name = get_ifname_from_procstatline(line);
printf(
"multigraph if_%s_1sec" "\n"
"graph_order down up" "\n"
"graph_title %s traffic" "\n"
"graph_category system::1sec" "\n"
"graph_vlabel bits in (-) / out (+) per ${graph_period}" "\n"
"graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 1y" "\n"
, if_name, if_name
);
printf(
"down.label -" "\n"
"down.type DERIVE" "\n"
"down.graph no" "\n"
"down.cdef down,8,*" "\n"
"down.min 0" "\n"
"up.label bps" "\n"
"up.type DERIVE" "\n"
"up.negative down" "\n"
"up.cdef down,8,*" "\n"
"up.min 0" "\n"
);
}
close(f);
return 0;
}
char* pid_filename;
char* cache_filename;
/* Wait until the next second, and return the EPOCH */
time_t wait_until_next_second() {
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
time_t current_epoch = tp.tv_sec;
long nsec_to_sleep = 1000*1000*1000 - tp.tv_nsec;
/* Only sleep if needed */
if (nsec_to_sleep > 0) {
tp.tv_sec = 0;
tp.tv_nsec = nsec_to_sleep;
nanosleep(&tp, NULL);
}
return current_epoch + 1;
}
int acquire() {
/* fork ourselves if not asked otherwise */
char* no_fork = getenv("no_fork");
if (! no_fork || strcmp("1", no_fork)) {
if (fork()) return;
// we are the child, complete the daemonization
/* Close standard IO */
fclose(stdin);
fclose(stdout);
fclose(stderr);
/* create new session and process group */
setsid();
}
/* write the pid */
FILE* pid_file = fopen(pid_filename, "w");
fprintf(pid_file, "%d\n", getpid());
fclose(pid_file);
/* Reading /proc/stat */
int f = open(PROC_STAT, O_RDONLY);
/* open the spoolfile */
int cache_file = open(cache_filename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
/* loop each second */
while (1) {
/* wait until next second */
time_t epoch = wait_until_next_second();
const int buffer_size = 64 * 1024;
char buffer[buffer_size];
if (lseek(f, 0, SEEK_SET) < 0) {
return fail("cannot seek " PROC_STAT);
}
// whole PROC file can be read in 1 syscall
if (read(f, buffer, buffer_size) <= 0) {
return fail("cannot read " PROC_STAT);
}
// ignore the 1rst line
char* line; char *saveptr;
const char* newl = "\n";
/* lock */
flock(cache_file, LOCK_EX);
int nif = -2;
for (line = strtok_r(buffer, newl, &saveptr); line; line = strtok_r(NULL, newl, &saveptr)) {
// Skip the header lines
if (nif ++ < 0) { continue; }
char if_id[64];
uint_fast64_t r_bytes, r_packets, r_errs, r_drop, r_fifo, r_frame, r_compressed, r_multicast;
uint_fast64_t t_bytes, t_packets, t_errs, t_drop, t_fifo, t_frame, t_compressed, t_multicast;
sscanf(line, "%s"
" "
"%llu %llu %llu %llu %llu %llu %llu %llu"
" "
"%llu %llu %llu %llu %llu %llu %llu %llu"
, if_id
, &r_bytes, &r_packets, &r_errs, &r_drop, &r_fifo, &r_frame, &r_compressed, &r_multicast
, &t_bytes, &t_packets, &t_errs, &t_drop, &t_fifo, &t_frame, &t_compressed, &t_multicast
);
// Remove trailing ':' of if_id
if_id[strlen(if_id) - 1] = '\0';
char out_buffer[1024];
sprintf(out_buffer,
"multigraph if_%s_1sec" "\n"
"up.value %ld:%llu" "\n"
"down.value %ld:%llu" "\n"
, if_id
, epoch, r_bytes
, epoch, t_bytes
);
write(cache_file, out_buffer, strlen(out_buffer));
}
/* unlock */
flock(cache_file, LOCK_UN);
}
close(cache_file);
close(f);
return 0;
}
int fetch() {
FILE* cache_file = fopen(cache_filename, "r+");
/* lock */
flock(fileno(cache_file), LOCK_EX);
/* cat the cache_file to stdout */
char buffer[1024];
while (fgets(buffer, 1024, cache_file)) {
printf("%s", buffer);
}
ftruncate(fileno(cache_file), 0);
fclose(cache_file);
return 0;
}
int main(int argc, char **argv) {
/* resolve paths */
char *MUNIN_PLUGSTATE = getenv("MUNIN_PLUGSTATE");
/* Default is current directory */
if (! MUNIN_PLUGSTATE) MUNIN_PLUGSTATE = ".";
size_t MUNIN_PLUGSTATE_length = strlen(MUNIN_PLUGSTATE);
pid_filename = malloc(MUNIN_PLUGSTATE_length + strlen("/" PLUGIN_NAME ".") + strlen("pid") + 1); pid_filename[0] = '\0';
cache_filename = malloc(MUNIN_PLUGSTATE_length + strlen("/" PLUGIN_NAME ".") + strlen("value") + 1); cache_filename[0] = '\0';
strcat(pid_filename, MUNIN_PLUGSTATE);
strcat(pid_filename, "/" PLUGIN_NAME "." "pid");
strcat(cache_filename, MUNIN_PLUGSTATE);
strcat(cache_filename, "/" PLUGIN_NAME "." "value");
if (argc > 1) {
char* first_arg = argv[1];
if (! strcmp(first_arg, "config")) {
return config();
}
if (! strcmp(first_arg, "acquire")) {
return acquire();
}
}
return fetch();
}
/***** DEMO
/proc/net/dev sample
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 4364 54 0 0 0 0 0 0 4364 54 0 0 0 0 0 0
eth0: 3459461624 22016512 0 70 0 0 0 0 3670486138 18117144 0 0 0 0 0 0
*****/

View file

@ -1,84 +0,0 @@
#!/bin/sh
#
# Plugin to monitor CPU usage, for a selected set of processes. Tested on FreeBSD.
#
# Author: Erik Cederstrand
# Based on http://waste.mandragor.org/munin_tutorial/cpubyuser
# Thanks to Yann Hamon.
#
# Usage: Place in /usr/local/etc/munin/plugins/ (or link it there using ln -s)
# Add this to your /ur/local/etc/munin/plugin-conf.d/plugins.conf:
# [cpubyproc]
# env.procs httpd java
#
# httpd and java being a list of the processes to monitor.
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#
#%# family=auto
#%# capabilities=autoconf
if [ "$1" = "autoconf" ] ; then
if [ -n "$procs" ] ; then
echo "yes"
else
echo "\$procs not defined."
fi
exit
fi
if [ "$1" = "config" ] ; then
echo "graph_args --base 1000 -r --lower-limit 0";
echo "graph_title CPU usage, by process";
echo "graph_category system";
echo "graph_info This graph shows CPU usage, for monitored processes.";
echo 'graph_vlabel %'
echo 'graph_scale no'
echo 'graph_period second'
echo "graph_order $procs"
FIRSTPROC=1;
for proc in $procs; do
echo "${proc}.label $proc"
echo "${proc}.info CPU used by process $proc"
echo "${proc}.type GAUGE"
if [ $FIRSTPROC -eq 1 ] ; then
echo "${proc}.draw AREA"
export FIRSTPROC=0;
else
echo "${proc}.draw STACK"
fi
done ;
exit
fi
for proc in $procs ; do {
ps axo 'pcpu,comm' | grep "$proc" |
awk '
BEGIN {
FS=" "
CPU_PROC=0
}
{
CPU_PROC+=$0
}
END {
print "'$proc'.value "CPU_PROC
}'
}
done;

View file

@ -1,118 +0,0 @@
#! /bin/sh
# Multigraph CPU plugin
# It shows a global cpu graph, and you can drill down per-core
PLUGINBASE=$(basename $0)
emit_config()
{
cat <<EOF
graph_title CPU usage $1
graph_order system user nice idle iowait irq softirq
graph_vlabel %
graph_scale no
graph_info This graph shows how CPU time is spent.
graph_category system
graph_period second
system.label system
system.draw AREA
system.min 0
system.type DERIVE
system.info CPU time spent by the kernel in system activities
user.label user
user.draw STACK
user.min 0
user.type DERIVE
user.info CPU time spent by normal programs and daemons
nice.label nice
nice.draw STACK
nice.min 0
nice.type DERIVE
nice.info CPU time spent by nice(1)d programs
idle.label idle
idle.draw STACK
idle.min 0
idle.type DERIVE
idle.info Idle CPU time
iowait.label iowait
iowait.draw STACK
iowait.min 0
iowait.type DERIVE
iowait.info CPU time spent waiting for I/O operations to finish when there is nothing else to do.
irq.label irq
irq.draw STACK
irq.min 0
irq.type DERIVE
irq.info CPU time spent handling interrupts
softirq.label softirq
softirq.draw STACK
softirq.min 0
softirq.type DERIVE
softirq.info CPU time spent handling "batched" interrupts
steal.label steal
steal.draw STACK
steal.min 0
steal.type DERIVE
steal.info The time that a virtual CPU had runnable tasks, but the virtual CPU itself was not running
guest.label guest
guest.draw STACK
guest.min 0
guest.type DERIVE
guest.info The time spent running a virtual CPU for guest operating systems under the control of the Linux kernel.
guest_nice.label guest
guest_nice.draw STACK
guest_nice.min 0
guest_nice.type DERIVE
guest_nice.info The time spent running a virtual CPU for niced guest operating systems under the control of the Linux kernel.
EOF
}
CPUS=$(grep '^cpu[0-9]' /proc/stat | cut -d ' ' -f 1)
if [ "$1" = "config" ]
then
echo multigraph $PLUGINBASE
emit_config
# Emit one subgraph per core
for cpu in $CPUS
do
echo multigraph $PLUGINBASE.$cpu
emit_config $cpu
done
exit 0
fi
emit_values()
{
while read key user nice system idle iowait irq softirq steal guest guest_nice
do
[ "$guest_nice" = "" ] && guest_nice=0
[ "$key" != "$1" ] && continue
cat <<EOF
system.value $system
user.value $user
nice.value $nice
idle.value $idle
iowait.value $iowait
irq.value $irq
softirq.value $softirq
steal.value $steal
guest.value $guest
guest_nice.value $guest_nice
EOF
done < /proc/stat
}
# Values
echo multigraph $PLUGINBASE
emit_values cpu
# Emit one subgraph per core
for cpu in $CPUS
do
echo multigraph $PLUGINBASE.$cpu
emit_values $cpu
done
exit 0

View file

@ -1,111 +0,0 @@
#!/usr/bin/perl
#
# Copyright 2012 Chris Wilson
# Copyright 2006 Holger Levsen
#
# This plugin monitors ALL processes on a system. No exceptions. It can
# produce very big graphs! But if you want to know where your CPU time
# is going without knowing what to monitor in advance, this can help;
# or in addition to one of the more specific CPU plugins to monitor
# just Apache or MySQL, for example.
#
# It's not obvious what the graph heights actually mean, even to me.
# Each counter is a DERIVE (difference since the last counter reading)
# of the CPU time usage (in seconds) accounted to each process, summed
# by the process name, so all Apache and all MySQL processes are grouped
# together. Processes with no CPU usage at all are ignored. Processes
# that die may not appear on the graph, and anyway their last chunk of
# CPU usage before they died is lost. You could modify this plugin to
# read SAR/psacct records if you care about that.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#scriptname=`basename $0`
#vsname=`echo $scriptname | perl -ne '/^vserver_proc_VM_(.*)/ and print $1'`
#if [ "$1" = "suggest" ]; then
# ls -1 /etc/vservers
# exit 0
#elif [ -z "$vsname" ]; then
# echo "Must be used with a vserver name; try '$0 suggest'" >&2
# exit 2
#fi
use strict;
use warnings;
my $cmd = "ps -eo time,comm h";
open PS, "$cmd|" or die "Failed to run ps command: $cmd: $!";
# my $header_line = <PS>;
my %total_cpu_by_process;
while (<PS>)
{
my @fields = split;
my $cputime = $fields[0];
my $process = $fields[1];
# remove any / and everything after it from the process name,
# e.g. kworker/0:2 -> kworker
$process =~ s|/.*||;
# remove any . at the end of the name (why does this appear?)
# $process =~ s|\.$||;
# change any symbol that's not allowed in a munin variable name to _
$process =~ tr|a-zA-Z0-9|_|c;
my @times = split /:/, $cputime;
my @days = split /-/, $times[0];
if ($days[1]) {
$cputime = ((($days[0] * 24) + $days[1]) * 60 + $times[1]) * 60 + $times[2];
} else {
$cputime = (($times[0] * 60) + $times[1]) * 60 + $times[2];
}
$total_cpu_by_process{$process} += $cputime;
}
foreach my $process (keys %total_cpu_by_process)
{
# remove all processes with 0 cpu time
if (not $total_cpu_by_process{$process})
{
delete $total_cpu_by_process{$process};
}
}
close(PS);
if (@ARGV and $ARGV[0] eq "config")
{
print <<END;
graph_title CPU time by Process
graph_args --base 1000
graph_vlabel seconds
graph_category system
graph_info Shows CPU time used by each process name
END
my $stack = 0;
sub draw() { return $stack++ ? "STACK" : "AREA" }
print map
{
"$_.label $_\n" .
"$_.min 0\n" .
"$_.type DERIVE\n" .
"$_.draw " . draw() . "\n"
} sort keys %total_cpu_by_process;
}
else
{
print map
{
"$_.value $total_cpu_by_process{$_}\n"
} sort keys %total_cpu_by_process;
}
exit(0);

View file

@ -1,129 +0,0 @@
#!/bin/bash
#
# Plugin made by Dju
# useful to know your freebox uptime, and to see when it has rebooted ;)
#
# Uses nmap to get the uptime (by tcp connection, RFC1323)
# ports usually opened on the freebox: 80 554 9100
#
# ----------------------------------------------------------------------------------------------------
# nmap example with the -O option
# on a freebox v5
#
# Starting Nmap 4.62 ( http://nmap.org ) at 2010-12-17 02:25 CET
# Interesting ports on mafreebox.freebox.fr (212.27.38.253):
# Not shown: 1712 filtered ports
# PORT STATE SERVICE
# 80/tcp open http
# 554/tcp open rtsp
# 9100/tcp open jetdirect
# Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
# Device type: remote management
# Running: HP embedded
# OS details: HP Onboard Administrator management console
# Uptime: 7.226 days (since Thu Dec 9 21:01:44 2010)
#
# OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
# Nmap done: 1 IP address (1 host up) scanned in 29.279 seconds
# ----------------------------------------------------------------------------------------------------
#
# by using nmap on a specific tcp port, the detection is pretty fast (2-5 seconds)
# with this command: nmap -O --osscan-guess -p80 remote_host
#
# if you dont want nmap to query your freebox each time, set CACHE_HOURS=n
# to keep the uptime in cache for n hours
# if not, set CACHE_HOURS=0
#
# to allow this plugin to use nmap, edit /etc/munin/plugin-conf.d/munin-node and add
# [FreeboxUptime]
# user root
#
# exit value if error:
# 1: nmap not installed
# 2: freebox not reachable by ping
# 3: uptime not found in nmap result
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=manual
#%# capabilities=autoconf
CACHE_FILE=/var/lib/munin/plugin-state/FreeboxUptime.cache
CACHE_HOURS=3
NMAP=$(which nmap)
TCP_PORT=9100
FREEBOX_HOST=mafreebox.freebox.fr
# check if network connection is ok
if ping -c1 -w1 -s20 $FREEBOX_HOST 2>/dev/null > /dev/null; then
PING=1
else
PING=0
fi
if [ "$1" = "autoconf" ]; then
if [ -z "$NMAP" ]; then
echo "no (nmap not installed)"
exit 1
else
if [ $PING -eq 0 ]; then
echo "no (Freebox not reachable)"
exit 2
else
echo yes
exit 0
fi
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Freebox Uptime'
echo 'graph_category system'
echo 'graph_args --base 1000 -l 0 '
echo 'graph_vlabel uptime in days'
graph_info="Shows the uptime of your freebox (cache: ${CACHE_HOURS}h"
if [ -f $CACHE_FILE ]; then
lastCheck=$(stat -c %z $CACHE_FILE | cut -d"." -f1)
lastReboot=$(awk -F"@" '{print $2}' $CACHE_FILE)
graph_info="${graph_info} - last check: ${lastCheck} - last reboot: $lastReboot"
else
graph_info="${graph_info})"
fi
echo "graph_info ${graph_info}"
echo 'uptime.label uptime'
echo 'uptime.draw AREA'
exit 0
fi
if [ -z "$NMAP" ]; then
exit 1
elif [ $PING -eq 0 ]; then
exit 2
else
use_nmap=1
if [ -f $CACHE_FILE ]; then
ts_cache=$(stat -c %Y $CACHE_FILE)
ts_now=$(date "+%s")
sec_diff=$(expr $ts_now - $ts_cache)
hours_diff=$(expr $sec_diff / 3600)
if [ $hours_diff -lt $CACHE_HOURS ]; then
use_nmap=0
uptime=$(cat $CACHE_FILE | awk -F"@" '{print $1}')
fi
fi
if [ $use_nmap -eq 1 ]; then
uptime=$(nmap -O --osscan-guess -p${TCP_PORT} ${FREEBOX_HOST} | grep Uptime)
if [ -z "$uptime" ]; then
exit 3
else
lastReboot=$(echo $uptime | grep -o '(since .*)' | sed 's/(since //g')
uptime=$(echo $uptime | awk '{print $2}')
echo "${uptime}@${lastReboot}" > $CACHE_FILE
fi
fi
echo "uptime.value ${uptime}"
fi

View file

@ -1,79 +0,0 @@
#!/bin/bash
#
# Script to monitor iostat cpu|tps.
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
judge=`basename $0 | sed 's/^iostat_//g'`
current=`date +%H":"%M":"%S`;
tenMago=`date --date "10 minutes ago" +%H":"%M":"%S`
export LANG=en_US.UTF-8
# autoconf
if [ "$1" == "autoconf" ]; then
if ( sar 1 1 >/dev/null 2>&1 ); then
echo yes
exit 0
else
if [ $? -eq 127 ]; then
echo "no (could not run \"sar\")"
exit 1
else
echo no
exit 1
fi
fi
fi
ARRAY=( `sar -p -d -s ${tenMago} -e ${current} | grep -v nodev | grep "Average" | awk '{ print $2 , $3 , $10 }'` )
# config
if [ "$1" == "config" ]; then
if [ "$judge" == cpu_average ]; then
echo 'graph_title iostat util'
echo 'graph_args --upper-limit 100 -l 0'
echo 'graph_vlabel %'
echo 'graph_category System'
for (( i=0 ; i<${#ARRAY[*]} ; i++ )) ; do
echo "_dev_${ARRAY[i]}.label ${ARRAY[i]}"
i=`expr $i + 2`
done
exit 0
fi
if [ "$judge" == tps_average ]; then
echo 'graph_title iostat tps'
echo 'graph_args -l 0'
echo 'graph_vlabel tps'
echo 'graph_category System'
for (( i=0 ; i<${#ARRAY[*]} ; i++ )) ; do
echo "_dev_${ARRAY[i]}.label ${ARRAY[i]}"
i=`expr $i + 2`
done
exit 0
fi
fi
# other
if [ "$judge" == cpu_average ]; then
for (( i=0 ; i<${#ARRAY[*]} ; i++ )) ; do
echo -n "_dev_${ARRAY[i]}.value "
i=`expr $i + 2`
echo "${ARRAY[i]}"
done
fi
if [ "$judge" == tps_average ]; then
for (( i=0 ; i<${#ARRAY[*]} ; i++ )) ; do
echo -n "_dev_${ARRAY[i]}.value "
i=`expr $i + 1`
echo "${ARRAY[i]}"
i=`expr $i + 1`
done
fi

View file

@ -1,64 +0,0 @@
#!/bin/sh
# Kernel Memory usage stats.
# Author: alex@trull.org
#
# Based on the short script at http://wiki.freebsd.org/ZFSTuningGuide (20080820)
#
# Parameters:
#
# config (required)
# autoconf (optional - only used by munin-config)
#
# Magic markers (optional - only used by munin-config and some
# installation scripts):
#%# family=auto
#%# capabilities=autoconf
if [ "$1" = "autoconf" ]; then
if [ -x /sbin/sysctl ]; then
/sbin/sysctl vm.kmem_size_max > /dev/null
if [ $? = "0" ]; then
echo yes
exit 0
else
echo no
exit 1
fi
else
echo no
exit 1
fi
fi
TEXT=`kldstat | tr a-f A-F | awk 'BEGIN {print "ibase=16"}; NR > 1 {print $4}' | bc | awk '{a+=$1}; END {print a}'`
DATA=`vmstat -m | sed 's/K//' | awk '{a+=$3}; END {print a*1024}'`
TOTAL=`echo $DATA $TEXT | awk '{print $1+$2}'`
MAX=`sysctl vm.kmem_size_max | awk '{print $2}'`
if [ "$1" = "config" ]; then
echo 'graph_args --base 1024 -l 0 --vertical-label Bytes'
echo 'graph_title Kernel Memory usage'
echo 'graph_category system'
echo 'graph_info This graph shows kmem usage.'
echo 'graph_order text data'
echo 'text.label text'
echo 'text.info kmem text'
echo 'text.draw AREA'
echo 'data.label data'
echo 'data.info kmem data'
echo 'data.draw STACK'
echo 'total.label total'
echo 'total.info kmem total'
echo 'total.draw LINE'
echo 'max.label max'
echo 'max.info kmem max'
echo 'max.draw LINE2'
exit 0
fi
echo "text.value $TEXT"
echo "data.value $DATA"
echo "total.value $TOTAL"
echo "max.value $MAX"

View file

@ -1,60 +0,0 @@
#!/bin/bash
#
# Plugin to monitor Memory usage inspired by cpubyuser
#
# 2012-05-23 Sebastien Campion
LU=`ps auh | cut -d' ' -f 1 | sort -u`
USERS=`echo $LU`
if [ "$1" = "autoconf" ]; then
if [ -n "$USERS" ]; then
echo "yes"
else
echo "\$USERS not defined."
fi
exit
fi
if [ "$1" = "config" ]; then
echo "graph_args --base 1000 -r --lower-limit 0"
echo "graph_title Memory usage, by user"
echo "graph_category memory"
echo "graph_info This graph shows memory usage, for monitored users."
echo "graph_vlabel KB"
echo "graph_scale no"
echo "graph_period second"
_USERS=${USERS//[-.]/_}
echo "graph_order $_USERS others"
FIRSTUSER=1;
for USER in $USERS "others"; do
_USER=${USER//[-.]/_}
echo "${_USER}.label $USER"
echo "${_USER}.info Memory used by user $USER"
echo "${_USER}.type GAUGE"
if [ $FIRSTUSER -eq 1 ]; then
echo "${_USER}.draw AREA"
FIRSTUSER=0
else
echo "${_USER}.draw STACK"
fi
done
exit
fi
ps -e -o "%z%U" | \
awk -v USERS="$USERS" '
{ if ($2 != "USER") MEM_USER[$2]+=$1 }
END {
others_sum = 0
for (user in MEM_USER) {
m = match(USERS,user)
if (m != 0) {
_user=user
gsub(/[-.]/,"_", _user);
print _user".value", MEM_USER[user]
} else
others_sum += MEM_USER[user]
}
print "others.value", others_sum;
}'

View file

@ -1,89 +0,0 @@
#!/bin/bash
# (c) 2012 - Bushmills
# License : GPLv2
#%# family=auto
#%# capabilities=autoconf
interval=1 # mpstat sampling interval
timeout=1200 # 20 minutes daemon watchdog timeout
watchdog=60 # test for timeout every $watchdog seconds
pluginfull="$0" # full name of plugin
plugin="${0##*/}" # name of plugin
pidfile="$MUNIN_PLUGSTATE/munin.$plugin.pid"
cache="$MUNIN_PLUGSTATE/munin.$plugin.value"
graph="$plugin"
section="system:cpu"
style="AREA"
cpus=$(grep -c ^processor /proc/cpuinfo)
run_watchdog() { # should also trap kill and term signals
kill -0 $(cat $pidfile) 2> /dev/null || rm -f $pidfile
}
run_acquire() {
echo "$$" > $pidfile
LANG=C mpstat -P ALL $interval |
awk -v cpus=$cpus '$2>=0&&$2<99 {print $2, systime(), (100-$11)/cpus; system("");}' >> $cache
rm -f $pidfile $cache
}
run_daemon() {
run_watchdog
if [ -f $pidfile ]; then
touch $pidfile
else
$pluginfull acquire &
fi
}
# --------------------------------------------------------------------------
run_autoconf() {
run=(yes no)
type -t mpstat > /dev/null
echo "${run[$?]}"
}
run_config() {
run_daemon
cat << EOF
graph_title $graph
graph_category $section
graph_vlabel average cpu use %
graph_scale no
graph_total All CPUs
update_rate 1
graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 1y
EOF
cpun=0
for ((i=0; i<$cpus; i++)); do
cat << EOF
cpu${cpun}.label CPU $cpun
cpu${cpun}.draw $style
cpu${cpun}.min 0
EOF
style=STACK
((cpun++))
done
}
run_fetch() {
run_daemon
awk 'NF==3 {print "cpu" $1 ".value " $2 ":" $3}' $cache
> $cache
}
run_${1:-fetch}
exit 0
# export -f functionname export functionname to subshell, avoiding the need
# for locating plugin for subshell calling, when process needs a different
# pid. Instead, $SHELL -c functionname can be used. useful for calling
# acquire which needs a different pid than watchdog, otherwise watchdog
# could/will kill itself when expiring before the watched process is killed.
# not a POSIX feature.

View file

@ -1,221 +0,0 @@
/*
* multicpu1sec C plugin
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <sys/file.h>
#define PROC_STAT "/proc/stat"
int fail(char* msg) {
perror(msg);
return 1;
}
int config() {
/* Get the number of CPU */
int f;
if ( !(f=open(PROC_STAT, O_RDONLY)) ) {
return fail("cannot open " PROC_STAT);
}
// Starting with -1, since the first line is the "global cpu line"
int ncpu = -1;
const int buffer_size = 64 * 1024;
char buffer[buffer_size];
// whole /proc/stat can be read in 1 syscall
if (read(f, buffer, buffer_size) <= 0) {
return fail("cannot read " PROC_STAT);
}
// tokenization per-line
char* line;
char* newl = "\n";
for (line = strtok(buffer, newl); line; line = strtok(NULL, newl)) {
if (! strncmp(line, "cpu", 3)) ncpu ++;
}
close(f);
printf(
"graph_title multicpu1sec\n"
"graph_category system::1sec\n"
"graph_vlabel average cpu use %%\n"
"graph_scale no\n"
"graph_total All CPUs\n"
"update_rate 1\n"
"graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 1y\n"
);
int i;
for (i = 0; i < ncpu; i++) {
printf("cpu%d.label CPU %d\n", i, i);
printf("cpu%d.draw %s\n", i, "AREASTACK");
printf("cpu%d.type %s\n", i, "DERIVE");
printf("cpu%d.min 0\n", i);
}
return 0;
}
char* pid_filename;
char* cache_filename;
/* Wait until the next second, and return the EPOCH */
time_t wait_until_next_second() {
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
time_t current_epoch = tp.tv_sec;
long nsec_to_sleep = 1000*1000*1000 - tp.tv_nsec;
/* Only sleep if needed */
if (nsec_to_sleep > 0) {
tp.tv_sec = 0;
tp.tv_nsec = nsec_to_sleep;
nanosleep(&tp, NULL);
}
return current_epoch + 1;
}
int acquire() {
/* fork ourselves if not asked otherwise */
char* no_fork = getenv("no_fork");
if (! no_fork || strcmp("1", no_fork)) {
if (fork()) return;
// we are the child, complete the daemonization
/* Close standard IO */
fclose(stdin);
fclose(stdout);
fclose(stderr);
/* create new session and process group */
setsid();
}
/* write the pid */
FILE* pid_file = fopen(pid_filename, "w");
fprintf(pid_file, "%d\n", getpid());
fclose(pid_file);
/* Reading /proc/stat */
int f = open(PROC_STAT, O_RDONLY);
/* open the spoolfile */
int cache_file = open(cache_filename, O_CREAT | O_APPEND | O_WRONLY);
/* loop each second */
while (1) {
/* wait until next second */
time_t epoch = wait_until_next_second();
const int buffer_size = 64 * 1024;
char buffer[buffer_size];
if (lseek(f, 0, SEEK_SET) < 0) {
return fail("cannot seek " PROC_STAT);
}
// whole /proc/stat can be read in 1 syscall
if (read(f, buffer, buffer_size) <= 0) {
return fail("cannot read " PROC_STAT);
}
// ignore the 1rst line
char* line;
const char* newl = "\n";
line = strtok(buffer, newl);
/* lock */
flock(cache_file, LOCK_EX);
for (line = strtok(NULL, newl); line; line = strtok(NULL, newl)) {
// Not on CPU lines anymore
if (strncmp(line, "cpu", 3)) break;
char cpu_id[64];
long usr, nice, sys, idle, iowait, irq, softirq;
sscanf(line, "%s %ld %ld %ld %ld %ld %ld %ld", cpu_id, &usr, &nice, &sys, &idle, &iowait, &irq, &softirq);
long used = usr + nice + sys + iowait + irq + softirq;
char out_buffer[1024];
sprintf(out_buffer, "%s.value %ld:%ld\n", cpu_id, epoch, used);
write(cache_file, out_buffer, strlen(out_buffer));
}
/* unlock */
flock(cache_file, LOCK_UN);
}
close(cache_file);
close(f);
return 0;
}
int fetch() {
FILE* cache_file = fopen(cache_filename, "r+");
/* lock */
flock(fileno(cache_file), LOCK_EX);
/* cat the cache_file to stdout */
char buffer[1024];
while (fgets(buffer, 1024, cache_file)) {
printf("%s", buffer);
}
ftruncate(fileno(cache_file), 0);
fclose(cache_file);
return 0;
}
int main(int argc, char **argv) {
/* resolve paths */
char *MUNIN_PLUGSTATE = getenv("MUNIN_PLUGSTATE");
/* Default is current directory */
if (! MUNIN_PLUGSTATE) MUNIN_PLUGSTATE = ".";
size_t MUNIN_PLUGSTATE_length = strlen(MUNIN_PLUGSTATE);
pid_filename = malloc(MUNIN_PLUGSTATE_length + strlen("/multicpu1sec.") + strlen("pid") + 1); pid_filename[0] = '\0';
cache_filename = malloc(MUNIN_PLUGSTATE_length + strlen("/multicpu1sec.") + strlen("value") + 1); cache_filename[0] = '\0';
strcat(pid_filename, MUNIN_PLUGSTATE);
strcat(pid_filename, "/multicpu1sec.pid");
strcat(cache_filename, MUNIN_PLUGSTATE);
strcat(cache_filename, "/multicpu1sec.value");
if (argc > 1) {
char* first_arg = argv[1];
if (! strcmp(first_arg, "config")) {
return config();
}
if (! strcmp(first_arg, "acquire")) {
return acquire();
}
}
return fetch();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

View file

@ -1,64 +0,0 @@
#!/bin/sh
# Julien Francoz CoCoZ <julien@francoz.net>
# graph memory usage detail for a process using /proc/$PID/status
# create a link to this plugin with the syntax proc_yourprocessname_status
# example : proc_master_status pour postfix master process
cmd=`basename "$0"`
process=`echo "$cmd"| cut -d'_' -f 2`
pid=`pgrep -o -x "$process"`
#echo $pid
if [ "$1" = "autoconf" ]; then
if [ -r /proc/$pid/status ]; then
echo yes
exit 0
else
echo no
exit 1
fi
fi
if [ "$1" = "config" ]; then
echo "graph_title Memory usage for process $process"
echo "graph_order VmExe VmLib VmStk VmData VmRSS VmSize"
echo 'graph_vlabel Ko'
echo 'graph_scale no'
echo "graph_info This graph display memory usage for a process"
echo 'graph_category system'
echo 'graph_period second'
echo 'VmExe.label VmExe'
echo 'VmExe.draw AREA'
echo "VmExe.info The size of the executable segment"
echo 'VmLib.label VmLib'
echo 'VmLib.draw STACK'
echo 'VmLib.info The size of the library code'
echo 'VmStk.label VmStk'
echo 'VmStk.draw STACK'
echo 'VmStk.info The stack size'
echo 'VmLck.label VmLck'
echo 'VmLck.draw STACK'
echo 'VmLck.info The amount of locked memory'
echo 'VmData.label VmData'
echo 'VmData.draw STACK'
echo 'VmData.info The size of the Data segment'
echo 'VmRSS.label VmRSS'
echo 'VmRSS.draw LINE2'
echo 'VmRSS.info The amount of memory mapped in RAM ( instead of swapped out)'
echo 'VmSize.label VmSize'
echo 'VmSize.draw LINE2'
echo 'VmSize.info The size of the virtual memory allocated to the process'
exit 0
fi
cat /proc/$pid/status |grep -E '^Vm' | sed -e 's/:/.value/' -e 's/\s\+kB$//' -e 's/\s\+/ /'

View file

@ -1,50 +0,0 @@
#!/bin/sh
# Plugin to get the number of logged in users
# Written by Henrik Andersén 2010 <code@henrikandersen.se>
#
# Copyright (c) 2010, Henrik Andersen
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Henrik Andersen BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
case $1 in
config)
cat <<'EOM'
graph_args --base 1000 -l 0
graph_scale no
graph_category system
graph_info The number of users currently logged into the system
graph_title Logged in users
graph_vlabel users
user.info Number of users currently logged in
user.label users
user.min 0
EOM
exit 0;;
esac
count=$(/usr/bin/who -q )
printf "user.value %i\n" ${count#*=}
exit 0

View file

@ -1,84 +0,0 @@
#!/bin/sh
# -*- sh -*-
: << =cut
=head1 NAME
systemd - Plugin to monitor systemd units state
=head1 APPLICABLE SYSTEMS
Linux systems with systemd installed.
=head1 CONFIGURATION
None needed.
=head1 AUTHOR
Olivier Mehani <shtrom+munin@ssji.net>
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
states="active \
reloading \
inactive \
failed \
activating \
deactivating"
autoconf() {
which systemctl >/dev/null && \
systemctl --state=failed --no-pager --no-legend >/dev/null 2>&1 && echo yes || echo "no (No systemctl or error running it)"
}
config () {
cat << EOF
graph_title Systemd units state
graph_args -l 0
graph_category system
graph_scale no
graph_vlabel units
EOF
for state in $states; do
echo "$state.label $state"
echo "$state.draw AREASTACK"
if [ "$state" = "failed" ]; then
echo "$state.warning 0"
echo "$state.critical 10"
fi
done
}
fetch () {
tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}')
for state in $states ; do
count=$(echo "$tmp" | grep -c "$state$")
echo "$state.value $count"
extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ')
if [ -n "$extinfo" ]; then
echo "$state.extinfo" "$extinfo"
fi
done
}
case $1 in
"autoconf")
autoconf
;;
"config")
config
;;
*)
fetch
;;
esac

View file

@ -1,64 +0,0 @@
#!/bin/bash
#
# Monitors memory usage in openVZ or Virtuozzo
# based on http://www.huschi.net/archiv/speicher-anzeigen-mit-vzfree.html
# Author: Michael Richter, http://osor.de/
# Cleaned up and translated to english by: Marian Sigler <m@qjym.de>, 2010-08-13
#
#%# capabilities=autoconf
BEANCOUNTERS=/proc/user_beancounters
if [ "$1" == "autoconf" ]; then
if [ -e $BEANCOUNTERS ]; then
echo yes
exit 0
else
echo no
exit 1
fi
fi
if [ ! -r $BEANCOUNTERS ]; then
echo "$BEANCOUNTERS not readable" >&2
exit 1
fi
if [ "$1" == "config" ]; then
limit=$(awk '/privvmpages/ {print $5*4096}' $BEANCOUNTERS)
cut -c9- <<EOF
graph_args --base 1024 -l 0 --vertical-label bytes --upper-limit $limit
graph_title VPS memory usage
graph_category system
graph_info Shows memory usage and VPS memory limits.
graph_order maxheld held oomguar barrier limit
held.label held
held.draw AREA
held.info currently held memory
maxheld.label maxheld
maxheld.draw AREA
maxheld.info maximum held memory
oomguar.label guaranteed
oomguar.draw LINE2
oomguar.info memory guaranteed for OOM
barrier.label barrier
barrier.draw LINE2
barrier.info memory usage barrier
limit.label limit
limit.draw LINE2
limit.info memory usage limit
EOF
exit 0
fi
if [ -n "$1" ]; then
echo "Invalid argument: $1" >&2
exit 1
fi
awk '/privvmpages/ {print "held.value", $2*4096 "\nmaxheld.value", $3*4096 "\nbarrier.value", $4*4096 "\nlimit.value", $5*4096}' $BEANCOUNTERS
awk '/oomguarpages/ { print "oomguar.value", $4*4096 }' $BEANCOUNTERS

View file

@ -1,59 +0,0 @@
#!/bin/sh
#%# family=auto
#%# capabilities=autoconf
PRSTAT=/usr/bin/prstat
PRSTAT_OPTS="-Z -n 1,99 1 1"
if [ "$1" = 'autoconf' ]; then
if [ -f $PRSTAT ]; then
zones=`/usr/sbin/zoneadm list | wc -l`
if [ $zones -gt 1 ]; then
echo yes
else
echo yes
fi
exit 0
else
echo no
exit 1
fi
fi
if [ "$1" = 'config' ]; then
echo 'graph_title zone cpu usage'
echo 'graph_args --upper-limit 100'
echo 'graph_category system'
stack=AREA
$PRSTAT $PRSTAT_OPTS | sed '1,/^ZONEID/d' | grep -v '^Total' | while read i; do
oIFS="$IFS"
IFS='
'
set -$- $i
name=$1
label=$8
printf "$name.label $label\n$name.draw $stack\n$name.warn 95\n"
IFS="$oIFS"
stack=STACK
done
exit 0
fi
# ZONEID NPROC SWAP RSS MEMORY TIME CPU ZONE $
# 0 48 470M 482M 1.5% 4:05:57 0.0% global $
# 3 85 2295M 2369M 7.2% 0:36:36 0.0% pearljam $
# 6 74 13G 3273M 10% 16:51:18 0.0% ministry $
# Total: 207 processes, 709 lwps, load averages: 0.05, 0.06, 0.11$
$PRSTAT $PRSTAT_OPTS | sed '1,/^ZONEID/d' | grep -v '^Total' | while read i; do
oIFS="$IFS"
IFS='%
'
set -$- $i
name=$1
value=$7
printf "$name.value $value\n"
IFS="$oIFS"
done

View file

@ -1,61 +0,0 @@
#!/bin/sh
# This plugin shows Solaris zone memory usage.
#%# family=auto
#%# capabilities=autoconf
PRSTAT=/usr/bin/prstat
PRSTAT_OPTS="-Z -n 1,99 1 1"
if [ "$1" = 'autoconf' ]; then
if [ -f $PRSTAT ]; then
zones=`/usr/sbin/zoneadm list | wc -l`
if [ $zones -gt 1 ]; then
echo yes
else
echo yes
fi
exit 0
else
echo no
exit 1
fi
fi
if [ "$1" = 'config' ]; then
echo 'graph_title zone memory usage'
echo 'graph_args --upper-limit 100'
echo 'graph_category system'
stack=AREA
$PRSTAT $PRSTAT_OPTS | sed '1,/^ZONEID/d' | grep -v '^Total' | while read i; do
oIFS="$IFS"
IFS='
'
set -$- $i
name=$1
label=$8
printf "$name.label $label\n$name.draw $stack\n$name.warn 95\n"
IFS="$oIFS"
stack=STACK
done
exit 0
fi
# ZONEID NPROC SWAP RSS MEMORY TIME CPU ZONE $
# 0 48 470M 482M 1.5% 4:05:57 0.0% global $
# 3 85 2295M 2369M 7.2% 0:36:36 0.0% pearljam $
# 6 74 13G 3273M 10% 16:51:18 0.0% ministry $
# Total: 207 processes, 709 lwps, load averages: 0.05, 0.06, 0.11$
$PRSTAT $PRSTAT_OPTS | sed '1,/^ZONEID/d' | grep -v '^Total' | while read i; do
oIFS="$IFS"
IFS='%
'
set -$- $i
name=$1
value=$5
printf "$name.value $value\n"
IFS="$oIFS"
done