Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Sébastien Luttringer
infrastructure
Commits
9df95d11
Verified
Commit
9df95d11
authored
May 30, 2018
by
Florian Pritz
Browse files
nginx-zabbix.pl: Extract updater code into method
Signed-off-by:
Florian Pritz
<
bluewind@xinu.at
>
parent
f5ee7a08
Changes
1
Hide whitespace changes
Inline
Side-by-side
roles/zabbix-agent/files/nginx-zabbix.pl
View file @
9df95d11
...
...
@@ -85,26 +85,7 @@ sub main {
$line
=
trim
(
$line
);
if
(
$line
=~
m/(?<remote_addr>\S+) (?<host>\S+) (?<remote_user>\S+) \[(?<time_local>.*?)\]\s+"(?<request>.*?)" (?<status>\S+) (?<body_bytes_sent>\S+) "(?<http_referer>.*?)" "(?<http_user_agent>.*?)" "(?<http_x_forwarded_for>\S+)"(?: (?<request_time>[\d\.]+|-))?/
)
{
my
%val
=
%+
;
my
$host
=
$val
{
host
};
next
unless
$host
=~
m/$hostname_regex/
;
if
(
not
defined
$values_per_host
->
{
$host
})
{
$values_per_host
->
{
$host
}
=
clone
(
$value_template
);
$stat_per_host
->
{
$host
}
=
Statistics::Descriptive::
Full
->
new
();
$modified_hostlist
=
1
;
}
my
$stat
=
$stat_per_host
->
{
$host
};
my
$values
=
$values_per_host
->
{
$host
};
$stat
->
add_data
(
$val
{
request_time
})
if
$val
{
request_time
}
!=
0
;
$values
->
{
request_count
}
++
;
$values
->
{
cached_request_count
}
++
if
$val
{
request_time
}
==
0
;
my
$status_key
=
defined
$values
->
{
status
}
->
{
$val
{
status
}}
?
$val
{
status
}
:
"
other
";
$values
->
{
status
}
->
{
$status_key
}
++
;
update_stats_for_line
(
$values_per_host
,
$stat_per_host
,
$value_template
,
\
$modified_hostlist
,
\%+
);
}
my
$now
=
time
;
...
...
@@ -137,4 +118,29 @@ sub main {
}
}
sub
update_stats_for_line
{
my
(
$values_per_host
,
$stat_per_host
,
$value_template
,
$modified_hostlist
,
$line_values
)
=
@_
;
my
%val
=
%$line_values
;
my
$host
=
$val
{
host
};
return
unless
$host
=~
m/$hostname_regex/
;
if
(
not
defined
$values_per_host
->
{
$host
})
{
$values_per_host
->
{
$host
}
=
clone
(
$value_template
);
$stat_per_host
->
{
$host
}
=
Statistics::Descriptive::
Full
->
new
();
$$modified_hostlist
=
1
;
}
my
$stat
=
$stat_per_host
->
{
$host
};
my
$values
=
$values_per_host
->
{
$host
};
$stat
->
add_data
(
$val
{
request_time
})
if
$val
{
request_time
}
!=
0
;
$values
->
{
request_count
}
++
;
$values
->
{
cached_request_count
}
++
if
$val
{
request_time
}
==
0
;
my
$status_key
=
defined
$values
->
{
status
}
->
{
$val
{
status
}}
?
$val
{
status
}
:
"
other
";
$values
->
{
status
}
->
{
$status_key
}
++
;
}
main
();
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment