--- /dev/null
+#!/bin/sh
+
+mem_apps_apps="netdata asterisk squid apache2 mysqld dovecot cupsd sshd named clamd smbd"
+
+# these are required for computing memory in bytes and cpu in seconds
+#mem_apps_pagesize="`getconf PAGESIZE`"
+#mem_apps_clockticks="`getconf CLK_TCK`"
+
+mem_apps_check() {
+ # this should return:
+ # - 0 to enable the chart
+ # - 1 to disable the chart
+
+ if [ -z "$mem_apps_apps" ]
+ then
+ echo >&2 "mem_apps: Please set mem_apps_apps='command1 command2 ...' in $confd/mem_apps_apps.conf"
+ return 1
+ fi
+ return 0
+}
+
+mem_apps_bc_finalze=
+
+mem_apps_create() {
+
+ cat <<EOF1
+CHART system.apps '' "Apps Memory" "MB" "mem" "mem" stacked 20000 $update_every
+EOF1
+
+ local x=
+ for x in $mem_apps_apps
+ do
+
+cat <<EOF1
+DIMENSION $x $x absolute 1 1024
+EOF1
+ # this string is needed later in the update() function
+ # to finalize the instructions for the bc command
+ mem_apps_bc_finalze="$mem_apps_bc_finalze \"SET $x = \"; $x;"
+ done
+ return 0
+}
+
+mem_apps_egrep="(`echo "$mem_apps_apps" | sed -e "s/^ \+//g" -e "s/ \+$//g" -e "s/ /|/g"`)"
+mem_apps_update() {
+ # do all the work to collect / calculate the values
+ # for each dimension
+ # remember: KEEP IT SIMPLE AND SHORT
+
+ echo "BEGIN system.apps"
+ ps -e -o comm,rss |\
+ egrep "^$mem_apps_egrep " |\
+ ( sed -e "s/ \+/ /g" -e "s/ /+=/g";
+ echo "$mem_apps_bc_finalze"
+ ) | bc
+ echo "END"
+
+ return 0
+}
+
squid_create() {
# create the charts
cat <<EOF
-CHART squid.client_bandwidth '' "Squid Client Bandwidth" "kilobits/s" squid squid area 1 $update_every
+CHART net.squid_clients '' "Squid Client Bandwidth" "kilobits/s" squid '' area 20001 $update_every
DIMENSION client_http_kbytes_in in incremental 8 1
DIMENSION client_http_kbytes_out out incremental -8 1
DIMENSION client_http_hit_kbytes_out hits incremental -8 1
-CHART squid.client_requests '' "Squid Client Requests" "requests/s" squid squid line 3 $update_every
+CHART squid.client_requests '' "Squid Client Requests" "requests/s" squid 'none' line 20003 $update_every
DIMENSION client_http_requests requests incremental 1 1
DIMENSION client_http_hits hits incremental 1 1
DIMENSION client_http_errors errors incremental -1 1
-CHART squid.server_bandwidth '' "Squid Server Bandwidth" "kilobits/s" squid squid area 2 $update_every
+CHART net.squid_servers '' "Squid Server Bandwidth" "kilobits/s" squid '' area 20002 $update_every
DIMENSION server_all_kbytes_in in incremental 8 1
DIMENSION server_all_kbytes_out out incremental -8 1
-CHART squid.server_requests '' "Squid Server Requests" "requests/s" squid squid line 4 $update_every
+CHART squid.server_requests '' "Squid Server Requests" "requests/s" squid 'none' line 20004 $update_every
DIMENSION server_all_requests requests incremental 1 1
DIMENSION server_all_errors errors incremental -1 1
EOF
# write the result of the work.
cat <<VALUESEOF
-BEGIN squid.client_bandwidth
+BEGIN net.squid_clients
SET client_http_kbytes_in = $client_http_kbytes_in
SET client_http_kbytes_out = $client_http_kbytes_out
SET client_http_hit_kbytes_out = $client_http_hit_kbytes_out
SET client_http_errors = $client_http_errors
END
-BEGIN squid.server_bandwidth
+BEGIN net.squid_servers
SET server_all_kbytes_in = $server_all_kbytes_in
SET server_all_kbytes_out = $server_all_kbytes_out
END
#!/bin/sh
-check=0
-if [ "$1" = "check" ]
-then
- check=1
- shift
-fi
-
-# default sleep function
-loopsleepms() {
- sleep $1
-}
-# if found and included, this file overwrites loopsleepms()
-# with a high resolution timer function for precise looping.
-. "`dirname $0`/loopsleepms.sh.inc"
-
-# netdata passes the requested update frequency as the first argument
-update_every=$1
-update_every=$(( update_every + 1 - 1)) # makes sure it is a number
-test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
+# -----------------------------------------------------------------------------
+# insternal defaults
pluginsd="plugins.d"
confd="conf.d"
chartsd="charts.d"
myconfig="$confd/charts.d.conf"
minimum_update_frequency=1
+update_every=1 # this is overwritten by the command line
+
+# -----------------------------------------------------------------------------
+# parse parameters
+
+debug=0
+check=0
+chart_only=
+while [ ! -z "$1" ]
+do
+ if [ "$1" = "check" ]
+ then
+ check=1
+ shift
+ continue
+ fi
+
+ if [ -f "$chartsd/$1.chart.sh" ]
+ then
+ debug=1
+ chart_only="`echo $1.chart.sh | sed "s/\.chart\.sh$//g"`"
+ shift
+ continue
+ fi
+
+ if [ -f "$chartsd/$1" ]
+ then
+ debug=1
+ chart_only="`echo $1 | sed "s/\.chart\.sh$//g"`"
+ shift
+ continue
+ fi
+
+ if [ -f "$1" ]
+ then
+ debug=1
+ chart_only="`basename "$1" | sed "s/\.chart\.sh$//g"`"
+ shift
+ continue
+ fi
+
+ # number check
+ n="$1"
+ x=$((n + 1 - 1))
+ if [ "$x" = "$n" ]
+ then
+ update_every=$x
+ shift
+ continue
+ fi
+
+ echo >&2 "Cannot understand parameter $1. Aborting."
+ echo "DISABLE"
+ exit 1
+done
+
+
+# -----------------------------------------------------------------------------
+# load my configuration
-# load the configuration
if [ -f "$myconfig" ]
then
. "$myconfig"
fi
fi
+
+# -----------------------------------------------------------------------------
+# internal checks
+
+# netdata passes the requested update frequency as the first argument
+update_every=$(( update_every + 1 - 1)) # makes sure it is a number
+test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
+
+# check the charts.d directory
if [ ! -d "$chartsd" ]
then
echo >&2 "charts.d: cannot find charts directory '$chartsd'"
echo "DISABLE"
fi
+
+# -----------------------------------------------------------------------------
+# loop control
+
+# default sleep function
+loopsleepms() {
+ sleep $1
+}
+# if found and included, this file overwrites loopsleepms()
+# with a high resolution timer function for precise looping.
+. "`dirname $0`/loopsleepms.sh.inc"
+
+
+# -----------------------------------------------------------------------------
+# charts check functions
+
all_charts() {
cd "$chartsd"
ls *.chart.sh | sed "s/\.chart\.sh$//g"
}
+# -----------------------------------------------------------------------------
+# load the charts
+
active_charts=
for x in `all_enabled_charts`
do
fi
done
+
+# -----------------------------------------------------------------------------
+# check overwrites
+
+# if we only need a specific chart, remove all the others
+debug_time=
+if [ ! -z "$chart_only" ]
+then
+ debug_time=tellwork
+ check_charts=
+ for x in $active_charts
+ do
+ if [ "$x" = "$chart_only" ]
+ then
+ check_charts="$x"
+ break
+ fi
+ done
+ active_charts="$check_charts"
+fi
+
+# stop if we just need a pre-check
if [ $check -eq 1 ]
then
echo "CHECK RESULT"
exit 0
fi
+
+# -----------------------------------------------------------------------------
+# create charts
+
run_charts=
for x in $active_charts
do
fi
done
-# work forever
+
+# -----------------------------------------------------------------------------
+# update dimensions
while [ 1 ]
do
now_charts=$run_charts
done
# wait the time you are required to
- loopsleepms $update_every
+ loopsleepms $debug_time $update_every
done
LOOPSLEEPMS_HIGHRES=2
LOOPSLEEPMS_LASTRUN=0
LOOPSLEEPMS_LASTSLEEP=0
+LOOPSLEEPMS_LASTWORK=0
loopsleepms() {
+ tellwork=0
+ if [ "$1" = "tellwork" ]
+ then
+ local tellwork=1
+ shift
+ fi
+
# the time in seconds to wait, as the first argument
local t=$1
test $LOOPSLEEPMS_LASTRUN -eq 0 && LOOPSLEEPMS_LASTRUN=$now
# calculate ms since last run
- local workms=$((now - LOOPSLEEPMS_LASTRUN - LOOPSLEEPMS_LASTSLEEP))
- # echo "# last loop's work took $workms ms"
+ LOOPSLEEPMS_LASTWORK=$((now - LOOPSLEEPMS_LASTRUN - LOOPSLEEPMS_LASTSLEEP))
+ # echo "# last loop's work took $LOOPSLEEPMS_LASTWORK ms"
+
+ test $tellwork -eq 1 && echo >&2 " >>> DEBUG >>> WORK TOOK $LOOPSLEEPMS_LASTWORK ms"
# calculate ms to sleep
- local mstosleep=$((t - workms))
+ local mstosleep=$((t - LOOPSLEEPMS_LASTWORK))
# echo "# mstosleep is $mstosleep ms"
# if we are too slow, sleep some time