If you've got multiple drives mounted in Windows and are monitoring usage with Telegraf, you might find you want to add a specific tag to just one drive for consumption by something in a later workflow.
For example, you might want to alert on root partitions across all servers (i.e. not just Windows boxes) so might want to add a tag to just the C:
drive to mark it as a root partition
The win_perf_counters
input plugin supports using a Wildcard, so you can easily capture all disks, but it doesn't directly allow you to tag just a single disk within that
This snippet details how to use the Template Processor plugin to conditionally apply a tag based on the value of another tag using a Golang string template
# Capture usage for our disks
[[inputs.win_perf_counters.object]]
# Disk times and queues
ObjectName = "LogicalDisk"
Instances = ["*"]
Counters = ["% Idle Time", "% Disk Time","% Disk Read Time", "% Disk Write Time", "% User Time", "% free space", "free megabytes"]
Measurement = "win_disk"
[[processors.template]]
# The name of the tag we'll add
tag = "PartitionType"
# The string template
#
# win_perf_counters includes the drive name in tag "instance"
# so if that equals C: add our tag
#
# If the condition isn't true, an empty value will be added and the
# tag won't be included
template = '{{if eq (.Tag "instance") "C:"}}RootPartition{{end}}'