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

feat: migrate output plugins to new sample config format #10910

Merged
merged 13 commits into from
Apr 7, 2022
15 changes: 15 additions & 0 deletions plugins/outputs/amon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ for the account.
If the point value being sent cannot be converted to a float64, the metric is skipped.

Metrics are grouped by converting any `_` characters to `.` in the Point Name.

## Configuration

```toml
# Configuration for Amon Server to send metrics to.
[[outputs.amon]]
## Amon Server Key
server_key = "my-server-key" # required.

## Amon Instance URL
amon_instance = "https://youramoninstance" # required

## Connection timeout.
# timeout = "5s"
```
19 changes: 0 additions & 19 deletions plugins/outputs/amon/amon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ type Amon struct {
client *http.Client
}

var sampleConfig = `
## Amon Server Key
server_key = "my-server-key" # required.

## Amon Instance URL
amon_instance = "https://youramoninstance" # required

## Connection timeout.
# timeout = "5s"
`

type TimeSeries struct {
Series []*Metric `json:"series"`
}
Expand Down Expand Up @@ -106,14 +95,6 @@ func (a *Amon) Write(metrics []telegraf.Metric) error {
return nil
}

func (a *Amon) SampleConfig() string {
return sampleConfig
}

func (a *Amon) Description() string {
return "Configuration for Amon Server to send metrics to."
}

func (a *Amon) authenticatedURL() string {
return fmt.Sprintf("%s/api/system/%s", a.AmonInstance, a.ServerKey)
}
Expand Down
8 changes: 8 additions & 0 deletions plugins/outputs/amon/amon_sample_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package amon

func (a *Amon) SampleConfig() string {
return `{{ .SampleConfig }}`
}
92 changes: 0 additions & 92 deletions plugins/outputs/amqp/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,98 +71,6 @@ type Client interface {
Close() error
}

var sampleConfig = `
## Brokers to publish to. If multiple brokers are specified a random broker
## will be selected anytime a connection is established. This can be
## helpful for load balancing when not using a dedicated load balancer.
brokers = ["amqp://localhost:5672/influxdb"]

## Maximum messages to send over a connection. Once this is reached, the
## connection is closed and a new connection is made. This can be helpful for
## load balancing when not using a dedicated load balancer.
# max_messages = 0

## Exchange to declare and publish to.
exchange = "telegraf"

## Exchange type; common types are "direct", "fanout", "topic", "header", "x-consistent-hash".
# exchange_type = "topic"

## If true, exchange will be passively declared.
# exchange_passive = false

## Exchange durability can be either "transient" or "durable".
# exchange_durability = "durable"

## Additional exchange arguments.
# exchange_arguments = { }
# exchange_arguments = {"hash_property" = "timestamp"}

## Authentication credentials for the PLAIN auth_method.
# username = ""
# password = ""

## Auth method. PLAIN and EXTERNAL are supported
## Using EXTERNAL requires enabling the rabbitmq_auth_mechanism_ssl plugin as
## described here: https://www.rabbitmq.com/plugins.html
# auth_method = "PLAIN"

## Metric tag to use as a routing key.
## ie, if this tag exists, its value will be used as the routing key
# routing_tag = "host"

## Static routing key. Used when no routing_tag is set or as a fallback
## when the tag specified in routing tag is not found.
# routing_key = ""
# routing_key = "telegraf"

## Delivery Mode controls if a published message is persistent.
## One of "transient" or "persistent".
# delivery_mode = "transient"

## Static headers added to each published message.
# headers = { }
# headers = {"database" = "telegraf", "retention_policy" = "default"}

## Connection timeout. If not provided, will default to 5s. 0s means no
## timeout (not recommended).
# timeout = "5s"

## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false

## If true use batch serialization format instead of line based delimiting.
## Only applies to data formats which are not line based such as JSON.
## Recommended to set to true.
# use_batch_format = false

## Content encoding for message payloads, can be set to "gzip" to or
## "identity" to apply no encoding.
##
## Please note that when use_batch_format = false each amqp message contains only
## a single metric, it is recommended to use compression with batch format
## for best results.
# content_encoding = "identity"

## Data format to output.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
# data_format = "influx"
`

func (q *AMQP) SampleConfig() string {
return sampleConfig
}

func (q *AMQP) Description() string {
return "Publishes metrics to an AMQP broker"
}

func (q *AMQP) SetSerializer(serializer serializers.Serializer) {
q.serializer = serializer
}
Expand Down
8 changes: 8 additions & 0 deletions plugins/outputs/amqp/amqp_sample_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package amqp

func (q *AMQP) SampleConfig() string {
return `{{ .SampleConfig }}`
}
1 change: 1 addition & 0 deletions plugins/outputs/application_insights/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This plugin writes telegraf metrics to [Azure Application Insights](https://azur
## Configuration

```toml
# Send metrics to Azure Application Insights
[[outputs.application_insights]]
## Instrumentation key of the Application Insights resource.
instrumentation_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
Expand Down
29 changes: 0 additions & 29 deletions plugins/outputs/application_insights/application_insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,10 @@ type ApplicationInsights struct {
}

var (
sampleConfig = `
## Instrumentation key of the Application Insights resource.
instrumentation_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"

## Regions that require endpoint modification https://docs.microsoft.com/en-us/azure/azure-monitor/app/custom-endpoints
# endpoint_url = "https://dc.services.visualstudio.com/v2/track"

## Timeout for closing (default: 5s).
# timeout = "5s"

## Enable additional diagnostic logging.
# enable_diagnostic_logging = false

## Context Tag Sources add Application Insights context tags to a tag value.
##
## For list of allowed context tag keys see:
## https://github.com/microsoft/ApplicationInsights-Go/blob/master/appinsights/contracts/contexttagkeys.go
# [outputs.application_insights.context_tag_sources]
# "ai.cloud.role" = "kubernetes_container_name"
# "ai.cloud.roleInstance" = "kubernetes_pod_name"
`
is32Bit bool
is32BitChecked bool
)

func (a *ApplicationInsights) SampleConfig() string {
return sampleConfig
}

func (a *ApplicationInsights) Description() string {
return "Send metrics to Azure Application Insights"
}

func (a *ApplicationInsights) Connect() error {
if a.InstrumentationKey == "" {
return fmt.Errorf("instrumentation key is required")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package application_insights

func (a *ApplicationInsights) SampleConfig() string {
return `{{ .SampleConfig }}`
}
7 changes: 4 additions & 3 deletions plugins/outputs/azure_data_explorer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ Azure Data Explorer is a distributed, columnar store, purpose built for any type
## Configuration

```toml
# Sends metrics to Azure Data Explorer
[[outputs.azure_data_explorer]]
## The URI property of the Azure Data Explorer resource on Azure
## ex: https://myadxresource.australiasoutheast.kusto.windows.net
# endpoint_url = ""
## ex: endpoint_url = https://myadxresource.australiasoutheast.kusto.windows.net
endpoint_url = ""

## The Azure Data Explorer database that the metrics will be ingested into.
## The plugin will NOT generate this database automatically, it's expected that this database already exists before ingestion.
## ex: "exampledatabase"
# database = ""
database = ""

## Timeout for Azure Data Explorer operations
# timeout = "20s"
Expand Down
32 changes: 0 additions & 32 deletions plugins/outputs/azure_data_explorer/azure_data_explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,6 @@ type ingestorFactory func(localClient, string, string) (localIngestor, error)
const createTableCommand = `.create-merge table ['%s'] (['fields']:dynamic, ['name']:string, ['tags']:dynamic, ['timestamp']:datetime);`
const createTableMappingCommand = `.create-or-alter table ['%s'] ingestion json mapping '%s_mapping' '[{"column":"fields", "Properties":{"Path":"$[\'fields\']"}},{"column":"name", "Properties":{"Path":"$[\'name\']"}},{"column":"tags", "Properties":{"Path":"$[\'tags\']"}},{"column":"timestamp", "Properties":{"Path":"$[\'timestamp\']"}}]'`

func (adx *AzureDataExplorer) Description() string {
return "Sends metrics to Azure Data Explorer"
}

func (adx *AzureDataExplorer) SampleConfig() string {
return `
## Azure Data Explorer cluster endpoint
## ex: endpoint_url = "https://clustername.australiasoutheast.kusto.windows.net"
endpoint_url = ""

## The Azure Data Explorer database that the metrics will be ingested into.
## The plugin will NOT generate this database automatically, it's expected that this database already exists before ingestion.
## ex: "exampledatabase"
database = ""

## Timeout for Azure Data Explorer operations
# timeout = "20s"

## Type of metrics grouping used when pushing to Azure Data Explorer.
## Default is "TablePerMetric" for one table per different metric.
## For more information, please check the plugin README.
# metrics_grouping_type = "TablePerMetric"

## Name of the single table to store all the metrics (Only needed if metrics_grouping_type is "SingleTable").
# table_name = ""

## Creates tables and relevant mapping if set to true(default).
## Skips table and mapping creation if set to false, this is useful for running Telegraf with the lowest possible permissions i.e. table ingestor role.
# create_tables = true
`
}

func (adx *AzureDataExplorer) Connect() error {
authorizer, err := auth.NewAuthorizerFromEnvironmentWithResource(adx.Endpoint)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package azure_data_explorer

func (adx *AzureDataExplorer) SampleConfig() string {
return `{{ .SampleConfig }}`
}
3 changes: 2 additions & 1 deletion plugins/outputs/azure_monitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ written as a dimension on each Azure Monitor metric.
## Configuration

```toml
# Send aggregate metrics to Azure Monitor
[[outputs.azure_monitor]]
## Timeout for HTTP writes.
# timeout = "20s"
Expand All @@ -43,7 +44,7 @@ written as a dimension on each Azure Monitor metric.

## Optionally, if in Azure US Government, China, or other sovereign
## cloud environment, set the appropriate REST endpoint for receiving
## metrics. (Note: region may be unused in this context)
## metrics. (Note: region may be unused in this context)
# endpoint_url = "https://monitoring.core.usgovcloudapi.net"
```

Expand Down
40 changes: 0 additions & 40 deletions plugins/outputs/azure_monitor/azure_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,6 @@ const (
maxRequestBodySize = 4000000
)

var sampleConfig = `
## Timeout for HTTP writes.
# 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

## Both region and resource_id must be set or be available via the
## Instance Metadata service on Azure Virtual Machines.
#
## Azure Region to publish metrics against.
## ex: region = "southcentralus"
# region = ""
#
## The Azure Resource ID against which metric will be logged, e.g.
## ex: resource_id = "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>"
# resource_id = ""

## Optionally, if in Azure US Government, China or other sovereign
## cloud environment, set appropriate REST endpoint for receiving
## metrics. (Note: region may be unused in this context)
# endpoint_url = "https://monitoring.core.usgovcloudapi.net"
`

// Description provides a description of the plugin
func (a *AzureMonitor) Description() string {
return "Send aggregate metrics to Azure Monitor"
}

// SampleConfig provides a sample configuration for the plugin
func (a *AzureMonitor) SampleConfig() string {
return sampleConfig
}

// Connect initializes the plugin and validates connectivity
func (a *AzureMonitor) Connect() error {
a.cache = make(map[time.Time]map[uint64]*aggregate, 36)
Expand Down
8 changes: 8 additions & 0 deletions plugins/outputs/azure_monitor/azure_monitor_sample_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package azure_monitor

func (a *AzureMonitor) SampleConfig() string {
return `{{ .SampleConfig }}`
}
10 changes: 7 additions & 3 deletions plugins/outputs/bigquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ Be aware that this plugin accesses APIs that are [chargeable](https://cloud.goog
## Configuration

```toml
# Configuration for Google Cloud BigQuery to send entries
[[outputs.bigquery]]
## GCP Project
project = "erudite-bloom-151019"
## Credentials File
credentials_file = "/path/to/service/account/key.json"

## The BigQuery dataset
## Google Cloud Platform Project
project = "my-gcp-project"

## The namespace for the metric descriptor
dataset = "telegraf"

## Timeout for BigQuery operations.
Expand Down
Loading