Metrics.NET.Telegraf is an extension to the Metrics.NET library that allows to report collected metrics to Telegraf.
You can also write metrics straight to InfluxDB, since the same protocol is used (Influx line protocol).
First, configure your Telegraf instance to listen for metrics.
[[inputs.udp_listener]]
service_address = ":8092"
data_format = "influx"
Then configure your application to send metrics to Telegraf.
Metric.Config
.WithReporting(config => config
.WithTelegraf("udp://localhost:8092/", "", TimeSpan.FromSeconds(10))
);
Add an HTTP listener to Telegraf configuration. No need to specify data format since it only uses line protocol.
[[inputs.http_listener]]
service_address = ":8186"
And the Telegraf URI changes slightly:
Metric.Config
.WithReporting(config => config
.WithTelegraf("http://localhost:8186/write", "", TimeSpan.FromSeconds(10))
);
Simply specify InfluxDB write URL when configuring metrics reporting.
Metric.Config
.WithReporting(config => config
.WithTelegraf("http://localhost:8086/write?db=mydb&u=admin&p=admin", "", TimeSpan.FromSeconds(10))
);
You can optionally specify additional tags and/or a namespace (a prefix), that will be attached to all reported metrics.
Metric.Config
.WithReporting(config => config
.WithTelegraf("udp://localhost:8092/", "app.perf", TimeSpan.FromSeconds(10),
new string[] { "application:myapp", "environment:prod" })
);