Documentation ¶
Overview ¶
Package friendlytagger implements a telegraf processing plugin that adds human-readable labels to certain tags present in time series input.
Author: Shane Alcock <shane@alcock.co.nz>
Code tags that can be augmented with labels by this plugin:
continent_code country_code region_code county_code asn
The code -> label mappings for all code tags (except the continent codes which are statically defined in this module) are read from an SQLite3 database. The database should have a separate table for each code tag type, e.g. a table for country codes, a table for ASNs etc.
The mapping tables should have the following columns:
code (text) label (text) apply_from (int)
"code" is the tag value that will already be present in the report plugin output for the metric concerned. "label" is the human-readable label that corresponds to the code. For instance, a country code of "US" would have a label of "United States of America".
"apply_from" is a unix timestamp that indicates when a given label should be considered as applying to the code. This allows for a code to have different labels at different time periods, such as when a region changes names or an ASN changes ownership (and therefore name). When assigning a label to a code, this plugin will use the label with the closest "apply_from" timestamp to the timestamp associated with the telegraf metric.
If the underlying database is updated, you will need to restart telegraf to load any new mappings into the plugin.
See the accompanying README for details on how to install this plugin.
Index ¶
- type FriendlyTag
- type FriendlyTagger
- func (tagger *FriendlyTagger) Apply(in ...telegraf.Metric) []telegraf.Metric
- func (tagger *FriendlyTagger) Description() string
- func (tagger *FriendlyTagger) InsertFriendlyLabels(metric telegraf.Metric) telegraf.Metric
- func (tagger *FriendlyTagger) LoadAsnLabels()
- func (tagger *FriendlyTagger) LoadCountryLabels()
- func (tagger *FriendlyTagger) LoadCountyLabels()
- func (tagger *FriendlyTagger) LoadGenericLabels(table string, replacecode string, replacelabel string)
- func (tagger *FriendlyTagger) LoadRegionLabels()
- func (tagger *FriendlyTagger) SampleConfig() string
- type LabelSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FriendlyTag ¶
type FriendlyTag struct { // The name of the code field in the report plugin output CodedTag string // The name of the label field to add to the report plugin output NewTag string // The code->label mappings for this tag type ValueMappings map[string]LabelSet }
A set of code->label mappings for a single tag type (e.g. country_code)
type FriendlyTagger ¶
type FriendlyTagger struct { // The path to the SQLite3 database where the code->label mappings are DatabaseName string // The name of the table where the country code mappings are CountryLabelTable string // The name of the table where the region code mappings are RegionLabelTable string // The name of the table where the county code mappings are CountyLabelTable string // The name of the table where the ASN name mappings are AsnLabelTable string // The set of code->label mappings, indexed by tag type (e.g. // country_code, asn, region_code, etc.) Replacements map[string]FriendlyTag LastReload int64 ReloadFrequency int64 }
An instance of this plugin
func (*FriendlyTagger) Apply ¶
func (tagger *FriendlyTagger) Apply(in ...telegraf.Metric) []telegraf.Metric
Apply takes a metric received by telegraf and adds the appropriate human-friendly labels for any geo-tags and ASNs that might be present in the metric.
func (*FriendlyTagger) Description ¶
func (tagger *FriendlyTagger) Description() string
Description returns a brief description of this plugin, required by the telegraf processor plugin interface.
func (*FriendlyTagger) InsertFriendlyLabels ¶
func (tagger *FriendlyTagger) InsertFriendlyLabels(metric telegraf.Metric) telegraf.Metric
InsertFriendlyLabels scans a telegraf metric for any tags that match names where we can potentially add human-readable alternative labels, then looks up the value for the tag in our replacements map. If it finds a suitable label, then that label is added to the metric as another tag.
func (*FriendlyTagger) LoadAsnLabels ¶
func (tagger *FriendlyTagger) LoadAsnLabels()
LoadAsnLabels populates the Replacements map with the ASN to ASN label mappings from the database
func (*FriendlyTagger) LoadCountryLabels ¶
func (tagger *FriendlyTagger) LoadCountryLabels()
LoadCountryLabels populates the Replacements map with the country code to country label mappings from the database
func (*FriendlyTagger) LoadCountyLabels ¶
func (tagger *FriendlyTagger) LoadCountyLabels()
LoadCountyLabels populates the Replacements map with the county code to county label mappings from the database
func (*FriendlyTagger) LoadGenericLabels ¶
func (tagger *FriendlyTagger) LoadGenericLabels(table string, replacecode string, replacelabel string)
LoadGenericLabels reads the code->label mappings for a given tag type from the SQLite database and inserts them into memory for fast lookup when processing. "table" is the name of the table to read the mappings from. "replacecode" is the tag name for the field where the code will be found in the report plugin output (e.g. 'country_code', 'asn'). "replacelabel" is the tag name for the field where the label will be added if the code matches one of the codes found in the table (e.g. "country_label").
func (*FriendlyTagger) LoadRegionLabels ¶
func (tagger *FriendlyTagger) LoadRegionLabels()
LoadRegionLabels populates the Replacements map with the region code to region label mappings from the database
func (*FriendlyTagger) SampleConfig ¶
func (tagger *FriendlyTagger) SampleConfig() string
SampleConfig returns some sample configuration for this plugin, required by the telegraf processor plugin interface.
type LabelSet ¶
A set of labels for a given code and the timestamps from which those labels apply. Each entry in the Labels array will have its corresponding timestamp at the same index in the StartTimes array.
Example: ASN 681 changes its name from "University of Waikato, NZ" to "Quigley College, NZ" at timestamp 1592346088
StartTimes: {0, 1592346088} Labels: {"University of Waikato, NZ", "Quigley College, NZ"}