Skip to content

Commit 034601e

Browse files
gunnaraasenJean-Louis Dupond
authored andcommitted
Add Azure Monitor output plugin (influxdata#4089)
1 parent 5548b27 commit 034601e

File tree

12 files changed

+1318
-88
lines changed

12 files changed

+1318
-88
lines changed

Gopkg.lock

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,7 @@
221221
[[override]]
222222
source = "https://github.com/fsnotify/fsnotify/archive/v1.4.7.tar.gz"
223223
name = "gopkg.in/fsnotify.v1"
224+
225+
[[constraint]]
226+
name = "github.com/Azure/go-autorest"
227+
version = "10.12.0"

docs/LICENSE_OF_DEPENDENCIES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ following works:
88
- github.com/aerospike/aerospike-client-go [APACHE](https://github.com/aerospike/aerospike-client-go/blob/master/LICENSE)
99
- github.com/amir/raidman [PUBLIC DOMAIN](https://github.com/amir/raidman/blob/master/UNLICENSE)
1010
- github.com/armon/go-metrics [MIT](https://github.com/armon/go-metrics/blob/master/LICENSE)
11+
- github.com/Azure/go-autorest [APACHE](https://github.com/Azure/go-autorest/blob/master/LICENSE)
1112
- github.com/aws/aws-sdk-go [APACHE](https://github.com/aws/aws-sdk-go/blob/master/LICENSE.txt)
1213
- github.com/beorn7/perks [MIT](https://github.com/beorn7/perks/blob/master/LICENSE)
1314
- github.com/boltdb/bolt [MIT](https://github.com/boltdb/bolt/blob/master/LICENSE)
@@ -19,6 +20,7 @@ following works:
1920
- github.com/couchbase/goutils [MIT](https://github.com/couchbase/go-couchbase/blob/master/LICENSE)
2021
- github.com/dancannon/gorethink [APACHE](https://github.com/dancannon/gorethink/blob/master/LICENSE)
2122
- github.com/davecgh/go-spew [ISC](https://github.com/davecgh/go-spew/blob/master/LICENSE)
23+
- github.com/dimchansky/utfbom [APACHE](https://github.com/dimchansky/utfbom/blob/master/LICENSE)
2224
- github.com/docker/docker [APACHE](https://github.com/docker/docker/blob/master/LICENSE)
2325
- github.com/docker/cli [APACHE](https://github.com/docker/cli/blob/master/LICENSE)
2426
- github.com/eapache/go-resiliency [MIT](https://github.com/eapache/go-resiliency/blob/master/LICENSE)

internal/models/running_output.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ func (ro *RunningOutput) AddMetric(m telegraf.Metric) {
114114
m, _ = metric.New(name, tags, fields, t, tp)
115115
}
116116

117+
if output, ok := ro.Output.(telegraf.AggregatingOutput); ok {
118+
ro.Lock()
119+
defer ro.Unlock()
120+
output.Add(m)
121+
return
122+
}
123+
117124
ro.metrics.Add(m)
118125
if ro.metrics.Len() == ro.MetricBatchSize {
119126
batch := ro.metrics.Batch(ro.MetricBatchSize)
@@ -127,6 +134,12 @@ func (ro *RunningOutput) AddMetric(m telegraf.Metric) {
127134

128135
// Write writes all cached points to this output.
129136
func (ro *RunningOutput) Write() error {
137+
if output, ok := ro.Output.(telegraf.AggregatingOutput); ok {
138+
metrics := output.Push()
139+
ro.metrics.Add(metrics...)
140+
output.Reset()
141+
}
142+
130143
nFails, nMetrics := ro.failMetrics.Len(), ro.metrics.Len()
131144
ro.BufferSize.Set(int64(nFails + nMetrics))
132145
log.Printf("D! Output [%s] buffer fullness: %d / %d metrics. ",

output.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ type Output interface {
1313
Write(metrics []Metric) error
1414
}
1515

16+
type AggregatingOutput interface {
17+
Add(in Metric)
18+
Push() []Metric
19+
Reset()
20+
}
21+
1622
type ServiceOutput interface {
1723
// Connect to the Output
1824
Connect() error

plugins/outputs/all/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
_ "github.com/influxdata/telegraf/plugins/outputs/amon"
55
_ "github.com/influxdata/telegraf/plugins/outputs/amqp"
66
_ "github.com/influxdata/telegraf/plugins/outputs/application_insights"
7+
_ "github.com/influxdata/telegraf/plugins/outputs/azure_monitor"
78
_ "github.com/influxdata/telegraf/plugins/outputs/cloudwatch"
89
_ "github.com/influxdata/telegraf/plugins/outputs/cratedb"
910
_ "github.com/influxdata/telegraf/plugins/outputs/datadog"
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Azure Monitor
2+
3+
This plugin will send custom metrics to Azure Monitor. Azure Monitor has a
4+
metric resolution of one minute. To handle this in Telegraf, the Azure Monitor
5+
output plugin will automatically aggregates metrics into one minute buckets,
6+
which are then sent to Azure Monitor on every flush interval.
7+
8+
The metrics from each input plugin will be written to a separate Azure Monitor
9+
namespace, prefixed with `Telegraf/` by default. The field name for each
10+
metric is written as the Azure Monitor metric name. All field values are
11+
written as a summarized set that includes: min, max, sum, count. Tags are
12+
written as a dimension on each Azure Monitor metric.
13+
14+
Since Azure Monitor only accepts numeric values, string-typed fields are
15+
dropped by default. There is a configuration option (`strings_as_dimensions`)
16+
to retain fields that contain strings as extra dimensions. Azure Monitor
17+
allows a maximum of 10 dimensions per metric so any dimensions over that
18+
amount will be deterministically dropped.
19+
20+
### Configuration:
21+
22+
```toml
23+
[[outputs.azure_monitor]]
24+
## Timeout for HTTP writes.
25+
# timeout = "20s"
26+
27+
## Set the namespace prefix, defaults to "Telegraf/<input-name>".
28+
# namespace_prefix = "Telegraf/"
29+
30+
## Azure Monitor doesn't have a string value type, so convert string
31+
## fields to dimensions (a.k.a. tags) if enabled. Azure Monitor allows
32+
## a maximum of 10 dimensions so Telegraf will only send the first 10
33+
## alphanumeric dimensions.
34+
# strings_as_dimensions = false
35+
36+
## Both region and resource_id must be set or be available via the
37+
## Instance Metadata service on Azure Virtual Machines.
38+
#
39+
## Azure Region to publish metrics against.
40+
## ex: region = "southcentralus"
41+
# region = ""
42+
#
43+
## The Azure Resource ID against which metric will be logged, e.g.
44+
## ex: resource_id = "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>"
45+
# resource_id = ""
46+
```
47+
48+
### Setup
49+
50+
1. [Register the `microsoft.insights` resource provider in your Azure subscription][resource provider].
51+
2. If using Managed Service Identities to authenticate an Azure VM,
52+
[enable system-assigned managed identity][enable msi].
53+
2. Use a region that supports Azure Monitor Custom Metrics,
54+
For regions with Custom Metrics support, an endpoint will be available with
55+
the format `https://<region>.monitoring.azure.com`. The following regions
56+
are currently known to be supported:
57+
- East US (eastus)
58+
- West US 2 (westus2)
59+
- South Central US (southcentralus)
60+
- West Central US (westcentralus)
61+
- North Europe (northeurope)
62+
- West Europe (westeurope)
63+
- Southeast Asia (southeastasia)
64+
65+
[resource provider]: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-supported-services
66+
[enable msi]: https://docs.microsoft.com/en-us/azure/active-directory/managed-service-identity/qs-configure-portal-windows-vm
67+
68+
### Region and Resource ID
69+
70+
The plugin will attempt to discover the region and resource ID using the Azure
71+
VM Instance Metadata service. If Telegraf is not running on a virtual machine
72+
or the VM Instance Metadata service is not available, the following variables
73+
are required for the output to function.
74+
75+
* region
76+
* resource_id
77+
78+
### Authentication
79+
80+
This plugin uses one of several different types of authenticate methods. The
81+
preferred authentication methods are different from the *order* in which each
82+
authentication is checked. Here are the preferred authentication methods:
83+
84+
1. Managed Service Identity (MSI) token
85+
- This is the prefered authentication method. Telegraf will automatically
86+
authenticate using this method when running on Azure VMs.
87+
2. AAD Application Tokens (Service Principals)
88+
- Primarily useful if Telegraf is writing metrics for other resources.
89+
[More information][principal].
90+
- A Service Principal or User Principal needs to be assigned the `Monitoring
91+
Contributor` roles.
92+
3. AAD User Tokens (User Principals)
93+
- Allows Telegraf to authenticate like a user. It is best to use this method
94+
for development.
95+
96+
[principal]: https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-application-objects
97+
98+
The plugin will authenticate using the first available of the
99+
following configurations:
100+
101+
1. **Client Credentials**: Azure AD Application ID and Secret.
102+
103+
Set the following Telegraf configuration variables:
104+
105+
- `azure_tenant_id`: Specifies the Tenant to which to authenticate.
106+
- `azure_client_id`: Specifies the app client ID to use.
107+
- `azure_client_secret`: Specifies the app secret to use.
108+
109+
Or set the following environment variables:
110+
111+
- `AZURE_TENANT_ID`: Specifies the Tenant to which to authenticate.
112+
- `AZURE_CLIENT_ID`: Specifies the app client ID to use.
113+
- `AZURE_CLIENT_SECRET`: Specifies the app secret to use.
114+
115+
2. **Client Certificate**: Azure AD Application ID and X.509 Certificate.
116+
117+
- `AZURE_TENANT_ID`: Specifies the Tenant to which to authenticate.
118+
- `AZURE_CLIENT_ID`: Specifies the app client ID to use.
119+
- `AZURE_CERTIFICATE_PATH`: Specifies the certificate Path to use.
120+
- `AZURE_CERTIFICATE_PASSWORD`: Specifies the certificate password to use.
121+
122+
3. **Resource Owner Password**: Azure AD User and Password. This grant type is
123+
*not recommended*, use device login instead if you need interactive login.
124+
125+
- `AZURE_TENANT_ID`: Specifies the Tenant to which to authenticate.
126+
- `AZURE_CLIENT_ID`: Specifies the app client ID to use.
127+
- `AZURE_USERNAME`: Specifies the username to use.
128+
- `AZURE_PASSWORD`: Specifies the password to use.
129+
130+
4. **Azure Managed Service Identity**: Delegate credential management to the
131+
platform. Requires that code is running in Azure, e.g. on a VM. All
132+
configuration is handled by Azure. See [Azure Managed Service Identity][msi]
133+
for more details. Only available when using the [Azure Resource Manager][arm].
134+
135+
[msi]: https://docs.microsoft.com/en-us/azure/active-directory/msi-overview
136+
[arm]: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview
137+
138+
**Note: As shown above, the last option (#4) is the preferred way to
139+
authenticate when running Telegraf on Azure VMs.

0 commit comments

Comments
 (0)