Skip to content

Instantly share code, notes, and snippets.

@perlpunk
Created June 7, 2023 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlpunk/4aec2d85c51b22261c0717afc896aa4c to your computer and use it in GitHub Desktop.
Save perlpunk/4aec2d85c51b22261c0717afc896aa4c to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use v5.22;
use Data::Dumper;
my @states = qw/ active delayed failed inactive /;
if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
config();
exit;
}
my @data = qx{curl -s https://openqa.opensuse.org/admin/influxdb/minion};
my %values;
for my $line (@data) {
my ($metric, $url, $values) = $line =~ m/^(\w+),url=(\S+) (\S+)/;
next unless $metric eq 'openqa_minion_jobs';
%values = map { s/i$//r } map { split m/=/, $_ } split m/,/, $values;
}
my $total = 0;
for my $state (@states) {
my $value = $values{ $state } // 0;
$total += $value;
print <<"EOM";
$state.value $value
EOM
}
print <<"EOM";
total.value $total
EOM
sub config {
print <<"EOM";
graph_title Minion Jobs
graph_args --base 1000 -l 0
graph_category minion
graph_order @states
graph_vlabel minion_jobs
EOM
for my $state (@states) {
print <<"EOM";
$state.label $state
$state.draw LINE
EOM
}
print <<"EOM";
total.label Total
total.graph no
EOM
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment