Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Azure Monitor output plugin #4089

Merged
merged 29 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
28bf19d
Add idea for an output that aggregates before adding to metric buffer
danielnelson May 1, 2018
c092804
Starting on azure monitor metrics integration with MSI auth
Mar 28, 2018
f596bd6
Output: Azure Monitor: Initial aggregated metric implementation
gunnaraasen Apr 11, 2018
997ece2
Output: Azure Monitor: Cleanup and add README
gunnaraasen Apr 29, 2018
9bb22cc
Refactor to use AggregatingOutput
gunnaraasen May 3, 2018
d35c32e
Additional code cleanup
gunnaraasen May 7, 2018
82d50e5
Address PR feedback
gunnaraasen Jul 9, 2018
9e12ccf
Refactor authorization to use Azure SDK
gunnaraasen Jul 10, 2018
1560f22
Finish authorization refactor
gunnaraasen Jul 10, 2018
9340102
More refactoring
gunnaraasen Jul 10, 2018
92600fc
Finish auth refactor and address remaining PR feedback
gunnaraasen Jul 10, 2018
6cf2d06
Rename output to azure_monitor along with README updates
gunnaraasen Jul 11, 2018
16afd80
Address PR feedback
gunnaraasen Aug 7, 2018
0255e11
Remove temporarily remove tests to build package
gunnaraasen Aug 29, 2018
fb70450
Fix namespace issue
gunnaraasen Aug 29, 2018
55631dd
Remove trailing whitespace
danielnelson Aug 31, 2018
acceeef
Add selfstat for metric_outside_window
danielnelson Aug 31, 2018
f4b21ca
Adjust spacing in sample config
danielnelson Aug 31, 2018
0052401
Only pull instance metadata if not fully specified
danielnelson Aug 31, 2018
0df4b6b
Add testutils for comparing telegraf.Metric
danielnelson Sep 2, 2018
00c11b9
Add tests for aggregation functions
danielnelson Sep 2, 2018
8e4d345
Add tests for write method of azure monitor output
danielnelson Sep 4, 2018
949bfe9
Use dedicated aggregate type instead of Metric
danielnelson Sep 5, 2018
b277b5f
Fix testutil metrics testcase
danielnelson Sep 5, 2018
c112dbe
Call Add/Push/Write sequentially
danielnelson Sep 5, 2018
a8e8ced
Fix error if tag value is empty
danielnelson Sep 5, 2018
1a7c64b
Update readme
danielnelson Sep 5, 2018
ed1f080
Update region list in readme
danielnelson Sep 5, 2018
e21494a
Update license of dependencies
danielnelson Sep 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,7 @@
[[override]]
source = "https://github.com/fsnotify/fsnotify/archive/v1.4.7.tar.gz"
name = "gopkg.in/fsnotify.v1"

[[constraint]]
name = "github.com/Azure/go-autorest"
version = "10.12.0"
11 changes: 11 additions & 0 deletions internal/models/running_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func (ro *RunningOutput) AddMetric(m telegraf.Metric) {
m, _ = metric.New(name, tags, fields, t, tp)
}

if output, ok := ro.Output.(telegraf.AggregatingOutput); ok {
output.Add(m)
return
}

