From 01ae944c809962f0b2f3fb764b9396c578843b4e Mon Sep 17 00:00:00 2001 From: Nikola Knezevic Date: Thu, 14 Nov 2019 16:02:00 +0100 Subject: [PATCH] Add host tag to InfluxDB metrics This should help us discern machines in environments with multiple Hydra deployments. --- src/lib/Hydra/Plugin/InfluxDBNotification.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/Hydra/Plugin/InfluxDBNotification.pm b/src/lib/Hydra/Plugin/InfluxDBNotification.pm index 3b653201..21a3fa31 100644 --- a/src/lib/Hydra/Plugin/InfluxDBNotification.pm +++ b/src/lib/Hydra/Plugin/InfluxDBNotification.pm @@ -3,9 +3,8 @@ package Hydra::Plugin::InfluxDBNotification; use strict; use parent 'Hydra::Plugin'; use HTTP::Request; -# use JSON; use LWP::UserAgent; -# use Hydra::Helper::CatalystUtils; +use Sys::Hostname::Long; sub isEnabled { my ($self) = @_; @@ -67,6 +66,11 @@ sub toBuildStatusClass { } } +# Get the hostname. If we can't, we swallow the exception from hostname. +my $hostname = eval { + hostname_long; +}; + # Syntax # build_status,job=my-job status=failed,result=dependency-failed duration=123i # | -------------------- -------------- | @@ -81,6 +85,8 @@ sub createLine { foreach my $tag (sort keys %$tagSet) { push @tags, "$tag=$tagSet->{$tag}"; } + # we add host tag to all outputs + push @tags, "host=$hostname" if defined $hostname; my @fields = (); foreach my $field (sort keys %$fieldSet) { push @fields, "$field=$fieldSet->{$field}";