### PostgreSQL TLS Configuration Example Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/postgresql/README.md Example of how to configure TLS/SSL options for a PostgreSQL connection string. ```shell host=localhost user=pgotest dbname=app_production sslmode=require sslkey=/etc/telegraf/key.pem sslcert=/etc/telegraf/cert.pem sslrootcert=/etc/telegraf/ca.pem ``` -------------------------------- ### Proxmox Example Output Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/proxmox/README.md This is an example of the metrics output format from the Proxmox input plugin. ```text proxmox,host=pxnode,node_fqdn=pxnode.example.com,vm_fqdn=vm1.example.com,vm_id=112,vm_name=vm1,vm_type=lxc cpuload=0.147998116735236,disk_free=4461129728i,disk_total=5217320960i,disk_used=756191232i,disk_used_percentage=14,disk_read_bytes=8604417024i,disk_write_bytes=2481549824i,net_in_bytes=1469711887i,net_out_bytes=58448585i,mem_free=1046827008i,mem_total=1073741824i,mem_used=26914816i,mem_used_percentage=2,status="running",swap_free=536698880i,swap_total=536870912i,swap_used=172032i,swap_used_percentage=0,uptime=1643793i 1595457277000000000 ``` -------------------------------- ### Configure the example input plugin Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/example/README.md Add this block to your Telegraf configuration file to enable the example plugin. ```toml # This is an example plugin [[inputs.example]] example_option = "example_value" ``` -------------------------------- ### View Example Plugin Output Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/supervisor/README.md Sample output format for supervisor_processes and supervisor_instance metrics. ```text supervisor_processes,group=ExampleGroup,id=supervisor,port=9001,process=ExampleProcess,source=localhost state=20i,uptime=75958i 1659786637000000000 supervisor_instance,id=supervisor,port=9001,source=localhost state=1i 1659786637000000000 ``` -------------------------------- ### Start Telegraf Service using net start Source: https://github.com/influxdata/telegraf/blob/master/docs/WINDOWS_SERVICE.md This command starts the Telegraf service using the Windows 'net start' command. Ensure the service name 'telegraf' matches your installation. ```shell > net start telegraf ``` -------------------------------- ### Basic Testcontainer Setup for PostgreSQL Source: https://github.com/influxdata/telegraf/blob/master/docs/INTEGRATION_TESTS.md Demonstrates setting up a PostgreSQL container for integration testing. Ensure the container image, exposed ports, environment variables, and a waiting strategy are defined. ```go servicePort := "5432" container := testutil.Container{ Image: "postgres:alpine", ExposedPorts: []string{servicePort}, Env: map[string]string{ "POSTGRES_HOST_AUTH_METHOD": "trust", }, WaitingFor: wait.ForAll( wait.ForLog("database system is ready to accept connections"), wait.ForListeningPort(servicePort), ), } require.NoError(t, container.Start(), "failed to start container") defer func() { require.NoError(t, container.Terminate(), "terminating container failed") }() ``` -------------------------------- ### PromQL Range Query Example Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/promql/README.md Example of configuring a range query to fetch metrics over a specified time period. Includes 'start', 'end', and 'step' parameters for time-series data. ```toml ## Range queries, multiple instances are allowed [[inputs.promql.range]] ## Fallback name of the resulting metrics to use as metric name in case ## the __name__ property of the query results is empty. # name = "promql" ## Query to execute query = 'prometheus_http_requests_total{job="prometheus"}' ## Range parameters relative to the gathering time with positive values ## refer to BEFORE and negative to AFTER the gathering time start = "5m" # end = "0s" step = "1m" ## Limit for the number of results returned by the server with zero ## meaning no limit # limit = 0 ``` -------------------------------- ### Get Telegraf Version Source: https://github.com/influxdata/telegraf/blob/master/cmd/telegraf/README.md Use this command to check the installed Telegraf binary version. ```bash telegraf version ``` -------------------------------- ### Example Configuration Source: https://github.com/influxdata/telegraf/blob/master/plugins/processors/ifname/README.md A minimal configuration example for the ifname processor, setting the source interface index tag and the destination interface name tag. ```toml [[processors.ifname]] tag = "ifIndex" dest = "ifName" ``` -------------------------------- ### Example Plugin Configuration with Labels Source: https://github.com/influxdata/telegraf/blob/master/config/README.md Shows how to add a 'labels' table to a plugin configuration to define key-value pairs for matching against command-line selectors. Labels are plain strings. ```toml [[inputs.cpu]] [inputs.cpu.labels] app = "payments" region = "us-east" env = "prod" ``` -------------------------------- ### Get Bridge Config Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/huebridge/README.md Example curl command to retrieve bridge configuration, including the bridge ID. ```bash curl -k https://
/api/config/0 ``` -------------------------------- ### Install Telegraf Service with Specific Config File Source: https://github.com/influxdata/telegraf/blob/master/docs/WINDOWS_SERVICE.md When installing Telegraf as a service, always specify the full path to the configuration file using the `--config` flag to prevent startup failures. This example shows the correct way to specify a custom config file path. ```shell > "C:\Program Files\Telegraf\telegraf.exe" --config "C:\MyConfigs\telegraf.conf" service install ``` -------------------------------- ### Example Disk I/O Utilization and Service Time Output Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/diskio/README.md This example shows disk I/O utilization (`io_util`), service time (`io_svctm`), and I/O await time (`io_await`) metrics for different disks. These values represent the percentage of time the disk was active, the service time per I/O operation, and the time spent waiting for I/O, respectively. ```text diskio,name=sda io_await:0.3317307692307692,io_svctm:0.07692307692307693,io_util:0.5329780146568954 1578326400000000000 diskio,name=sda1 io_await:0.3317307692307692,io_svctm:0.07692307692307693,io_util:0.5329780146568954 1578326400000000000 diskio,name=sda2 io_await:0.3317307692307692,io_svctm:0.07692307692307693,io_util:0.5329780146568954 1578326400000000000 ``` -------------------------------- ### Filter Windows Network Metrics with tagdrop Source: https://github.com/influxdata/telegraf/blob/master/config/README.md Use tagdrop to exclude specific network interface instances. This example prevents metrics from interfaces starting with 'isatap' or 'Local' from being collected. ```toml [[inputs.win_perf_counters]] [[inputs.win_perf_counters.object]] ObjectName = "Network Interface" Instances = ["*"] Counters = [ "Bytes Received/sec", "Bytes Sent/sec" ] Measurement = "win_net" # Do not send metrics where the Windows interface name (instance) begins with # 'isatap' or 'Local' [inputs.win_perf_counters.tagdrop] instance = ["isatap*", "Local*"] ``` -------------------------------- ### Example Varnish Metrics Output (Version 1) Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/varnish/README.md Shows a basic example of Varnish metrics collected by the plugin. ```text varnish,host=rpercy-VirtualBox,section=MAIN cache_hit=0i,cache_miss=0i,uptime=8416i 1462765437090957980 ``` -------------------------------- ### Load Time Library Source: https://github.com/influxdata/telegraf/blob/master/plugins/processors/starlark/README.md Load the time library for time-related functions such as parsing durations, getting the current time, and timezone validation. See time_date.star, time_duration.star, and time_timestamp.star for examples. ```Starlark load("time.star", "time") ``` -------------------------------- ### TOML Configuration Style Example Source: https://github.com/influxdata/telegraf/blob/master/docs/developers/SAMPLE_CONFIG.md Illustrates TOML configuration style with double-commented documentation and default values. ```toml ## This text describes what an the exchange_type option does. # exchange_type = "topic" ``` ```toml ## Brokers are the AMQP brokers to connect to. brokers = ["amqp://localhost:5672"] ``` ```toml ## What an exchange type is. # exchange_type = "topic" ``` ```toml ## Static routing key. Used when no routing_tag is set or as a fallback ## when the tag specified in routing tag is not found. ## example: routing_key = "telegraf" # routing_key = "" ``` ```toml ## If true, queue will be declared as an exclusive queue. # queue_exclusive = false ## If true, queue will be declared as an auto deleted queue. # queue_auto_delete = false ## Authentication credentials for the PLAIN auth_method. # username = "" # password = "" ``` -------------------------------- ### MQTT Consumer Configuration Example Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/mqtt_consumer/README.md Basic configuration for the MQTT consumer plugin, including server addresses, topics to subscribe to, and data format settings. This example demonstrates how to set up the plugin to consume data in a 'value' format. ```toml [[inputs.mqtt_consumer]] ## Broker URLs for the MQTT server or cluster. To connect to multiple ## clusters or standalone servers, use a separate plugin instance. ## example: servers = ["tcp://localhost:1883"] ## servers = ["ssl://localhost:1883"] ## servers = ["ws://localhost:1883"] servers = ["tcp://127.0.0.1:1883"] ## Topics that will be subscribed to. topics = [ "telegraf/+/cpu/23", ] ## Data format to consume. ## 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_INPUT.md data_format = "value" data_type = "float" [[inputs.mqtt_consumer.topic_parsing]] topic = "telegraf/one/cpu/23" measurement = "_/_/measurement/_" tags = "tag/_/_/_" fields = "_/_/_/test" [inputs.mqtt_consumer.topic_parsing.types] test = "int" ``` -------------------------------- ### Printer Secret Store Plugin Implementation Source: https://github.com/influxdata/telegraf/blob/master/docs/SECRETSTORES.md Implements the Telegraf SecretStore interface for a 'Printer' plugin. This example demonstrates Get, Set, List, and GetResolver methods, and registers the plugin using secretstores.Add. ```go //go:generate ../../../tools/readme_config_includer/generator package main import ( _ "embed" "errors" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/secretstores" ) //go:embed sample.conf var sampleConfig string type Printer struct { Log telegraf.Logger `toml:"-"` cache map[string]string } func (p *Printer) SampleConfig() string { return sampleConfig } func (p *Printer) Init() error { return nil } // Get searches for the given key and return the secret func (p *Printer) Get(key string) ([]byte, error) { v, found := p.cache[key] if !found { return nil, errors.New("not found") } return []byte(v), nil } // Set sets the given secret for the given key func (p *Printer) Set(key, value string) error { p.cache[key] = value return nil } // List lists all known secret keys func (p *Printer) List() ([]string, error) { keys := make([]string, 0, len(p.cache)) for k := range p.cache { keys = append(keys, k) } return keys, nil } // GetResolver returns a function to resolve the given key. func (p *Printer) GetResolver(key string) (telegraf.ResolveFunc, error) { resolver := func() ([]byte, bool, error) { s, err := p.Get(key) return s, false, err } return resolver, nil } // Register the secret store on load. func init() { secretstores.Add("printer", func(string) telegraf.SecretStore { return &Printer{} }) } ``` -------------------------------- ### View Example Plugin Output Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/net_response/README.md Sample metrics generated by the plugin showing success, connection failure, and read failure states. ```text net_response,port=8086,protocol=tcp,result=success,server=localhost response_time=0.000092948,result_code=0i,result_type="success" 1525820185000000000 net_response,port=8080,protocol=tcp,result=connection_failed,server=localhost result_code=2i,result_type="connection_failed" 1525820088000000000 net_response,port=8080,protocol=udp,result=read_failed,server=localhost result_code=3i,result_type="read_failed",string_found=false 1525820088000000000 ``` -------------------------------- ### Get Host IP using curl and jq Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/kubernetes/README.md Example command to retrieve the IP address of the host running a pod, using curl to query the Kubernetes API and jq to parse the JSON response. Requires API URL, pod namespace, and pod hostname to be set as environment variables. ```sh curl -s $API_URL/api/v1/namespaces/$POD_NAMESPACE/pods/$HOSTNAME \ --header "Authorization: Bearer $TOKEN" \ --insecure | jq -r '.status.hostIP' ``` -------------------------------- ### Node Configuration using Namespace Index (Equivalent) Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/opcua_listener/README.md This configuration using a namespace index is equivalent to the Namespace URI example, demonstrating the simpler but potentially less stable method. ```toml [[inputs.opcua_listener.nodes]] name = "ServerStatus" namespace = "0" identifier_type = "i" identifier = "2256" ``` -------------------------------- ### JSONv2 Format Example Source: https://github.com/influxdata/telegraf/blob/master/plugins/serializers/nowmetric/README.md Example of the JSONv2 format using a records object. ```json { "records": [ { "metric_type": "Disk C: % Free Space", "resource": "C:\\", "node": "lnux100", "value": 50, "timestamp": 1473183012000, "ci2metric_id": { "node": "lnux100" }, "source": "Telegraf" } ] } ``` -------------------------------- ### Telegraf Metric Input Example Source: https://github.com/influxdata/telegraf/blob/master/plugins/outputs/zabbix/README.md Example of a standard Telegraf metric measurement. ```text measurement,host=hostname valueA=0,valueB=1 ``` -------------------------------- ### Example Windows Services Output Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/win_services/README.md This is an example of the metrics collected for Windows services, showing the state and startup mode. ```text win_services,host=WIN2008R2H401,display_name=Server,service_name=LanmanServer state=4i,startup_mode=2i 1500040669000000000 win_services,display_name=Remote\ Desktop\ Services,service_name=TermService,host=WIN2008R2H401 state=1i,startup_mode=3i 1500040669000000000 ``` -------------------------------- ### Libvirt Plugin Example Configuration Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/libvirt/README.md A specific configuration example for the libvirt plugin, specifying domain names, the libvirt URI, enabled metrics, and additional statistics to collect. ```toml [[inputs.libvirt]] domain_names = ["ubuntu_20"] libvirt_uri = "qemu:///system" libvirt_metrics = ["state", "interface"] additional_statistics = ["vcpu_mapping"] ``` -------------------------------- ### Modbus Example Output Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/modbus/README.md An example of the metric output generated by the Modbus plugin. ```text modbus,name=device,slave_id=1,type=holding_register energy=3254.5,power=23.5,frequency=49,97 1701777274026591864 ``` -------------------------------- ### LVM Input Plugin Example Output Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/lvm/README.md Sample output demonstrating metrics collected for physical volumes, volume groups, and logical volumes, including details on size, free space, and usage percentages. ```text lvm_physical_vol,path=/dev/sda2,vol_group=vgroot free=0i,size=249510756352i,used=249510756352i,used_percent=100 1631823026000000000 lvm_physical_vol,path=/dev/sdb,vol_group=docker free=3858759680i,size=128316342272i,used=124457582592i,used_percent=96.99277612525741 1631823026000000000 lvm_vol_group,name=vgroot free=0i,logical_volume_count=1i,physical_volume_count=1i,size=249510756352i,snapshot_count=0i,used_percent=100 1631823026000000000 lvm_vol_group,name=docker free=3858759680i,logical_volume_count=1i,physical_volume_count=1i,size=128316342272i,snapshot_count=0i,used_percent=96.99277612525741 1631823026000000000 lvm_logical_vol,name=lvroot,vol_group=vgroot data_percent=0,metadata_percent=0,size=249510756352i 1631823026000000000 lvm_logical_vol,name=thinpool,vol_group=docker data_percent=0.36000001430511475,metadata_percent=1.3300000429153442,size=121899057152i 1631823026000000000 ``` -------------------------------- ### Homie-v4 Layout Example Metrics Source: https://github.com/influxdata/telegraf/blob/master/plugins/outputs/mqtt/README.md Example metrics demonstrating the 'homie-v4' layout format. ```text modbus,source=device\ 1,location=main\ building,type=Machine\ A,status=ok temperature=21.4,serial\ number="324nlk234r5u9834t",working\ hours=123i,supplied=true 1676522982000000000 modbus,source=device\ 2,location=main\ building,type=Machine\ B,status=offline supplied=false 1676522982000000000 modbus,source=device\ 2,location=main\ building,type=Machine\ B,status=online supplied=true,Throughput=12345i,Load\ [%]=81.2,account\ no="T3L3GrAf",Temperature=25.38,Voltage=24.1,Current=100 1676542982000000000 ``` -------------------------------- ### Field Layout Example Metrics Source: https://github.com/influxdata/telegraf/blob/master/plugins/outputs/mqtt/README.md Example metrics demonstrating the 'field' layout format. ```text modbus,location=main\ building,source=device\ 1,status=ok,type=Machine\ A temperature=21.4,serial\ number="324nlk234r5u9834t",working\ hours=123i,supplied=true 1676522982000000000 modbus,location=main\ building,source=device\ 2,status=offline,type=Machine\ B temperature=25.0,supplied=true 1676522982000000000 ``` -------------------------------- ### vSphere Inventory Path Structure Example Source: https://github.com/influxdata/telegraf/blob/master/plugins/inputs/vsphere/README.md Illustrates the tree-like structure of a vSphere inventory, showing how resources like datacenters, hosts, clusters, and VMs are organized. ```bash