diff --git a/check_journallog b/check_journallog new file mode 100755 index 0000000000000000000000000000000000000000..5f85292202c2d37d59fabf6dd4d17697b432218c --- /dev/null +++ b/check_journallog @@ -0,0 +1,130 @@ +#!/bin/bash +# ====================================================================== +# +# Check count of written entries in journallog +# +# requirements: +# - journalctl +# +# ---------------------------------------------------------------------- +# 2023-10-12 v0.1 <axel.hahn@unibe.ch> initial version +# ====================================================================== + + +. $( dirname $0 )/inc_pluginfunctions + +export self_APPVERSION=0.1 + +tmpfile=/tmp/last_journallog_line_${USER}.txt + +# ---------------------------------------------------------------------- +# FUNCTIONS +# ---------------------------------------------------------------------- + +# show help text +function showHelp(){ + local _self; _self=$(basename $0) +cat <<EOF +$( ph.showImlHelpHeader ) + +Show number of lines in journallog per min. +A strong change of the written lines per min COULD indicate a problem. + +The status is ... +- unknown - if journalctl is not available + - if the script is started the 1st time and stores the last + line of the journallog +- ok - when showing written tnries per min +- warning/ critical - when giving -c and -w parameter values + +This plugin sends performancedata. + +SYNTAX: + $_self [-h] [-w WARN_LIMIT] [-c CRITICAL_LIMIT] + +OPTIONS: + -h this help + -w VALUE warning level (default: 0) + -c VALUE critical level (default: 0) + +PARAMETERS: + None. + +EXAMPLES: + + $_self show count of newly written log entries + $_self -w 100 -c 200 + Set warning level to 100 written lines per min and + critical to 200. + $_self -w 100 + Set warning level to 100 written lines per min but + no critical limit. This check then never will send a + critical status. +EOF +} + +# ---------------------------------------------------------------------- +# MAIN +# ---------------------------------------------------------------------- + +# handle params +ph.hasParamoption "h" "$@"; bOptHelp=$? + +if [ $bOptHelp -eq 0 ]; then + showHelp + exit 0 +fi + +ph.require journalctl + +typeset -i iWarnLimit=$( ph.getValueWithParam 0 w "$@") +typeset -i iCriticalLimit=$( ph.getValueWithParam 0 c "$@") + + +lastLine=$( cat "$tmpfile" 2>/dev/null ) +if [ -z "$lastLine" ]; then + ph.setStatus unknown + ph.status "Initializing ... storing last line of jorunallog ..." + journalctl -n 1 > "$tmpfile" +else + ts=$( cut -f 1-3 -d " " <<< "$lastLine" ) + typeset -i iAge; iAge=$( ph.getFileAge "$tmpfile" ) + data=$( journalctl --since "$ts" ) + + # for next run: insert last handled line + tail -1 <<< "$data" > "$tmpfile" + + # detect last seen position and count lines from there + typeset -i iTotal; iTotal=$( wc -l <<< "$data" ) + typeset -i iFrom; iFrom=$( grep -Fn "$lastLine" <<< "$data" | head -1 | cut -f 1 -d ':' ) + typeset -i iLines; iLines=$iTotal-$iFrom + typeset -i iLinespermin; iLinespermin=$iLines*60/$iAge + + if [ $iWarnLimit -gt 0 -a $iWarnLimit -le $iLinespermin ]; then + ph.setStatus "warning" + fi + if [ $iCriticalLimit -gt 0 -a $iCriticalLimit -le $iLinespermin ]; then + ph.setStatus "critical" + fi + + ph.perfadd "lines-per-min" "${iLinespermin}" + + # output + ph.status "Journallog stored $iLinespermin lines per min" + sLimits="" + test $iWarnLimit -gt 0 && sLimits+="WARNING at $iWarnLimit" + test $iWarnLimit -gt 0 || sLimits+="No warning level" + sLimits+="; " + test $iCriticalLimit -gt 0 && sLimits+="CRITICAL at $iCriticalLimit" + test $iCriticalLimit -gt 0 || sLimits+="No critical level " + + echo "Limits: $sLimits" + # echo "Found $iLines new line(s) in the last $iAge sec" + +fi + +# cat "$tmpfile" + +ph.exit + +# ---------------------------------------------------------------------- diff --git a/docs/20_Checks/_index.md b/docs/20_Checks/_index.md index c02273cecd0e289f662c907420303686f4024179..1dce8b7e02e6d1fdf262351d9892bf9c0ab5eacc 100644 --- a/docs/20_Checks/_index.md +++ b/docs/20_Checks/_index.md @@ -26,6 +26,7 @@ There is one include script used by all checks: * [check_haproxy_health](check_haproxy_health.md) * [check_haproxy_status](check_haproxy_status.md) * [check_http](check_http.md) +* [check_journallog](check_journallog.md) * [check_memory](check_memory.md) * [check_mysqlserver](check_mysqlserver.md) * [check_netio](check_netio.md) diff --git a/docs/20_Checks/check_journallog.md b/docs/20_Checks/check_journallog.md new file mode 100644 index 0000000000000000000000000000000000000000..2012aecd79bfc0a81392145993e38c8d38be2bdf --- /dev/null +++ b/docs/20_Checks/check_journallog.md @@ -0,0 +1,71 @@ +# Check Systemd unit + +## Introduction + +This check shows the count of written entries in the journallog per minute. +This check requires access to journalctl. + +## Requirements + +* `journalctl` binary + +## Syntax + +```txt +______________________________________________________________________ + +CHECK_JOURNALLOG +v0.1 + +(c) Institute for Medical Education - University of Bern +Licence: GNU GPL 3 + +https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_journallog.html +______________________________________________________________________ + +Show number of lines in journallog per min. +A strong change of the written lines per min COULD indicate a problem. + +The status is ... +- unknown - if journalctl is not available + - if the script is started the 1st time and stores the last + line of the journallog +- ok - when showing written tnries per min +- warning/ critical - when giving -c and -w parameter values + +This plugin sends performancedata. + +SYNTAX: + check_journallog [-h] [-w WARN_LIMIT] [-c CRITICAL_LIMIT] + +OPTIONS: + -h this help + -w VALUE warning level (default: 0) + -c VALUE critical level (default: 0) + +PARAMETERS: + None. + +EXAMPLES: + + check_journallog show count of newly written log entries + check_journallog -w 100 -c 200 + Set warning level to 100 written lines per min and + critical to 200. + check_journallog -w 100 + Set warning level to 100 written lines per min but + no critical limit. This check then never will send a + critical status. + +``` + +## Examples + +``./check_journallog`` returns + +```txt +./check_journallog +OK: Journallog stored 14 lines per min +Limits: No warning level; No critical level + |lines-per-min=14;; +```