Révision cc6600b4
Addressed PR comments
| plugins/logs/service_events | ||
|---|---|---|
| 8 | 8 |
|
| 9 | 9 |
service_events - Tracks the number of significant event occurrences per service |
| 10 | 10 |
|
| 11 |
This plugin is a riff on the loggrep family (\`loggrep\` and my own \`loggrepx_\`).
|
|
| 11 |
This plugin is a riff on the loggrep family (C<loggrep> and my own C<loggrepx_>).
|
|
| 12 | 12 |
However, rather than focusing on single log files, it focuses on providing |
| 13 | 13 |
insight into all "significant events" happening for a given service, which |
| 14 | 14 |
may be found across several log files. |
| ... | ... | |
| 78 | 78 |
|
| 79 | 79 |
For plugin-specific options, the following rules apply: |
| 80 | 80 |
|
| 81 |
* <type> is any arbitrary string. It just has to match between <type>_logfiles |
|
| 82 |
and <type>_regex. Common values are "apache", "nginx", "apt", "syslog", etc. |
|
| 81 |
* C<< <type> >> is any arbitrary string. It just has to match between |
|
| 82 |
C<< <type>_logfiles >> and C<< <type>_regex >>. Common values are "apache", |
|
| 83 |
"nginx", "apt", "syslog", etc. |
|
| 83 | 84 |
* <service> is a string derived by passing the service name through a filter |
| 84 | 85 |
that removes non-alphabet characters from the beginning and replaces all non- |
| 85 |
alpha-numeric characters with underscore (\`_\`).
|
|
| 86 |
* logfiles are bound to services by matching <service>_logbinding on the full
|
|
| 87 |
logfile path. For example, specifying my_site_logbinding=my-site would bind
|
|
| 88 |
both /var/log/my-site/errors.log and /srv/www/my-site/logs/app.log to the
|
|
| 89 |
defined my-site service.
|
|
| 86 |
alpha-numeric characters with underscore (C<_>).
|
|
| 87 |
* logfiles are bound to services by matching C<< <service>_logbinding >> on the
|
|
| 88 |
full logfile path. For example, specifying C<my_site_logbinding=my-site> would
|
|
| 89 |
bind both F</var/log/my-site/errors.log> and F</srv/www/my-site/logs/app.log>
|
|
| 90 |
to the defined C<my-site> service.
|
|
| 90 | 91 |
|
| 91 | 92 |
|
| 92 | 93 |
=head2 SERVICE AUTOCONF |
| ... | ... | |
| 100 | 101 |
/srv/local/. |
| 101 | 102 |
|
| 102 | 103 |
If you choose not to use the autoconf feature, you MUST specify services as a |
| 103 |
space-separated list of service names in the \`services\` variable.
|
|
| 104 |
space-separated list of service names in the C<services> variable.
|
|
| 104 | 105 |
|
| 105 | 106 |
|
| 106 | 107 |
=head2 EXAMPLE CONFIGS |
| ... | ... | |
| 197 | 198 |
n=0 |
| 198 | 199 |
while [ $n -lt "${#reqvars[@]}" ]; do
|
| 199 | 200 |
if echo "$v" | grep -Eq "${reqvars[$n]}$"; then
|
| 200 |
!((setvars|=$(( 2 ** $n )) ))
|
|
| 201 |
setvars=$((setvars | $(( 2 ** $n )) ))
|
|
| 201 | 202 |
fi |
| 202 |
!((n++))
|
|
| 203 |
n=$((n+1))
|
|
| 203 | 204 |
done |
| 204 | 205 |
done 3< <(echo "$vars") |
| 205 | 206 |
|
| ... | ... | |
| 208 | 209 |
n=0 |
| 209 | 210 |
allvars=0 |
| 210 | 211 |
while [ $n -lt "${#reqvars[@]}" ]; do
|
| 211 |
!((allvars+=$(( 2 ** $n ))))
|
|
| 212 |
!((n++))
|
|
| 212 |
allvars=$(( allvars + $(( 2 ** $n )) ))
|
|
| 213 |
n=$((n+1))
|
|
| 213 | 214 |
done |
| 214 | 215 |
|
| 215 | 216 |
# And scream if something's not set |
| ... | ... | |
| 223 | 224 |
>&2 echo " *${reqvars[$n]}"
|
| 224 | 225 |
fi |
| 225 | 226 |
i=$((i<<1)) |
| 226 |
!((n++))
|
|
| 227 |
n=$((n+1))
|
|
| 227 | 228 |
done |
| 228 | 229 |
>&2 echo |
| 229 | 230 |
>&2 echo "Please read the docs." |
| ... | ... | |
| 308 | 309 |
local curstate="$(cat "$MUNIN_STATEFILE")" |
| 309 | 310 |
local nextstate=() |
| 310 | 311 |
|
| 311 |
local n svcnm varnm service svc svc_counter logbinding logfile lognm logmatch prvlines curlines matches extinfo_var |
|
| 312 |
local n svcnm varnm service svc svc_counter_var logbinding logfile lognm logmatch prvlines curlines matches extinfo_var
|
|
| 312 | 313 |
|
| 313 | 314 |
# Set service counters to 0 and set any logbindings that aren't yet set |
| 314 | 315 |
while read -u 3 -r svc; do |
| ... | ... | |
| 354 | 355 |
|
| 355 | 356 |
# Get the current number of lines in the file (defaulting to 0 on error) |
| 356 | 357 |
curlines="$(wc -l < "$logfile")" |
| 357 |
curlines="${curlines:-0}"
|
|
| 358 | 358 |
|
| 359 | 359 |
# If the current line count is less than the previous line count, we've probably rotated. |
| 360 | 360 |
# Reset to 0. |
| ... | ... | |
| 371 | 371 |
# If there were matches, aggregate them and add this log to the extinfo for the service |
| 372 | 372 |
if [ "$matches" -gt 0 ]; then |
| 373 | 373 |
# Aggregate and add to the correct service counter |
| 374 |
svc_counter="${svcnm}_total"
|
|
| 375 |
!((matches+=${!svc_counter}))
|
|
| 376 |
typeset "$svc_counter=$matches" |
|
| 374 |
svc_counter_var="${svcnm}_total"
|
|
| 375 |
matches=$(($matches + ${!svc_counter_var}))
|
|
| 376 |
typeset "$svc_counter_var=$matches"
|
|
| 377 | 377 |
|
| 378 | 378 |
# Add this log to extinfo for service |
| 379 | 379 |
extinfo_var="${svcnm}_extinfo"
|
| ... | ... | |
| 383 | 383 |
# Push onto next state |
| 384 | 384 |
nextstate+=("${lognm}_lines=$curlines")
|
| 385 | 385 |
|
| 386 |
!((n++))
|
|
| 386 |
n=$((n+1))
|
|
| 387 | 387 |
done 3< <(echo "$LOGFILES") |
| 388 | 388 |
|
| 389 | 389 |
# Write state to munin statefile |
| ... | ... | |
| 392 | 392 |
# Now echo values |
| 393 | 393 |
while read -u 3 -r svc; do |
| 394 | 394 |
svcnm="$(echo "$svc" | sed -r 's/^[^a-zA-Z]+//g' | sed -r 's/[^a-zA-Z0-9]+/_/g')" |
| 395 |
svc_counter="${svcnm}_total"
|
|
| 395 |
svc_counter_var="${svcnm}_total"
|
|
| 396 | 396 |
extinfo_var="${svcnm}_extinfo"
|
| 397 |
echo "${svcnm}.value ${!svc_counter}"
|
|
| 397 |
echo "${svcnm}.value ${!svc_counter_var}"
|
|
| 398 | 398 |
echo "${svcnm}.extinfo ${!extinfo_var}"
|
| 399 | 399 |
done 3< <(IFS=$'\n'; echo "${services[*]}")
|
| 400 | 400 |
|
Formats disponibles : Unified diff