mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
Merge pull request #883 from henti/master
Folder recursion and offline fix for jenkins plugin
This commit is contained in:
commit
36c0717b95
2 changed files with 76 additions and 41 deletions
|
@ -54,6 +54,7 @@ use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use JSON;
|
use JSON;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
|
use URI;
|
||||||
|
|
||||||
# VARS
|
# VARS
|
||||||
my $url = ($ENV{'url'} || 'localhost');
|
my $url = ($ENV{'url'} || 'localhost');
|
||||||
|
@ -79,7 +80,7 @@ my %states = (
|
||||||
'aborted'=>'failing',
|
'aborted'=>'failing',
|
||||||
'aborted_anime'=>'failing'
|
'aborted_anime'=>'failing'
|
||||||
);
|
);
|
||||||
my %counts = ('stable' => 0, 'unstable'=>0, 'failing'=>0, 'disabled'=>0);
|
my $auth = ( $user ne "" and $apiToken ne "" ? " --auth-no-challenge --user=$user --password=$apiToken" : "" );
|
||||||
|
|
||||||
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
if( $type eq "results" ) {
|
if( $type eq "results" ) {
|
||||||
|
@ -103,7 +104,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
print "build_stable.draw STACK\n";
|
print "build_stable.draw STACK\n";
|
||||||
print "build_stable.label stable\n";
|
print "build_stable.label stable\n";
|
||||||
print "build_stable.type GAUGE\n";
|
print "build_stable.type GAUGE\n";
|
||||||
print "build_stable.colour 294D99\n";
|
print "build_stable.colour 294D99\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
if( $type eq "queue" ) {
|
if( $type eq "queue" ) {
|
||||||
|
@ -125,46 +126,80 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
print "build_running.label running Builds\n";
|
print "build_running.label running Builds\n";
|
||||||
print "build_running.type GAUGE\n";
|
print "build_running.type GAUGE\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
# CODE
|
my $cmd = "$wgetBin $auth -qO- $url:$port$context";
|
||||||
my $auth = ( $user ne "" and $apiToken ne "" ? " --auth-no-challenge --user=$user --password=$apiToken" : "" );
|
|
||||||
my $cmd = "$wgetBin $auth -qO- $url:$port$context";
|
|
||||||
|
|
||||||
if( $type eq "results" ) {
|
if( $type eq "results" ) {
|
||||||
my $result = `$cmd/api/json`;
|
my $counts = get_results('');
|
||||||
my $parsed = decode_json($result);
|
|
||||||
foreach my $cur(@{$parsed->{'jobs'}}) {
|
foreach my $status (keys %{$counts}) {
|
||||||
if (defined $states{$cur->{'color'}}) {
|
print "build_$status.value $counts->{$status}\n";
|
||||||
$counts{$states{$cur->{'color'}}} += 1;
|
|
||||||
} else {
|
|
||||||
warn "Ignoring unknown color " . $cur->{'color'} . "\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach my $status (keys %counts) {
|
|
||||||
print "build_$status.value $counts{$status}\n";
|
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $type eq "running" ) {
|
if( $type eq "running" ) {
|
||||||
my $count = 0;
|
my $running_count = get_running('');
|
||||||
my $result = `$cmd/api/json`;
|
print "build_running.value ", $running_count, "\n";
|
||||||
my $parsed = decode_json($result);
|
exit;
|
||||||
foreach my $cur(@{$parsed->{'jobs'}}) {
|
|
||||||
if( $cur->{'color'} =~ /anime$/ ) {
|
|
||||||
$count += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print "build_running.value ", $count, "\n";
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $type eq "queue" ) {
|
if( $type eq "queue" ) {
|
||||||
my $result = `$cmd/queue/api/json`;
|
my $result = `$cmd/queue/api/json`;
|
||||||
my $parsed = decode_json($result);
|
my $parsed = decode_json($result);
|
||||||
print "build_count.value ", scalar( @{$parsed->{'items'}} ), "\n";
|
print "build_count.value ", scalar( @{$parsed->{'items'}} ), "\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my %counts;
|
||||||
|
|
||||||
|
sub get_results{
|
||||||
|
my $query_context = shift;
|
||||||
|
die "get_results requires an argument" unless defined $query_context;
|
||||||
|
unless (%counts) {
|
||||||
|
# initialise
|
||||||
|
%counts = ('stable' => 0, 'unstable'=>0, 'failing'=>0, 'disabled'=>0);
|
||||||
|
}
|
||||||
|
my $cmd = "$wgetBin $auth -qO- $url:$port$context$query_context/api/json";
|
||||||
|
my $result = `$cmd`;
|
||||||
|
my $parsed = decode_json($result);
|
||||||
|
foreach my $cur(@{$parsed->{'jobs'}}) {
|
||||||
|
if (exists $cur->{'color'} && defined $states{$cur->{'color'}}) {
|
||||||
|
$counts{$states{$cur->{'color'}}} += 1;
|
||||||
|
} elsif ($cur->{'_class'} eq 'com.cloudbees.hudson.plugins.folder.Folder'){
|
||||||
|
my $uri = URI->new($cur->{'url'});
|
||||||
|
my $folder = $uri->path;
|
||||||
|
get_results($folder);
|
||||||
|
} else {
|
||||||
|
warn "Ignoring unknown color " . $cur->{'color'} . "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return \%counts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $running_count;
|
||||||
|
sub get_running{
|
||||||
|
my $query_context = shift;
|
||||||
|
die "get_results requires an argument" unless defined $query_context;
|
||||||
|
$running_count //= 0;
|
||||||
|
my $cmd = "$wgetBin $auth -qO- $url:$port$context$query_context/api/json";
|
||||||
|
my $result = `$cmd`;
|
||||||
|
my $parsed = decode_json($result);
|
||||||
|
foreach my $cur(@{$parsed->{'jobs'}}) {
|
||||||
|
if( exists $cur->{'color'} && $cur->{'color'} =~ /anime$/ ) {
|
||||||
|
$running_count += 1;
|
||||||
|
} elsif ($cur->{'_class'} eq 'com.cloudbees.hudson.plugins.folder.Folder'){
|
||||||
|
my $uri = URI->new($cur->{'url'});
|
||||||
|
my $folder = $uri->path;
|
||||||
|
get_running($folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $running_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
18
plugins/jenkins/jenkins_nodes_
Normal file → Executable file
18
plugins/jenkins/jenkins_nodes_
Normal file → Executable file
|
@ -51,7 +51,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
my $result = `$cmd/computer/api/json`;
|
my $result = `$cmd/computer/api/json`;
|
||||||
my $parsed = decode_json($result);
|
my $parsed = decode_json($result);
|
||||||
foreach my $cur(@{$parsed->{'computer'}}) {
|
foreach my $cur(@{$parsed->{'computer'}}) {
|
||||||
if( $cur->{'offline'} =~ /false$/ ) {
|
if( !$cur->{'offline'} ) {
|
||||||
my $cat = $cur->{'displayName'};
|
my $cat = $cur->{'displayName'};
|
||||||
$cat =~ s/\./\_/g;
|
$cat =~ s/\./\_/g;
|
||||||
if( $lcount > 0 ){
|
if( $lcount > 0 ){
|
||||||
|
@ -77,7 +77,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
my $result = `$cmd/computer/api/json`;
|
my $result = `$cmd/computer/api/json`;
|
||||||
my $parsed = decode_json($result);
|
my $parsed = decode_json($result);
|
||||||
foreach my $cur(@{$parsed->{'computer'}}) {
|
foreach my $cur(@{$parsed->{'computer'}}) {
|
||||||
if( $cur->{'offline'} =~ /false$/ ) {
|
if( !$cur->{'offline'} ) {
|
||||||
my $cat = $cur->{'displayName'};
|
my $cat = $cur->{'displayName'};
|
||||||
$cat =~ s/\./\_/g;
|
$cat =~ s/\./\_/g;
|
||||||
if( $lcount > 0 ){
|
if( $lcount > 0 ){
|
||||||
|
@ -103,7 +103,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
my $result = `$cmd/computer/api/json`;
|
my $result = `$cmd/computer/api/json`;
|
||||||
my $parsed = decode_json($result);
|
my $parsed = decode_json($result);
|
||||||
foreach my $cur(@{$parsed->{'computer'}}) {
|
foreach my $cur(@{$parsed->{'computer'}}) {
|
||||||
if( $cur->{'offline'} =~ /false$/ ) {
|
if( !$cur->{'offline'} ) {
|
||||||
my $cat = $cur->{'displayName'};
|
my $cat = $cur->{'displayName'};
|
||||||
$cat =~ s/\./\_/g;
|
$cat =~ s/\./\_/g;
|
||||||
if( $lcount > 0 ){
|
if( $lcount > 0 ){
|
||||||
|
@ -130,7 +130,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
my %archs = ();
|
my %archs = ();
|
||||||
my $cat;
|
my $cat;
|
||||||
foreach my $cur(@{$parsed->{'computer'}}) {
|
foreach my $cur(@{$parsed->{'computer'}}) {
|
||||||
if( $cur->{'offline'} =~ /false$/ ) {
|
if( !$cur->{'offline'} ) {
|
||||||
$cat = $cur->{'monitorData'}{'hudson.node_monitors.ArchitectureMonitor'};
|
$cat = $cur->{'monitorData'}{'hudson.node_monitors.ArchitectureMonitor'};
|
||||||
if (exists $archs{$cat} ) {} else {
|
if (exists $archs{$cat} ) {} else {
|
||||||
$archs{$cat} = 0;
|
$archs{$cat} = 0;
|
||||||
|
@ -178,7 +178,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
my $total_mem = 0;
|
my $total_mem = 0;
|
||||||
my $used_mem = 0;
|
my $used_mem = 0;
|
||||||
foreach my $cur(@{$parsed->{'computer'}}) {
|
foreach my $cur(@{$parsed->{'computer'}}) {
|
||||||
if( $cur->{'offline'} =~ /false$/ ) {
|
if( !$cur->{'offline'} ) {
|
||||||
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.SwapSpaceMonitor'};
|
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.SwapSpaceMonitor'};
|
||||||
$avail_mem += $monitor->{'availablePhysicalMemory'};
|
$avail_mem += $monitor->{'availablePhysicalMemory'};
|
||||||
$total_mem += $monitor->{'totalPhysicalMemory'};
|
$total_mem += $monitor->{'totalPhysicalMemory'};
|
||||||
|
@ -193,7 +193,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
my $result = `$cmd/computer/api/json`;
|
my $result = `$cmd/computer/api/json`;
|
||||||
my $parsed = decode_json($result);
|
my $parsed = decode_json($result);
|
||||||
foreach my $cur(@{$parsed->{'computer'}}) {
|
foreach my $cur(@{$parsed->{'computer'}}) {
|
||||||
if( $cur->{'offline'} =~ /false$/ ) {
|
if( !$cur->{'offline'} ) {
|
||||||
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.SwapSpaceMonitor'};
|
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.SwapSpaceMonitor'};
|
||||||
my $cat = $cur->{'displayName'};
|
my $cat = $cur->{'displayName'};
|
||||||
$cat =~ s/\./\_/g;
|
$cat =~ s/\./\_/g;
|
||||||
|
@ -206,7 +206,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
my $result = `$cmd/computer/api/json`;
|
my $result = `$cmd/computer/api/json`;
|
||||||
my $parsed = decode_json($result);
|
my $parsed = decode_json($result);
|
||||||
foreach my $cur(@{$parsed->{'computer'}}) {
|
foreach my $cur(@{$parsed->{'computer'}}) {
|
||||||
if( $cur->{'offline'} =~ /false$/ ) {
|
if( !$cur->{'offline'} ) {
|
||||||
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.TemporarySpaceMonitor'};
|
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.TemporarySpaceMonitor'};
|
||||||
my $cat = $cur->{'displayName'};
|
my $cat = $cur->{'displayName'};
|
||||||
$cat =~ s/\./\_/g;
|
$cat =~ s/\./\_/g;
|
||||||
|
@ -219,7 +219,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
my $result = `$cmd/computer/api/json`;
|
my $result = `$cmd/computer/api/json`;
|
||||||
my $parsed = decode_json($result);
|
my $parsed = decode_json($result);
|
||||||
foreach my $cur(@{$parsed->{'computer'}}) {
|
foreach my $cur(@{$parsed->{'computer'}}) {
|
||||||
if( $cur->{'offline'} =~ /false$/ ) {
|
if( !$cur->{'offline'} ) {
|
||||||
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.DiskSpaceMonitor'};
|
$monitor = $cur->{'monitorData'}{'hudson.node_monitors.DiskSpaceMonitor'};
|
||||||
my $cat = $cur->{'displayName'};
|
my $cat = $cur->{'displayName'};
|
||||||
$cat =~ s/\./\_/g;
|
$cat =~ s/\./\_/g;
|
||||||
|
@ -233,7 +233,7 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
my %archs = ();
|
my %archs = ();
|
||||||
my $cat;
|
my $cat;
|
||||||
foreach my $cur(@{$parsed->{'computer'}}) {
|
foreach my $cur(@{$parsed->{'computer'}}) {
|
||||||
if( $cur->{'offline'} =~ /false$/ ) {
|
if( !$cur->{'offline'} ) {
|
||||||
$cat = $cur->{'monitorData'}{'hudson.node_monitors.ArchitectureMonitor'};
|
$cat = $cur->{'monitorData'}{'hudson.node_monitors.ArchitectureMonitor'};
|
||||||
if (exists $archs{$cat} ) {
|
if (exists $archs{$cat} ) {
|
||||||
$archs{$cat} += 1;
|
$archs{$cat} += 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue