mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
[http_load_] Use separate subroutines for config output
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
parent
1ee2a115f7
commit
d51266a358
1 changed files with 282 additions and 198 deletions
|
@ -208,6 +208,280 @@ sub get_id{
|
|||
return $url;
|
||||
}
|
||||
|
||||
sub graph_title_config{
|
||||
my $id = $_[0];
|
||||
my %urls = %{$_[1]};
|
||||
my $type = $_[2];
|
||||
|
||||
print "graph_title $urls{$id} ${type}\n";
|
||||
print "graph_args -l 0 --base 1000\n";
|
||||
print "graph_category webserver\n";
|
||||
}
|
||||
|
||||
sub size_config{
|
||||
my $id = $_[0];
|
||||
my %urls = %{$_[1]};
|
||||
my %cache = %{$_[2]};
|
||||
|
||||
my $count = 0;
|
||||
|
||||
graph_title_config($id, \%urls, "size");
|
||||
|
||||
print "graph_vlabel Bytes\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to calculate the total size of $urls{$id}.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^size_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
print "$name.label from $host\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 20000000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub loadtime_config{
|
||||
my $id = $_[0];
|
||||
my %urls = %{$_[1]};
|
||||
my %cache = %{$_[2]};
|
||||
|
||||
my $count = 0;
|
||||
|
||||
graph_title_config($id, \%urls, "loadtime");
|
||||
|
||||
print "graph_vlabel Seconds\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to calculate the total time to load $urls{$id}. ";
|
||||
print "Note that browsers usually fork() the GET requests, resulting in a shorter total loading time.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^loadtime_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
print "$name.label from $host\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 400\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub elements_config{
|
||||
my $id = $_[0];
|
||||
my %urls = %{$_[1]};
|
||||
my %cache = %{$_[2]};
|
||||
|
||||
my $count = 0;
|
||||
|
||||
graph_title_config($id, \%urls, "elements");
|
||||
|
||||
print "graph_vlabel Number of elements\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to count the number of elements (images, CSS files, etc) from $urls{$id}.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^elements_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
print "$name.label from $host\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 10000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub response_config{
|
||||
my $id = $_[0];
|
||||
my %urls = %{$_[1]};
|
||||
my %cache = %{$_[2]};
|
||||
|
||||
my $count = 0;
|
||||
|
||||
graph_title_config($id, \%urls, "response");
|
||||
|
||||
print "graph_vlabel Server response code count\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to visualize the server response codes received while loading $urls{$id}.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^response_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
$host =~ s/\_/ /g;
|
||||
$host =~ s/(\S+)\s(\d+)/ /g;
|
||||
$host=$1;
|
||||
my $code=$2;
|
||||
|
||||
print "$name.label $host ($code)\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 10000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub type_config{
|
||||
my $id = $_[0];
|
||||
my %urls = %{$_[1]};
|
||||
my %cache = %{$_[2]};
|
||||
|
||||
my $count = 0;
|
||||
|
||||
graph_title_config($id, \%urls, "type");
|
||||
|
||||
print "graph_vlabel Content type count\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to visualize the different content types $urls{$id} consists of.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^type_(\S+)$/){
|
||||
my $type=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
#$host =~ s/\_/ /g;
|
||||
#$host =~ s/(\S+)\s(\S+)/ /g;
|
||||
#$host=$1;
|
||||
#my $type=$2;
|
||||
|
||||
print "$name.label $type\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 100000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub tags_config{
|
||||
my $id = $_[0];
|
||||
my %urls = %{$_[1]};
|
||||
my %cache = %{$_[2]};
|
||||
|
||||
my $count = 0;
|
||||
|
||||
graph_title_config($id, \%urls, "tags");
|
||||
|
||||
print "graph_vlabel HTML tag count\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to visualize the different tags $urls{$id} consists of.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^tags_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
$host =~ s/\W/ /g;
|
||||
|
||||
print "$name.label $host\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 100000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub cache_values{
|
||||
my %cache = %{$_[0]};
|
||||
my $type = $_[1];
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
if($key =~ m/^([A-Za-z]+)\_(\S+)$/){
|
||||
my $name=$2;
|
||||
|
||||
if ($1 eq $type){
|
||||
$name=get_fieldname($name);
|
||||
print $name . ".value " . $value . "\n";
|
||||
}
|
||||
} elsif(m/^(\S+)\s+(\S+)$/){
|
||||
if ($1 eq $type){
|
||||
print $1 . ".value " . $2 . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$debug && print "Scriptname: " . $scriptname . "\n";
|
||||
|
||||
# Get the url id and the type of the graph
|
||||
|
@ -379,223 +653,33 @@ if($ARGV[0] and $ARGV[0] eq "autoconf") {
|
|||
}elsif($ARGV[0] and $ARGV[0] eq "config") {
|
||||
my %urls=&read_urls($url_file);
|
||||
|
||||
print "graph_title $urls{$id} ${type}\n";
|
||||
print "graph_args -l 0 --base 1000\n";
|
||||
print "graph_category webserver\n";
|
||||
$debug && print "Reading cache file\n";
|
||||
my $cachefile=$cachedir . "/" . &get_cache_file_name($scriptname,$id);
|
||||
my %cache=read_cache($cachefile);
|
||||
|
||||
my $count=0;
|
||||
$debug && print "The cache file contains " . keys(%cache) . " lines\n";
|
||||
|
||||
if($type eq "size"){
|
||||
print "graph_vlabel Bytes\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to calculate the total size of $urls{$id}.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^size_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
print "$name.label from $host\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 20000000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
size_config($id, \%urls, \%cache)
|
||||
}elsif($type eq "loadtime"){
|
||||
print "graph_vlabel Seconds\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to calculate the total time to load $urls{$id}. ";
|
||||
print "Note that browsers usually fork() the GET requests, resulting in a shorter total loading time.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^loadtime_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
print "$name.label from $host\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 400\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadtime_config($id, \%urls, \%cache)
|
||||
}elsif($type eq "elements"){
|
||||
print "graph_vlabel Number of elements\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to count the number of elements (images, CSS files, etc) from $urls{$id}.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^elements_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
print "$name.label from $host\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 10000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
elements_config($id, \%urls, \%cache)
|
||||
}elsif($type eq "response"){
|
||||
print "graph_vlabel Server response code count\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to visualize the server response codes received while loading $urls{$id}.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^response_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
$host =~ s/\_/ /g;
|
||||
$host =~ s/(\S+)\s(\d+)/ /g;
|
||||
$host=$1;
|
||||
my $code=$2;
|
||||
|
||||
print "$name.label $host ($code)\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 10000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
response_config($id, \%urls, \%cache)
|
||||
}elsif($type eq "type"){
|
||||
print "graph_vlabel Content type count\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to visualize the different content types $urls{$id} consists of.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^type_(\S+)$/){
|
||||
my $type=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
#$host =~ s/\_/ /g;
|
||||
#$host =~ s/(\S+)\s(\S+)/ /g;
|
||||
#$host=$1;
|
||||
#my $type=$2;
|
||||
|
||||
print "$name.label $type\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 100000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
type_config($id, \%urls, \%cache)
|
||||
}elsif($type eq "tags"){
|
||||
print "graph_vlabel HTML tag count\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_info This graph is generated by a set of serial GETs to visualize the different tags $urls{$id} consists of.\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort reverse keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
|
||||
if($key =~ m/^tags_(\S+)$/){
|
||||
my $host=$1;
|
||||
my $value=$value;
|
||||
|
||||
my $name=$1;
|
||||
$name=get_fieldname($name);
|
||||
|
||||
$host =~ s/\W/ /g;
|
||||
|
||||
print "$name.label $host\n";
|
||||
print "$name.min 0\n";
|
||||
print "$name.max 100000\n";
|
||||
if($count eq 0){
|
||||
print "$name.draw AREA\n";
|
||||
} else {
|
||||
print "$name.draw STACK\n";
|
||||
}
|
||||
$count+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
tags_config($id, \%urls, \%cache)
|
||||
}
|
||||
exit(0);
|
||||
exit(0);
|
||||
} else {
|
||||
my $cachefile=$cachedir . "/" . &get_cache_file_name($scriptname,$id);
|
||||
$debug && print "Reading cache file: " . $cachefile . "\n";
|
||||
my %cache=read_cache($cachefile);
|
||||
$debug && print "Number of lines in cache file: " . keys(%cache) . "\n";
|
||||
|
||||
if(keys(%cache)>0){
|
||||
for my $key ( sort keys %cache ){
|
||||
my $value=$cache{$key};
|
||||
if($key =~ m/^([A-Za-z]+)\_(\S+)$/){
|
||||
my $name=$2;
|
||||
|
||||
if ($1 eq $type){
|
||||
$name=get_fieldname($name);
|
||||
print $name . ".value " . $value . "\n";
|
||||
}
|
||||
} elsif(m/^(\S+)\s+(\S+)$/){
|
||||
if ($1 eq $type){
|
||||
print $1 . ".value " . $2 . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cache_values(\%cache, $type);
|
||||
}
|
||||
|
||||
# vim:syntax=perl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue