Skip to content

Commit

Permalink
schaufel_exporter: make hostname dynamic through options
Browse files Browse the repository at this point in the history
  • Loading branch information
zegeek committed Feb 9, 2024
1 parent d866b4d commit a085acb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app-metrics/schaufel_exporter/files/schaufel_exporter.pl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

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(
"h|help" => \$help,
"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;

Expand Down Expand Up @@ -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 = "";
Expand Down

0 comments on commit a085acb

Please sign in to comment.