From d2ba8908a76a8dbebcd2583f0b21e678e90f39aa Mon Sep 17 00:00:00 2001 From: UnAfraid Date: Mon, 9 Jan 2023 21:42:34 +0200 Subject: [PATCH] Added server_id, server_host and server_name as tags for influxdb --- app/Jobs/SendDataToInfluxDbV2.php | 2 +- app/Models/Result.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Jobs/SendDataToInfluxDbV2.php b/app/Jobs/SendDataToInfluxDbV2.php index 4b25e6fbc..637778cfa 100644 --- a/app/Jobs/SendDataToInfluxDbV2.php +++ b/app/Jobs/SendDataToInfluxDbV2.php @@ -59,7 +59,7 @@ public function handle() $dataArray = [ 'name' => 'speedtest', - 'tags' => null, + 'tags' => $this->result->formatTagsForInfluxDB2(), 'fields' => $this->result->formatForInfluxDB2(), 'time' => strtotime($this->result->created_at), ]; diff --git a/app/Models/Result.php b/app/Models/Result.php index b4ac8ddcd..1e01078f1 100644 --- a/app/Models/Result.php +++ b/app/Models/Result.php @@ -54,6 +54,18 @@ class Result extends Model 'created' => ResultCreated::class, ]; + /** + * The tag attributes to be passed to influxdb + */ + public function formatTagsForInfluxDB2(): array + { + return [ + 'server_id' => (int) $this->server_id, + 'server_host' => $this->server_host, + 'server_name' => $this->server_name, + ]; + } + /** * The attributes to be passed to influxdb */