Skip to content

Instantly share code, notes, and snippets.

@Grauwolf
Created December 1, 2016 09:41
Show Gist options
  • Save Grauwolf/9d1aa7e1767ef0b04b942d9fcd38bd92 to your computer and use it in GitHub Desktop.
Save Grauwolf/9d1aa7e1767ef0b04b942d9fcd38bd92 to your computer and use it in GitHub Desktop.
prometheus-apt
#!/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