ro.metrics.Add(m)
if ro.metrics.Len() == ro.MetricBatchSize {
batch := ro.metrics.Batch(ro.MetricBatchSize)
Expand All @@ -127,6 +132,12 @@ func (ro *RunningOutput) AddMetric(m telegraf.Metric) {

// Write writes all cached points to this output.
func (ro *RunningOutput) Write() error {
if output, ok := ro.Output.(telegraf.AggregatingOutput); ok {
metrics := output.Push()
ro.metrics.Add(metrics...)
output.Reset()
}

nFails, nMetrics := ro.failMetrics.Len(), ro.metrics.Len()
ro.BufferSize.Set(int64(nFails + nMetrics))
log.Printf("D! Output [%s] buffer fullness: %d / %d metrics. ",
Expand Down
6 changes: 6 additions & 0 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ type Output interface {
Write(metrics []Metric) error
}

type AggregatingOutput interface {
Add(in Metric)
Push() []Metric
Reset()
}

type ServiceOutput interface {
// Connect to the Output
Connect() error
Expand Down
1 change: 1 addition & 0 deletions plugins/outputs/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "github.com/influxdata/telegraf/plugins/outputs/amon"
_ "github.com/influxdata/telegraf/plugins/outputs/amqp"
_ "github.com/influxdata/telegraf/plugins/outputs/application_insights"
_ "github.com/influxdata/telegraf/plugins/outputs/azure_monitor"
_ "github.com/influxdata/telegraf/plugins/outputs/cloudwatch"
_ "github.com/influxdata/telegraf/plugins/outputs/cratedb"
_ "github.com/influxdata/telegraf/plugins/outputs/datadog"
Expand Down
130 changes: 130 additions & 0 deletions plugins/outputs/azure_monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
## Azure Monitor Custom Metrics Output for Telegraf

This plugin will send custom metrics to Azure Monitor. Azure Monitor has a
metric resolution of one minute. To handle this in Telegraf, the Azure Monitor
output plugin will automatically aggregates metrics into one minute buckets,
which are then sent to Azure Monitor on every flush interval.

The metrics from each input plugin will be written to a separate Azure Monitor
namespace, prefixed with `Telegraf/` by default. The field name for each
metric is written as the Azure Monitor metric name. All field values are
written as a summarized set that includes: min, max, sum, count. Tags are
written as a dimension on each Azure Monitor metric.

Since Azure Monitor only accepts numeric values, string-typed fields are
dropped by default. There is a configuration option (`strings_as_dimensions`)
to retain fields that contain strings as extra dimensions. Azure Monitor
allows a maximum of 10 dimensions per metric so any dimensions over that
amount will be deterministically dropped.

## Initial Setup

1. [Register your Azure subscription with the `microsoft.insights` resource
provider.](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-supported-services#portal)
2. [Consult this chart to identify which regions support Azure Monitor.](https://azure.microsoft.com/en-us/global-infrastructure/services/)
3. Only some Azure Monitor regions support Custom Metrics. For regions with
Custom Metrics support, an endpoint will be available with the format
`https://<region>.monitoring.azure.com`. The following regions are
currently known to be supported:
- West Central US, e.g. `https://westcentralus.monitoring.azure.com`
- South Central US, e.g. `https://southcentralus.monitoring.azure.com`

## Azure Authentication

This plugin uses one of several different types of authenticate methods. The
preferred authentication methods are different from the *order* in which each
authentication is checked. Here are the preferred authentication methods:

1. Managed Service Identity (MSI) token
- This is the prefered authentication method. Telegraf will automatically
authenticate using this method when running on Azure VMs.
2. AAD Application Tokens (Service Principals)
- Primarily useful if Telegraf is writing metrics for other resources. [More
information](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-application-objects).
- A Service Principal or User Principal needs to be assigned the `Monitoring
Contributor` roles.
3. AAD User Tokens (User Principals)
- Allows Telegraf to authenticate like a user. It is best to use this method
for development.

The plugin will attempt to authenticate with the first available of the
following configurations in this order:

1. **Client Credentials**: Azure AD Application ID and Secret.

Set the following Telegraf configuration variables:

- `azure_tenant_id`: Specifies the Tenant to which to authenticate.
- `azure_client_id`: Specifies the app client ID to use.
- `azure_client_secret`: Specifies the app secret to use.

Or set the following environment variables:

- `AZURE_TENANT_ID`: Specifies the Tenant to which to authenticate.
- `AZURE_CLIENT_ID`: Specifies the app client ID to use.
- `AZURE_CLIENT_SECRET`: Specifies the app secret to use.

2. **Client Certificate**: Azure AD Application ID and X.509 Certificate.

- `AZURE_TENANT_ID`: Specifies the Tenant to which to authenticate.
- `AZURE_CLIENT_ID`: Specifies the app client ID to use.
- `AZURE_CERTIFICATE_PATH`: Specifies the certificate Path to use.
- `AZURE_CERTIFICATE_PASSWORD`: Specifies the certificate password to use.

3. **Resource Owner Password**: Azure AD User and Password. This grant type is
*not recommended*, use device login instead if you need interactive login.

- `AZURE_TENANT_ID`: Specifies the Tenant to which to authenticate.
- `AZURE_CLIENT_ID`: Specifies the app client ID to use.
- `AZURE_USERNAME`: Specifies the username to use.
- `AZURE_PASSWORD`: Specifies the password to use.

4. **Azure Managed Service Identity**: Delegate credential management to the
platform. Requires that code is running in Azure, e.g. on a VM. All
configuration is handled by Azure. See [Azure Managed Service
Identity](https://docs.microsoft.com/en-us/azure/active-directory/msi-overview)
for more details. Only available on ARM-based resources.

**Note: As shown above, the last option (#4) is the preferred way to
authenticate when running Telegraf on Azure VMs. Make sure you've followed the
[initial setup instructions](#initial-setup).**

## Config

The plugin will automatically attempt to discover the region and resource ID
using the Azure VM Instance Metadata service. If Telegraf is not running on a
virtual machine or the VM Instance Metadata service is not available, the
following variables are required for the output to function.

* region
* resource_id

### Configuration:

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this can you run telegraf --usage azure_monitor and use the output (minus the Description text).

[[outputs.azure_monitor]]
## See the [Azure Monitor output plugin README](/plugins/outputs/azure_monitor/README.md)
## for details on authentication options.

## Write HTTP timeout, formatted as a string. Defaults to 20s.
#timeout = "20s"

## Set the namespace prefix, defaults to "Telegraf/<input-name>".
#namespace_prefix = "Telegraf/"

## Azure Monitor doesn't have a string value type, so convert string
## fields to dimensions (a.k.a. tags) if enabled. Azure Monitor allows
## a maximum of 10 dimensions so Telegraf will only send the first 10
## alphanumeric dimensions.
#strings_as_dimensions = false

## *The following two fields must be set or be available via the
## Instance Metadata service on Azure Virtual Machines.*

## Azure Region to publish metrics against, e.g. eastus, southcentralus.
#region = ""

## The Azure Resource ID against which metric will be logged, e.g.
## "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>"
#resource_id = ""
```
Loading