Telegraf: Dynamic Tags (global tags)
Aus Wiki-WebPerfect
Version vom 6. Mai 2020, 10:31 Uhr von Admin (Diskussion | Beiträge)
tags.global.conf
- 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
- region Variables
- Variable: ClusteName
$ClusterName = (Get-Cluster -ErrorAction SilentlyContinue).Name
- endregion Variables
- Generate an array of the variables for the RegKey
$RegKeyValue =@( "ClusterName=$ClusterName", )
- 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
- Restart the Telegrafg agent to apply the configuration changes
Restart-Service -Name Telegraf