From a085acbddbf5e4b0a679c1c6db63ddfef9940601 Mon Sep 17 00:00:00 2001 From: zegeek Date: Fri, 9 Feb 2024 11:53:58 +0100 Subject: [PATCH] schaufel_exporter: make hostname dynamic through options --- .../schaufel_exporter/files/schaufel_exporter.pl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) mode change 100644 => 100755 app-metrics/schaufel_exporter/files/schaufel_exporter.pl diff --git a/app-metrics/schaufel_exporter/files/schaufel_exporter.pl b/app-metrics/schaufel_exporter/files/schaufel_exporter.pl old mode 100644 new mode 100755 index 50712df0..6056fc04 --- a/app-metrics/schaufel_exporter/files/schaufel_exporter.pl +++ b/app-metrics/schaufel_exporter/files/schaufel_exporter.pl @@ -16,7 +16,7 @@ use Data::Dumper; -my ($help, $verbose, $time, $parser, $json, $prometheus); +my ($help, $verbose, $time, $parser, $json, $prometheus, $name); my $base_uri = "/insert/prometheus/api/v1/import/prometheus"; GetOptions( @@ -24,7 +24,8 @@ "t|time=i" => \$time, "v|verbose" => \$verbose, "p|parser=s" => \&_parse_handler, - "j|json" => \$json + "j|json" => \$json, + "n|name=s" => \$name ) or _help(2); _parse_handler('parser','stats') unless $parser; @@ -333,16 +334,17 @@ sub _send_victoriametrics sub _parse_prometheus { my $file = shift; + my $id = $name ? $name : hostname(); # turns out tail is much better than anything # I can whip up in perl on short notice open(my $fh, '-|', "tail -n0 -f $file 2>/dev/null") or die ("Can't tail $file: $!"); - my ($topic) = $file =~ m/(?:schaufel_?)?(?:exports_?)?([^\/]+?)\.log/; - my $grafana_delivered = "schaufel_delivered{ topic=\"$topic\" , host=\"".hostname()."\" }" ; - my $grafana_kafkaerr = "schaufel_kafkaerr{ topic=\"$topic\" , host=\"".hostname()."\" }" ; - my $grafana_autocommit = "schaufel_autocommit{ topic=\"$topic\" , host=\"".hostname()."\" }" ; - my $grafana_rebalance = "schaufel_rebalanced{ topic=\"$topic\" , host=\"".hostname()."\" }" ; + my ($topic) = $file =~ m/(?:schaufel_?)?(?:exports_?)?(?:[a-z0-9]+\.)?([^\/]+?)\.log/; + my $grafana_delivered = "schaufel_delivered{ topic=\"$topic\" , host=\"".$id."\" }" ; + my $grafana_kafkaerr = "schaufel_kafkaerr{ topic=\"$topic\" , host=\"".$id."\" }" ; + my $grafana_autocommit = "schaufel_autocommit{ topic=\"$topic\" , host=\"".$id."\" }" ; + my $grafana_rebalance = "schaufel_rebalanced{ topic=\"$topic\" , host=\"".$id."\" }" ; # using http connections to prometheus my $data = "";