Telegraf: Dynamic Tags (global tags)

Aus Wiki-WebPerfect
Version vom 6. Mai 2020, 10:31 Uhr von Admin (Diskussion | Beiträge)

(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche


tags.global.conf

  1. Global tags can be specified here in key="value" format.

[global_tags]

 # dc = "us-east-1" # will tag all metrics with dc=us-east-1
 # rack = "1a"
 ## Environment variables can be used as tags, and throughout the config file
 # user = "$USER"

Cluster = "$ClusterName"



inputs.exec.set-globaltags.conf

 [[inputs.exec]]
 commands = ['powershell -NoProfile -File "C:\Program Files\Telegraf\scripts\tag.set-globaltags.ps1"']
 interval = "30m"
 timeout = "1m" 



tag.set-globaltags.ps1

      1. region Variables
  1. Variable: ClusteName

$ClusterName = (Get-Cluster -ErrorAction SilentlyContinue).Name

      1. endregion Variables


  1. Generate an array of the variables for the RegKey

$RegKeyValue =@( "ClusterName=$ClusterName", )

  1. Create or update the RegKey "Environment" with the Variables

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\telegraf" -Name "Environment" -Value $RegKeyValue -PropertyType "MultiString" -Force | Out-Null

  1. Restart the Telegrafg agent to apply the configuration changes

Restart-Service -Name Telegraf