Created
December 1, 2016 09:41
-
-
Save Grauwolf/9d1aa7e1767ef0b04b942d9fcd38bd92 to your computer and use it in GitHub Desktop.
prometheus-apt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# generates output for prometheus-node-exporter textfile collector | |
# run as cronjob. eg. | |
# 0 * * * * root /usr/local/bin/prometheus-apt > /var/lib/prometheus-textfile/prometheus-apt.prom | |
use strict; | |
use warnings; | |
use feature 'say'; | |
say "# HELP apt_update | |
# TYPE apt_update gauge"; | |
my $command = 'apt-get -o Debug::NoLocking=yes -s dist-upgrade -y'; | |
open(my $fh, '-|', $command) or die $!; | |
while (my $line = <$fh>) { | |
if ($line =~ /^Inst\s(\S+)\s(\[\S+\]\s)?\(\S+\s(.*)\s\[.*\]\)(\s\[.*\])?$/) { | |
say 'apt_update{package="', $1, '",repository="', $3, '"} 1'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment