mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Merge pull request #1462 from ap-wtioit/master-improve_nginx_error
nginx_error: support custom log format with awk scripts
This commit is contained in:
commit
6263e178e1
1 changed files with 13 additions and 8 deletions
|
@ -15,18 +15,18 @@ Any host running nginx, with bash version > 4.0
|
||||||
|
|
||||||
=head1 CONFIGURATION
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
This shows the default configuration of this plugin. You can override
|
This shows the default configuration of this plugin. You can override
|
||||||
the log file path and the logpattern.
|
the log file path, the logpattern and the awk_script.
|
||||||
Additionally you may want to adjust 'group' (or 'user') based on the
|
Additionally you may want to adjust 'group' (or 'user') based on the
|
||||||
permissions required for reading the log file.
|
permissions required for reading the log file.
|
||||||
|
|
||||||
[nginx_error]
|
[nginx_error]
|
||||||
group adm
|
group adm
|
||||||
env.logpath /var/log/nginx
|
env.logpath /var/log/nginx
|
||||||
env.logpattern a.*.log
|
env.logpattern a.*.log
|
||||||
|
env.awk_script {print $9}
|
||||||
Nginx must also be configured to log accesses in "combined" log format (default)
|
|
||||||
|
|
||||||
|
Nginx must also be configured to log accesses in "combined" log format (default) or the awk_script adapted for your log format
|
||||||
|
|
||||||
=head1 USAGE
|
=head1 USAGE
|
||||||
|
|
||||||
|
@ -60,6 +60,9 @@ None known.
|
||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
|
1.2 - 2024/10/29
|
||||||
|
* add env variable awk_script to support other log formats
|
||||||
|
|
||||||
1.1 - 2018/01/20
|
1.1 - 2018/01/20
|
||||||
* add 'dirty config' capability support
|
* add 'dirty config' capability support
|
||||||
* fix shell style issues reported by shellcheck
|
* fix shell style issues reported by shellcheck
|
||||||
|
@ -101,6 +104,8 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log="$logpath/$log_filename"
|
log="$logpath/$log_filename"
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
awk_script=${awk_script:-'{print $9}'}
|
||||||
|
|
||||||
# declaring an array with http status codes, we are interested in
|
# declaring an array with http status codes, we are interested in
|
||||||
declare -A http_codes
|
declare -A http_codes
|
||||||
|
@ -122,7 +127,7 @@ http_codes[503]='Service Unavailable'
|
||||||
do_fetch () {
|
do_fetch () {
|
||||||
local count status_code
|
local count status_code
|
||||||
declare -A line_counts
|
declare -A line_counts
|
||||||
values="$(awk '{print $9}' "$log" | sort | uniq -c)"
|
values="$(awk "$awk_script" "$log" | sort | uniq -c)"
|
||||||
# Log files may be empty due to logrotation
|
# Log files may be empty due to logrotation
|
||||||
if [ -n "$values" ]; then
|
if [ -n "$values" ]; then
|
||||||
while read -r count status_code; do
|
while read -r count status_code; do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue