2

I have a metric that should only be checked and logged daily.

Calculation is CPU-intensive, and querying multiple times per day returns the same value (i.e. it just wastes CPU time).

Is it possible to make a plugin that is queried only once per day?

I've tried to specify "update_rate 3600" in munin-node config for this plugin, but it was still queried every 5 minutes. Graphs are also displayed with 5 minutes granularity.

Surely, local cache is an option, but makes things more complicated.

BarsMonster
  • 724
  • 4
  • 12
  • 26

2 Answers2

1

You could play with cron to have two entries in /etc/cron.d/munin. The normal one which call munin-cron every 5 minutes (*/5) with the base config where you remove reference to your daily run plugin, and a second one which call only the update (munin-update) every day at 7:30 for example (30 7) with a extra config file you will have to write that only deal with the daily plugin.

*/5 * * * * munin-cron   --config /etc/munin/munin.conf
30 7 * * *  munin-update --config /etc/munin/munin_daily_plugin.conf

I don't have munin anymore to play and test it, but nevertheless, as far as I remember how it works, it should help you to solve your issue.

xenlo
  • 140
  • 7
  • 1
    If you were to set a custom interval on some plugins, the resulting graph would be missing metrics. You'll end up with one plot per job, while every occurrence that was skipped would be blank. – SYN Nov 15 '19 at 15:09
1

Although this does not exactly answer your question, it could be a workaround. Consider the following munin plugin:

$ cat /usr/share/munin/plugins/pool_
#!/bin/sh

pool_dir=/tmp/munin-pool
probe=`basename $0 | sed 's|^pool_||'`

test -d $pool_dir/$probe || exit 1
if test "$1" = autoconf; then
    test -s $pool_dir/$probe/autoconf || exit 0
    cat $pool_dir/$probe/autoconf
elif test "$1" = config; then
    test -s $pool_dir/$probe/config || exit 0
    cat $pool_dir/$probe/config
else
    test -s $pool_dir/$probe/value || exit 0
    cat $pool_dir/$probe/value
fi

exit 0

And this crontab:

#!/bin/sh

pool_dir=/tmp/munin-pool
TMPFILE=/tmp/`basename $0`.$$

if test -s $pool_dir/lock; then
    pid=`cat $pool_dir/lock`
    if ps ax | grep "$pid[ ]" >/dev/null; then
    exit 0
    fi
fi
test -d $pool_dir || mkdir $pool_dir
echo $$ >$pool_dir/lock

test -d <%=@conf_dir%>/plugins-pool || exit 1
cd /etc/munin/plugins-pool

for probe in *
do
    test -d $pool_dir/$probe || mkdir -p $pool_dir/$probe
    if ! test -f $pool_dir/$probe/autoconf; then
        ./$probe autoconf >$TMPFILE
        test -s $TMPFILE && mv $TMPFILE $pool_dir/$probe/autoconf
    fi
    if ! test -f $pool_dir/$probe/config; then
        ./$probe config >$TMPFILE
        test -s $TMPFILE && mv $TMPFILE $pool_dir/$probe/config
    fi
    ./$probe >$TMPFILE
    test -s $TMPFILE && mv $TMPFILE $pool_dir/$probe/value
done 2>&1 | awk '{print strftime("[%Y/%m/%d - %H:%M:%S] "), $0}' ><munin-log-dir>/munin-pooler.log

rm -f $pool_dir/lock

exit 0

In /etc/munin/plugin-pool, I would link the probes whose results I want to cache locally:

ln -sf /usr/share/munin/plugins/some_probe /etc/munin/plugin-pool/

The crontab would iterate over those, keep track of the results in /tmp/munin-pool/. While the pool_ probe would query that cache:

ln -sf /usr/share/munin/plugins/pool_ /etc/munin/plugins/some_probe

So instead of re-querying a service every five minutes, I can gather metrics from my crontab, on whatever schedule I need. Or, in my use case, if a probe usually exceeds munin query timeout, you're not left with empty graphs.

If we were to scrape some probes on different intervals, without such workaround, then the resulting graphs would only include those points you did gather, and lots of blanks for those we "missed".

SYN
  • 1,751
  • 9
  • 14