├── scripts ├── build.py ├── docker-entrypoint.sh ├── local_circleci.sh ├── deb │ ├── pre-remove.sh │ ├── post-remove.sh │ └── pre-install.sh ├── buster.docker ├── stretch.docker ├── telegraf_entry_mac ├── ci-1.15.docker ├── ci-1.16.docker ├── telegraf.service ├── alpine.docker ├── check-file-changes.sh └── rpm │ └── pre-install.sh ├── internal ├── globpath │ └── testdata │ │ ├── log1.log │ │ ├── log2.log │ │ ├── log[!.log │ │ ├── nested1 │ │ └── nested2 │ │ │ └── nested.txt │ │ └── test.conf ├── goplugin │ ├── noplugin.go │ └── plugin.go ├── templating │ └── template_test.go ├── process │ ├── process_windows.go │ └── process_posix.go ├── docker │ └── docker.go ├── syslog │ └── framing_test.go └── choice │ └── choice.go ├── plugins ├── inputs │ ├── filecount │ │ └── testdata │ │ │ ├── bar │ │ │ ├── baz │ │ │ ├── foo │ │ │ ├── subdir │ │ │ ├── quux │ │ │ ├── quuz │ │ │ └── nested2 │ │ │ │ └── qux │ │ │ └── qux │ ├── filestat │ │ └── testdata │ │ │ ├── log1.log │ │ │ ├── log2.log │ │ │ └── test.conf │ ├── cgroup │ │ ├── testdata │ │ │ ├── memory │ │ │ │ ├── memory.empty │ │ │ │ ├── notify_on_release │ │ │ │ ├── memory.use_hierarchy │ │ │ │ ├── memory.usage_in_bytes │ │ │ │ ├── group_1 │ │ │ │ │ ├── memory.kmem.max_usage_in_bytes │ │ │ │ │ ├── memory.limit_in_bytes │ │ │ │ │ ├── memory.kmem.limit_in_bytes │ │ │ │ │ ├── group_1_1 │ │ │ │ │ │ ├── memory.limit_in_bytes │ │ │ │ │ │ └── memory.stat │ │ │ │ │ ├── group_1_2 │ │ │ │ │ │ ├── memory.limit_in_bytes │ │ │ │ │ │ └── memory.stat │ │ │ │ │ └── memory.stat │ │ │ │ ├── memory.limit_in_bytes │ │ │ │ ├── memory.max_usage_in_bytes │ │ │ │ ├── memory.kmem.limit_in_bytes │ │ │ │ ├── group_2 │ │ │ │ │ ├── memory.limit_in_bytes │ │ │ │ │ ├── group_1_1 │ │ │ │ │ │ ├── memory.limit_in_bytes │ │ │ │ │ │ └── memory.stat │ │ │ │ │ └── memory.stat │ │ │ │ ├── memory.stat │ │ │ │ └── memory.numa_stat │ │ │ ├── cpu │ │ │ │ ├── cpu.cfs_quota_us │ │ │ │ └── cpuacct.usage_percpu │ │ │ └── blkio │ │ │ │ └── blkio.io_serviced │ │ └── cgroup_notlinux.go │ ├── multifile │ │ └── testdata │ │ │ ├── bool.txt │ │ │ ├── int.txt │ │ │ ├── tag.txt │ │ │ ├── float.txt │ │ │ └── string.txt │ ├── dpdk │ │ └── dpdk_notlinux.go │ ├── ipvs │ │ └── ipvs_notlinux.go │ ├── bcache │ │ └── bcache_windows.go │ ├── lustre2 │ │ └── lustre2_windows.go │ ├── nats │ │ └── nats_freebsd.go │ ├── postfix │ │ ├── postfix_windows.go │ │ ├── stat_none.go │ │ ├── stat_ctimespec.go │ │ └── stat_ctim.go │ ├── postgresql_extensible │ │ └── testdata │ │ │ └── test.sql │ ├── sensors │ │ └── sensors_notlinux.go │ ├── sysstat │ │ └── sysstat_notlinux.go │ ├── varnish │ │ └── varnish_windows.go │ ├── iptables │ │ └── iptables_nocompile.go │ ├── conntrack │ │ └── conntrack_notlinux.go │ ├── intel_rdt │ │ ├── intel_rdt_windows.go │ │ └── processes.go │ ├── logparser │ │ ├── logparser_solaris.go │ │ ├── testdata │ │ │ ├── test_c.log │ │ │ ├── test_b.log │ │ │ └── test_a.log │ │ └── dev │ │ │ ├── test.log │ │ │ ├── docker-compose.yml │ │ │ └── telegraf.conf │ ├── execd │ │ ├── shim │ │ │ ├── example │ │ │ │ └── cmd │ │ │ │ │ ├── plugin.conf │ │ │ │ │ └── main.go │ │ │ ├── testdata │ │ │ │ └── plugin.conf │ │ │ ├── README.md │ │ │ ├── input.go │ │ │ ├── goshim_windows.go │ │ │ └── goshim_posix.go │ │ ├── examples │ │ │ ├── count.sh │ │ │ ├── count.go │ │ │ └── count.rb │ │ └── execd_windows.go │ ├── kernel_vmstat │ │ └── kernel_vmstat_notlinux.go │ ├── ras │ │ └── ras_notlinux.go │ ├── systemd_units │ │ └── systemd_units_notlinux.go │ ├── win_services │ │ └── win_services_notwindows.go │ ├── intel_powerstat │ │ ├── intel_powerstat_notlinux.go │ │ └── dto.go │ ├── rabbitmq │ │ └── testdata │ │ │ ├── set2 │ │ │ ├── federation-links.json │ │ │ └── memory.json │ │ │ └── set1 │ │ │ ├── exchanges.json │ │ │ └── memory.json │ ├── win_perf_counters │ │ └── win_perf_counters_notwindows.go │ ├── file │ │ ├── testdata │ │ │ ├── mtr-utf-16be.csv │ │ │ ├── mtr-utf-16le.csv │ │ │ └── mtr-utf-8.csv │ │ ├── dev │ │ │ ├── telegraf.conf │ │ │ ├── testfiles │ │ │ │ ├── grok_a.log │ │ │ │ └── json_a.log │ │ │ └── docker-compose.yml │ │ └── README.md │ ├── tail │ │ ├── tail_solaris.go │ │ └── testdata │ │ │ ├── cpu-utf-16be.influx │ │ │ ├── cpu-utf-16le.influx │ │ │ ├── test-patterns │ │ │ ├── cpu-utf-8.influx │ │ │ └── test_multiline.log │ ├── zipkin │ │ └── testdata │ │ │ ├── threespans.dat │ │ │ ├── cli_microservice.dat │ │ │ ├── distributed_trace_sample.dat │ │ │ └── json │ │ │ └── distributed_trace_sample.json │ ├── clickhouse │ │ └── dev │ │ │ ├── tls_settings.xml │ │ │ ├── telegraf.conf │ │ │ ├── part_log.xml │ │ │ ├── text_log.xml │ │ │ ├── telegraf_ssl.conf │ │ │ ├── zookeeper.xml │ │ │ └── dhparam.pem │ ├── http_listener_v2 │ │ └── testdata │ │ │ └── testmsgs.gz │ ├── influxdb_listener │ │ └── testdata │ │ │ └── testmsgs.gz │ ├── influxdb_v2_listener │ │ └── testdata │ │ │ └── testmsgs.gz │ ├── sql │ │ ├── drivers_sqlite.go │ │ └── drivers.go │ ├── x509_cert │ │ └── dev │ │ │ └── telegraf.conf │ ├── kibana │ │ └── test_environment │ │ │ └── run_test_env.sh │ ├── beat │ │ └── beat6_info.json │ ├── procstat │ │ ├── dev │ │ │ └── telegraf.conf │ │ ├── win_service_notwindows.go │ │ ├── native_finder_test.go │ │ ├── native_finder_windows.go │ │ └── native_finder_notwindows.go │ ├── redfish │ │ └── testdata │ │ │ └── hp_chassis.json │ ├── zookeeper │ │ └── dev │ │ │ ├── telegraf.conf │ │ │ └── docker-compose.yml │ ├── win_eventlog │ │ └── win_eventlog_notwindows.go │ ├── mongodb │ │ └── dev │ │ │ ├── telegraf.conf │ │ │ └── docker-compose.yml │ ├── diskio │ │ └── diskio_other.go │ ├── processes │ │ ├── processes.go │ │ └── processes_windows.go │ ├── burrow │ │ └── testdata │ │ │ ├── v3_kafka.json │ │ │ ├── v3_kafka_clustername1_topic.json │ │ │ ├── error.json │ │ │ ├── v3_kafka_clustername1_consumer.json │ │ │ └── v3_kafka_clustername1_topic_topicA.json │ ├── registry.go │ ├── couchdb │ │ └── dev │ │ │ └── telegraf.conf │ ├── tcp_listener │ │ └── README.md │ ├── udp_listener │ │ └── README.md │ ├── docker │ │ ├── dev │ │ │ └── telegraf.conf │ │ └── errors.go │ ├── dmcache │ │ ├── dmcache_notlinux.go │ │ └── dmcache.go │ ├── opentelemetry │ │ └── logger.go │ ├── zfs │ │ └── zfs_other.go │ ├── kubernetes │ │ └── kubernetes_pods.go │ ├── nsq │ │ └── README.md │ ├── ethtool │ │ └── ethtool_notlinux.go │ ├── ravendb │ │ └── testdata │ │ │ ├── collections_min.json │ │ │ ├── collections_full.json │ │ │ ├── indexes_min.json │ │ │ └── indexes_full.json │ ├── synproxy │ │ ├── synproxy_notlinux.go │ │ └── synproxy.go │ ├── wireless │ │ ├── wireless_notlinux.go │ │ └── wireless.go │ ├── infiniband │ │ ├── infiniband_notlinux.go │ │ └── infiniband.go │ ├── linux_sysctl_fs │ │ └── README.md │ ├── webhooks │ │ ├── filestack │ │ │ ├── filestack_webhooks_events.go │ │ │ └── README.md │ │ └── mandrill │ │ │ ├── mandrill_webhooks_events.go │ │ │ └── README.md │ ├── jolokia2 │ │ ├── jolokia.go │ │ └── examples │ │ │ └── zookeeper.conf │ ├── suricata │ │ └── testdata │ │ │ ├── test3.json │ │ │ └── test2.json │ ├── kernel │ │ └── kernel_notlinux.go │ ├── snmp │ │ └── testdata │ │ │ └── snmpd.conf │ ├── knx_listener │ │ └── knx_dummy_interface.go │ ├── trig │ │ └── trig_test.go │ ├── kube_inventory │ │ └── client_test.go │ ├── exec │ │ └── dev │ │ │ └── telegraf.conf │ ├── puppetagent │ │ └── last_run_summary.yaml │ ├── sflow │ │ └── binaryio │ │ │ └── minreader_test.go │ ├── temp │ │ ├── temp_test.go │ │ └── README.md │ ├── swap │ │ ├── README.md │ │ └── swap_test.go │ └── csgo │ │ └── README.md ├── processors │ ├── printer │ │ ├── printer_test.go │ │ └── README.md │ ├── port_name │ │ ├── services_path_notwindows.go │ │ └── services_path.go │ ├── execd │ │ └── examples │ │ │ └── multiplier_line_protocol │ │ │ ├── multiplier.conf │ │ │ └── multiplier_line_protocol.rb │ ├── starlark │ │ └── testdata │ │ │ ├── drop_string_fields.star │ │ │ ├── time_set_timestamp.star │ │ │ ├── math.star │ │ │ ├── scale.star │ │ │ ├── fail.star │ │ │ ├── pivot.star │ │ │ ├── number_logic.star │ │ │ ├── ratio.star │ │ │ ├── logging.star │ │ │ ├── value_filter.star │ │ │ ├── json.star │ │ │ ├── time_duration.star │ │ │ ├── rename.star │ │ │ ├── rename_prometheus_remote_write.star │ │ │ ├── time_date.star │ │ │ ├── multiple_metrics.star │ │ │ └── time_timestamp.star │ ├── ifname │ │ ├── cache_test.go │ │ └── ttl_cache_test.go │ ├── template │ │ └── template_metric.go │ ├── dedup │ │ └── README.md │ ├── unpivot │ │ └── README.md │ ├── registry.go │ ├── pivot │ │ └── README.md │ ├── tag_limit │ │ └── README.md │ └── rename │ │ └── README.md ├── outputs │ ├── sql │ │ ├── testdata │ │ │ ├── postgres │ │ │ │ └── initdb │ │ │ │ │ └── init.sql │ │ │ └── mariadb │ │ │ │ └── initdb │ │ │ │ └── script.sql │ │ └── sqlite.go │ ├── nsq │ │ ├── README.md │ │ └── nsq_test.go │ ├── execd │ │ ├── examples │ │ │ ├── file │ │ │ │ ├── file.sh │ │ │ │ └── telegraf.conf │ │ │ └── redis │ │ │ │ ├── telegraf.conf │ │ │ │ ├── redis_influx.rb │ │ │ │ └── redis_json.rb │ │ └── README.md │ ├── registry.go │ ├── discard │ │ ├── README.md │ │ └── discard.go │ ├── application_insights │ │ ├── mocks │ │ │ ├── diagnostics_message_listener.go │ │ │ ├── transmitter.go │ │ │ └── diagnostics_message_subscriber.go │ │ ├── diagnostic_message_subscriber.go │ │ └── transmitter.go │ ├── health │ │ └── contains.go │ ├── amon │ │ └── README.md │ ├── riemann_legacy │ │ └── riemann_test.go │ ├── librato │ │ └── README.md │ ├── graylog │ │ └── README.md │ ├── mqtt │ │ └── mqtt_test.go │ ├── exec │ │ └── README.md │ ├── nats │ │ └── nats_test.go │ ├── signalfx │ │ └── README.md │ ├── yandex_cloud_monitoring │ │ └── README.md │ └── loki │ │ └── README.md ├── parsers │ ├── json_v2 │ │ └── testdata │ │ │ ├── measurement_name_int │ │ │ ├── expected.out │ │ │ ├── telegraf.conf │ │ │ └── input.json │ │ │ ├── array_of_objects │ │ │ ├── expected.out │ │ │ ├── input.json │ │ │ └── telegraf.conf │ │ │ ├── multiple_timestamps │ │ │ ├── expected.out │ │ │ ├── input.json │ │ │ └── telegraf.conf │ │ │ ├── fields_and_tags │ │ │ ├── expected.out │ │ │ └── telegraf.conf │ │ │ ├── nested_tags │ │ │ ├── expected.out │ │ │ ├── input.json │ │ │ └── telegraf.conf │ │ │ ├── fields_and_tags_complex │ │ │ ├── expected.out │ │ │ └── telegraf.conf │ │ │ ├── large_numbers │ │ │ ├── expected.out │ │ │ ├── input.json │ │ │ └── telegraf.conf │ │ │ ├── timestamp │ │ │ ├── expected.out │ │ │ ├── telegraf.conf │ │ │ └── input.json │ │ │ ├── nested_tags_complex │ │ │ ├── expected.out │ │ │ └── telegraf.conf │ │ │ ├── null │ │ │ ├── expected.out │ │ │ └── telegraf.conf │ │ │ ├── object │ │ │ ├── expected.out │ │ │ └── telegraf.conf │ │ │ ├── nested_array_of_objects │ │ │ ├── expected.out │ │ │ └── telegraf.conf │ │ │ ├── complex_nesting │ │ │ ├── telegraf.conf │ │ │ ├── expected.out │ │ │ └── input.json │ │ │ ├── multiple_arrays_in_object │ │ │ ├── telegraf.conf │ │ │ └── input.json │ │ │ ├── types │ │ │ ├── expected.out │ │ │ └── input.json │ │ │ └── nested_and_nonnested_tags │ │ │ ├── telegraf.conf │ │ │ └── expected.out │ ├── grok │ │ └── testdata │ │ │ ├── test_b.log │ │ │ ├── test_a.log │ │ │ └── test-patterns │ ├── xpath │ │ └── testcases │ │ │ ├── tracker.msg │ │ │ ├── addressbook.dat │ │ │ ├── multisensor_explicit_basic.conf │ │ │ ├── addressbook.proto │ │ │ ├── tracker_msgpack.conf │ │ │ ├── multisensor_selection_batch.conf │ │ │ ├── addressbook.conf │ │ │ └── multisensor.xml │ ├── nagios │ │ └── README.md │ ├── influx │ │ └── README.md │ ├── wavefront │ │ ├── README.md │ │ └── token.go │ ├── prometheus │ │ ├── README.md │ │ └── common │ │ │ └── helpers.go │ └── logfmt │ │ └── README.md ├── common │ ├── shim │ │ ├── testdata │ │ │ ├── processor.conf │ │ │ ├── special.conf │ │ │ └── plugin.conf │ │ └── example │ │ │ └── cmd │ │ │ └── plugin.conf │ ├── parallel │ │ └── parallel.go │ ├── proxy │ │ └── proxy.go │ ├── logrus │ │ └── hook.go │ ├── oauth │ │ └── config.go │ ├── kafka │ │ └── scram_client.go │ └── tls │ │ └── utils.go └── aggregators │ ├── registry.go │ ├── all │ └── all.go │ └── merge │ └── README.md ├── config ├── README.md └── testdata │ ├── wrong_field_type.toml │ ├── invalid_field.toml │ ├── wrong_field_type2.toml │ ├── subconfig │ ├── procstat.conf │ ├── exec.conf │ └── memcached.conf │ ├── slice_comment.toml │ ├── azure_monitor.toml │ ├── non_slice_slice.toml │ ├── special_types.toml │ ├── inline_table.toml │ ├── single_plugin.toml │ └── single_plugin_env_vars.toml ├── docs ├── developers │ ├── README.md │ └── CODE_STYLE.md ├── README.md ├── PROFILING.md └── METRICS.md ├── .lgtm.yml ├── assets └── icon.icns ├── .gitignore ├── .gitattributes ├── etc └── logrotate.d │ └── telegraf ├── cmd └── telegraf │ └── telegraf_posix.go ├── agent ├── agent_windows.go └── agent_posix.go ├── .github ├── dependabot.yml ├── ISSUE_TEMPLATE │ ├── Feature_request.md │ └── Support.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── golangci-lint.yml ├── info.plist ├── models ├── log_test.go └── makemetric.go ├── aggregator.go ├── metric └── series_grouper_test.go ├── testutil ├── pki │ ├── cacert.pem │ ├── clientcert.pem │ ├── servercert.pem │ ├── clientkey.pem │ ├── serverkey.pem │ └── cakey.pem └── testutil_test.go ├── input.go └── selfstat └── stat.go /scripts/build.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /internal/globpath/testdata/log1.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /internal/globpath/testdata/log2.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /internal/globpath/testdata/log[!.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /plugins/inputs/filecount/testdata/bar: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /plugins/inputs/filecount/testdata/baz: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /plugins/inputs/filecount/testdata/foo: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/README.md: -------------------------------------------------------------------------------- 1 | ../docs/CONFIGURATION.md -------------------------------------------------------------------------------- /plugins/inputs/filestat/testdata/log1.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /plugins/inputs/filestat/testdata/log2.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/developers/README.md: -------------------------------------------------------------------------------- 1 | ../../CONTRIBUTING.md -------------------------------------------------------------------------------- /plugins/inputs/filecount/testdata/subdir/quux: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /plugins/inputs/filecount/testdata/subdir/quuz: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /internal/globpath/testdata/nested1/nested2/nested.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/memory.empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /plugins/inputs/multifile/testdata/bool.txt: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /plugins/inputs/multifile/testdata/int.txt: -------------------------------------------------------------------------------- 1 | 123456 2 | -------------------------------------------------------------------------------- /plugins/inputs/multifile/testdata/tag.txt: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/cpu/cpu.cfs_quota_us: -------------------------------------------------------------------------------- 1 | -1 2 | -------------------------------------------------------------------------------- /plugins/inputs/multifile/testdata/float.txt: -------------------------------------------------------------------------------- 1 | 123.456 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/notify_on_release: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /plugins/inputs/multifile/testdata/string.txt: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /plugins/processors/printer/printer_test.go: -------------------------------------------------------------------------------- 1 | package printer 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/blkio/blkio.io_serviced: -------------------------------------------------------------------------------- 1 | Total 0 2 | -------------------------------------------------------------------------------- /.lgtm.yml: -------------------------------------------------------------------------------- 1 | queries: 2 | - exclude: go/disabled-certificate-check 3 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/memory.use_hierarchy: -------------------------------------------------------------------------------- 1 | 12-781 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/memory.usage_in_bytes: -------------------------------------------------------------------------------- 1 | 3513667584 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_1/memory.kmem.max_usage_in_bytes: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/memory.limit_in_bytes: -------------------------------------------------------------------------------- 1 | 223372036854771712 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/memory.max_usage_in_bytes: -------------------------------------------------------------------------------- 1 | 0 2 | -1 3 | 2 4 | -------------------------------------------------------------------------------- /plugins/inputs/dpdk/dpdk_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package dpdk 4 | -------------------------------------------------------------------------------- /plugins/inputs/ipvs/ipvs_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package ipvs 4 | -------------------------------------------------------------------------------- /plugins/outputs/sql/testdata/postgres/initdb/init.sql: -------------------------------------------------------------------------------- 1 | create database foo; 2 | 3 | -------------------------------------------------------------------------------- /assets/icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/assets/icon.icns -------------------------------------------------------------------------------- /config/testdata/wrong_field_type.toml: -------------------------------------------------------------------------------- 1 | [[inputs.http_listener_v2]] 2 | port = "80" 3 | -------------------------------------------------------------------------------- /plugins/inputs/bcache/bcache_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package bcache 4 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/memory.kmem.limit_in_bytes: -------------------------------------------------------------------------------- 1 | 9223372036854771712 2 | -------------------------------------------------------------------------------- /plugins/inputs/lustre2/lustre2_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package lustre2 4 | -------------------------------------------------------------------------------- /plugins/inputs/nats/nats_freebsd.go: -------------------------------------------------------------------------------- 1 | // +build freebsd,!cgo 2 | 3 | package nats 4 | -------------------------------------------------------------------------------- /plugins/inputs/postfix/postfix_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package postfix 4 | -------------------------------------------------------------------------------- /plugins/inputs/postgresql_extensible/testdata/test.sql: -------------------------------------------------------------------------------- 1 | select * from pg_stat_database -------------------------------------------------------------------------------- /plugins/inputs/sensors/sensors_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package sensors 4 | -------------------------------------------------------------------------------- /plugins/inputs/sysstat/sysstat_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package sysstat 4 | -------------------------------------------------------------------------------- /plugins/inputs/varnish/varnish_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package varnish 4 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/measurement_name_int/expected.out: -------------------------------------------------------------------------------- 1 | 32 label="Basic" 2 | -------------------------------------------------------------------------------- /config/testdata/invalid_field.toml: -------------------------------------------------------------------------------- 1 | [[inputs.http_listener_v2]] 2 | not_a_field = true 3 | -------------------------------------------------------------------------------- /config/testdata/wrong_field_type2.toml: -------------------------------------------------------------------------------- 1 | [[inputs.http_listener_v2]] 2 | methods = "POST" 3 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_1/memory.limit_in_bytes: -------------------------------------------------------------------------------- 1 | 223372036854771712 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_2/memory.limit_in_bytes: -------------------------------------------------------------------------------- 1 | 223372036854771712 2 | -------------------------------------------------------------------------------- /plugins/inputs/iptables/iptables_nocompile.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package iptables 4 | -------------------------------------------------------------------------------- /plugins/common/shim/testdata/processor.conf: -------------------------------------------------------------------------------- 1 | [[processors.test_config_load]] 2 | loaded = "yep" -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_1/memory.kmem.limit_in_bytes: -------------------------------------------------------------------------------- 1 | 9223372036854771712 2 | -------------------------------------------------------------------------------- /plugins/inputs/conntrack/conntrack_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package conntrack 4 | -------------------------------------------------------------------------------- /plugins/inputs/intel_rdt/intel_rdt_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package intel_rdt 4 | -------------------------------------------------------------------------------- /plugins/inputs/logparser/logparser_solaris.go: -------------------------------------------------------------------------------- 1 | // +build solaris 2 | 3 | package logparser 4 | -------------------------------------------------------------------------------- /plugins/inputs/logparser/testdata/test_c.log: -------------------------------------------------------------------------------- 1 | 1568723594631 1.25 200 192.168.1.1 5.432µs 101 2 | -------------------------------------------------------------------------------- /plugins/common/shim/example/cmd/plugin.conf: -------------------------------------------------------------------------------- 1 | [[inputs.my_plugin_name]] 2 | value_name = "value" 3 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_1/group_1_1/memory.limit_in_bytes: -------------------------------------------------------------------------------- 1 | 223372036854771712 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_1/group_1_2/memory.limit_in_bytes: -------------------------------------------------------------------------------- 1 | 223372036854771712 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_2/group_1_1/memory.limit_in_bytes: -------------------------------------------------------------------------------- 1 | 223372036854771712 2 | -------------------------------------------------------------------------------- /plugins/inputs/logparser/testdata/test_b.log: -------------------------------------------------------------------------------- 1 | [04/06/2016--12:41:45] 1.25 mystring dropme nomodifier 2 | -------------------------------------------------------------------------------- /plugins/parsers/grok/testdata/test_b.log: -------------------------------------------------------------------------------- 1 | [04/06/2016--12:41:45] 1.25 mystring dropme nomodifier 2 | -------------------------------------------------------------------------------- /plugins/inputs/execd/shim/example/cmd/plugin.conf: -------------------------------------------------------------------------------- 1 | [[inputs.my_plugin_name]] 2 | value_name = "value" 3 | -------------------------------------------------------------------------------- /plugins/inputs/kernel_vmstat/kernel_vmstat_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package kernel_vmstat 4 | -------------------------------------------------------------------------------- /plugins/inputs/ras/ras_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux linux,!386,!amd64,!arm,!arm64 2 | 3 | package ras 4 | -------------------------------------------------------------------------------- /plugins/inputs/systemd_units/systemd_units_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package systemd_units 4 | -------------------------------------------------------------------------------- /plugins/inputs/win_services/win_services_notwindows.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package win_services 4 | -------------------------------------------------------------------------------- /plugins/parsers/grok/testdata/test_a.log: -------------------------------------------------------------------------------- 1 | [04/Jun/2016:12:41:45 +0100] 1.25 200 192.168.1.1 5.432µs 101 2 | -------------------------------------------------------------------------------- /config/testdata/subconfig/procstat.conf: -------------------------------------------------------------------------------- 1 | [[inputs.procstat]] 2 | pid_file = "/var/run/grafana-server.pid" 3 | -------------------------------------------------------------------------------- /plugins/inputs/intel_powerstat/intel_powerstat_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package intel_powerstat 4 | -------------------------------------------------------------------------------- /plugins/inputs/logparser/testdata/test_a.log: -------------------------------------------------------------------------------- 1 | [04/Jun/2016:12:41:45 +0100] 1.25 200 192.168.1.1 5.432µs 101 2 | -------------------------------------------------------------------------------- /plugins/inputs/rabbitmq/testdata/set2/federation-links.json: -------------------------------------------------------------------------------- 1 | {"error":"Object Not Found","reason":"Not Found"} 2 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/cpu/cpuacct.usage_percpu: -------------------------------------------------------------------------------- 1 | -1452543795404 1376681271659 1450950799997 -1473113374257 2 | -------------------------------------------------------------------------------- /config/testdata/slice_comment.toml: -------------------------------------------------------------------------------- 1 | [[outputs.http]] 2 | scopes = [ 3 | # comment 4 | "test" # comment 5 | ] 6 | -------------------------------------------------------------------------------- /plugins/inputs/win_perf_counters/win_perf_counters_notwindows.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package win_perf_counters 4 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/array_of_objects/expected.out: -------------------------------------------------------------------------------- 1 | file properties_mag=5.17 2 | file properties_mag=6.2 3 | -------------------------------------------------------------------------------- /config/testdata/azure_monitor.toml: -------------------------------------------------------------------------------- 1 | [[outputs.azure_monitor]] 2 | 3 | [[outputs.azure_monitor]] 4 | namespace_prefix = "" 5 | -------------------------------------------------------------------------------- /plugins/inputs/execd/shim/example/cmd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // see /plugins/common/shim/example/cmd/main.go instead. 4 | -------------------------------------------------------------------------------- /plugins/common/shim/testdata/special.conf: -------------------------------------------------------------------------------- 1 | # testing custom field types 2 | [[inputs.test]] 3 | duration = "3s" 4 | size = "3MB" -------------------------------------------------------------------------------- /plugins/parsers/xpath/testcases/tracker.msg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/parsers/xpath/testcases/tracker.msg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /build 3 | /telegraf 4 | /telegraf.exe 5 | /telegraf.gz 6 | /vendor 7 | .DS_Store 8 | process.yml 9 | /.vscode 10 | -------------------------------------------------------------------------------- /plugins/inputs/file/testdata/mtr-utf-16be.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/file/testdata/mtr-utf-16be.csv -------------------------------------------------------------------------------- /plugins/inputs/file/testdata/mtr-utf-16le.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/file/testdata/mtr-utf-16le.csv -------------------------------------------------------------------------------- /plugins/inputs/tail/tail_solaris.go: -------------------------------------------------------------------------------- 1 | // Skipping plugin on Solaris due to fsnotify support 2 | // 3 | // +build solaris 4 | 5 | package tail 6 | -------------------------------------------------------------------------------- /plugins/inputs/zipkin/testdata/threespans.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/zipkin/testdata/threespans.dat -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/multiple_timestamps/expected.out: -------------------------------------------------------------------------------- 1 | file name="fire" 1555745371450794118 2 | file name="flood" 1555745371450794118 3 | -------------------------------------------------------------------------------- /plugins/inputs/tail/testdata/cpu-utf-16be.influx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/tail/testdata/cpu-utf-16be.influx -------------------------------------------------------------------------------- /plugins/inputs/tail/testdata/cpu-utf-16le.influx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/tail/testdata/cpu-utf-16le.influx -------------------------------------------------------------------------------- /plugins/parsers/xpath/testcases/addressbook.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/parsers/xpath/testcases/addressbook.dat -------------------------------------------------------------------------------- /scripts/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [ "${1:0:1}" = '-' ]; then 5 | set -- telegraf "$@" 6 | fi 7 | 8 | exec "$@" 9 | -------------------------------------------------------------------------------- /config/testdata/non_slice_slice.toml: -------------------------------------------------------------------------------- 1 | [[outputs.http]] 2 | [outputs.http.headers] 3 | Content-Type = "application/json" 4 | taginclude = ["org_id"] 5 | -------------------------------------------------------------------------------- /plugins/inputs/clickhouse/dev/tls_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 8443 3 | 9440 4 | 5 | -------------------------------------------------------------------------------- /plugins/inputs/zipkin/testdata/cli_microservice.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/zipkin/testdata/cli_microservice.dat -------------------------------------------------------------------------------- /internal/globpath/testdata/test.conf: -------------------------------------------------------------------------------- 1 | # this is a fake testing config file 2 | # for testing the filestat plugin 3 | 4 | option1 = "foo" 5 | option2 = "bar" 6 | -------------------------------------------------------------------------------- /plugins/inputs/http_listener_v2/testdata/testmsgs.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/http_listener_v2/testdata/testmsgs.gz -------------------------------------------------------------------------------- /plugins/inputs/influxdb_listener/testdata/testmsgs.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/influxdb_listener/testdata/testmsgs.gz -------------------------------------------------------------------------------- /plugins/outputs/sql/testdata/mariadb/initdb/script.sql: -------------------------------------------------------------------------------- 1 | create database foo; 2 | use foo; 3 | create table bar (baz int); 4 | insert into bar (baz) values (1); 5 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/fields_and_tags/expected.out: -------------------------------------------------------------------------------- 1 | file,status=200 duration=2i,json_duration=100 2 | file,status=200 duration=2i,json_duration=60 3 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/memory.stat: -------------------------------------------------------------------------------- 1 | cache 1739362304123123123 2 | rss 1775325184 3 | rss_huge 778043392 4 | mapped_file 421036032 5 | dirty -307200 6 | -------------------------------------------------------------------------------- /plugins/inputs/filestat/testdata/test.conf: -------------------------------------------------------------------------------- 1 | # this is a fake testing config file 2 | # for testing the filestat plugin 3 | 4 | option1 = "foo" 5 | option2 = "bar" 6 | -------------------------------------------------------------------------------- /plugins/inputs/influxdb_v2_listener/testdata/testmsgs.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/influxdb_v2_listener/testdata/testmsgs.gz -------------------------------------------------------------------------------- /plugins/common/shim/testdata/plugin.conf: -------------------------------------------------------------------------------- 1 | [[inputs.test]] 2 | service_name = "awesome name" 3 | secret_token = "${SECRET_TOKEN}" 4 | secret_value = "$SECRET_VALUE" 5 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_1/memory.stat: -------------------------------------------------------------------------------- 1 | cache 1739362304123123123 2 | rss 1775325184 3 | rss_huge 778043392 4 | mapped_file 421036032 5 | dirty -307200 6 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_2/memory.stat: -------------------------------------------------------------------------------- 1 | cache 1739362304123123123 2 | rss 1775325184 3 | rss_huge 778043392 4 | mapped_file 421036032 5 | dirty -307200 6 | -------------------------------------------------------------------------------- /plugins/inputs/sql/drivers_sqlite.go: -------------------------------------------------------------------------------- 1 | // +build linux,freebsd,darwin 2 | // +build !mips !mips64 3 | 4 | package sql 5 | 6 | import ( 7 | _ "modernc.org/sqlite" 8 | ) 9 | -------------------------------------------------------------------------------- /plugins/inputs/zipkin/testdata/distributed_trace_sample.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Semporia/Telegraf/master/plugins/inputs/zipkin/testdata/distributed_trace_sample.dat -------------------------------------------------------------------------------- /config/testdata/subconfig/exec.conf: -------------------------------------------------------------------------------- 1 | [[inputs.exec]] 2 | # the command to run 3 | command = "/usr/bin/myothercollector --foo=bar" 4 | name_suffix = "_myothercollector" 5 | -------------------------------------------------------------------------------- /plugins/inputs/execd/shim/testdata/plugin.conf: -------------------------------------------------------------------------------- 1 | [[inputs.test]] 2 | service_name = "awesome name" 3 | secret_token = "${SECRET_TOKEN}" 4 | secret_value = "$SECRET_VALUE" 5 | -------------------------------------------------------------------------------- /plugins/processors/port_name/services_path_notwindows.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package portname 4 | 5 | func servicesPath() string { 6 | return "/etc/services" 7 | } 8 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_1/group_1_1/memory.stat: -------------------------------------------------------------------------------- 1 | cache 1739362304123123123 2 | rss 1775325184 3 | rss_huge 778043392 4 | mapped_file 421036032 5 | dirty -307200 6 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_1/group_1_2/memory.stat: -------------------------------------------------------------------------------- 1 | cache 1739362304123123123 2 | rss 1775325184 3 | rss_huge 778043392 4 | mapped_file 421036032 5 | dirty -307200 6 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/group_2/group_1_1/memory.stat: -------------------------------------------------------------------------------- 1 | cache 1739362304123123123 2 | rss 1775325184 3 | rss_huge 778043392 4 | mapped_file 421036032 5 | dirty -307200 6 | -------------------------------------------------------------------------------- /plugins/inputs/x509_cert/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | [[inputs.x509_cert]] 2 | sources = ["https://expired.badssl.com:443", "https://wrong.host.badssl.com:443"] 3 | 4 | [[outputs.file]] 5 | -------------------------------------------------------------------------------- /plugins/common/parallel/parallel.go: -------------------------------------------------------------------------------- 1 | package parallel 2 | 3 | import "github.com/influxdata/telegraf" 4 | 5 | type Parallel interface { 6 | Enqueue(telegraf.Metric) 7 | Stop() 8 | } 9 | -------------------------------------------------------------------------------- /scripts/local_circleci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | jobName=$1 4 | 5 | circleci config process .circleci/config.yml > process.yml 6 | circleci local execute -c process.yml --job $jobName 7 | -------------------------------------------------------------------------------- /plugins/outputs/nsq/README.md: -------------------------------------------------------------------------------- 1 | # NSQ Output Plugin 2 | 3 | This plugin writes to a specified NSQD instance, usually local to the producer. It requires 4 | a `server` name and a `topic` name. -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | CHANGELOG.md merge=union 2 | README.md merge=union 3 | go.sum merge=union 4 | plugins/inputs/all/all.go merge=union 5 | plugins/outputs/all/all.go merge=union 6 | **/testdata/** test eol=lf 7 | -------------------------------------------------------------------------------- /plugins/inputs/file/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | [[inputs.file]] 2 | files = ["/var/log/test.log"] 3 | data_format = "json" 4 | name_override = "json_file" 5 | 6 | [[outputs.file]] 7 | files = ["stdout"] 8 | -------------------------------------------------------------------------------- /plugins/inputs/kibana/test_environment/run_test_env.sh: -------------------------------------------------------------------------------- 1 | docker build -t local_telegraf -f scripts/alpine.docker . 2 | 3 | docker-compose -f plugins/inputs/kibana/test_environment/docker-compose.yml up 4 | -------------------------------------------------------------------------------- /etc/logrotate.d/telegraf: -------------------------------------------------------------------------------- 1 | /var/log/telegraf/telegraf.log 2 | { 3 | rotate 6 4 | daily 5 | missingok 6 | dateext 7 | copytruncate 8 | notifempty 9 | compress 10 | } 11 | 12 | -------------------------------------------------------------------------------- /plugins/inputs/beat/beat6_info.json: -------------------------------------------------------------------------------- 1 | { 2 | "beat": "filebeat", 3 | "hostname": "node-6", 4 | "name": "node-6-test", 5 | "uuid": "9c1c8697-acb4-4df0-987d-28197814f785", 6 | "version": "6.4.2" 7 | } 8 | -------------------------------------------------------------------------------- /plugins/inputs/procstat/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | interval="1s" 3 | flush_interval="1s" 4 | 5 | [[inputs.procstat]] 6 | exe = "telegraf" 7 | 8 | [[outputs.file]] 9 | files = ["stdout"] 10 | -------------------------------------------------------------------------------- /plugins/inputs/redfish/testdata/hp_chassis.json: -------------------------------------------------------------------------------- 1 | { 2 | "Power": { 3 | "@odata.id": "/redfish/v1/Chassis/1/Power" 4 | }, 5 | "Thermal": { 6 | "@odata.id": "/redfish/v1/Chassis/1/Thermal" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /plugins/inputs/zookeeper/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | interval="1s" 3 | flush_interval="1s" 4 | 5 | [[inputs.zookeeper]] 6 | servers = [":2181"] 7 | 8 | [[outputs.file]] 9 | files = ["stdout"] 10 | -------------------------------------------------------------------------------- /plugins/inputs/execd/shim/README.md: -------------------------------------------------------------------------------- 1 | # Telegraf Execd Go Shim 2 | 3 | This is deprecated. Please see [/plugins/common/shim/README.md](https://github.com/influxdata/telegraf/tree/master/plugins/common/shim/README.md) 4 | -------------------------------------------------------------------------------- /plugins/inputs/win_eventlog/win_eventlog_notwindows.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | //revive:disable-next-line:var-naming 4 | // Package win_eventlog Input plugin to collect Windows Event Log messages 5 | package win_eventlog 6 | -------------------------------------------------------------------------------- /config/testdata/special_types.toml: -------------------------------------------------------------------------------- 1 | [[inputs.http_listener_v2]] 2 | write_timeout = "1s" 3 | max_body_size = "1MiB" 4 | tls_cert = """ 5 | /path/to/my/cert 6 | """ 7 | tls_key = ''' 8 | /path/to/my/key 9 | ''' 10 | -------------------------------------------------------------------------------- /internal/goplugin/noplugin.go: -------------------------------------------------------------------------------- 1 | // +build !goplugin 2 | 3 | package goplugin 4 | 5 | import "errors" 6 | 7 | func LoadExternalPlugins(_ string) error { 8 | return errors.New("go plugin support is not enabled") 9 | } 10 | -------------------------------------------------------------------------------- /plugins/inputs/mongodb/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | interval="1s" 3 | flush_interval="3s" 4 | 5 | [[inputs.mongodb]] 6 | servers = ["mongodb://mongodb:27017"] 7 | 8 | [[outputs.file]] 9 | files = ["stdout"] 10 | -------------------------------------------------------------------------------- /plugins/outputs/execd/examples/file/file.sh: -------------------------------------------------------------------------------- 1 | # Usage: sh file.sh output_filename.ext 2 | # reads from stdin and writes out to a file named on the command line. 3 | while read line; do 4 | echo "$line" >> $1 5 | done < /dev/stdin 6 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/nested_tags/expected.out: -------------------------------------------------------------------------------- 1 | file,Firmware=LDGSW07G,Model=WDC\ WUH721414ALE604,Serial=9JHNGTUT Count=0,Errors=0 2 | file,Firmware=LDGSW07G,Model=WDC\ WUH721414ALE604,Serial=9JHLPW9T Errors=0,Count=0 3 | -------------------------------------------------------------------------------- /plugins/inputs/diskio/diskio_other.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package diskio 4 | 5 | type diskInfoCache struct{} 6 | 7 | func (d *DiskIO) diskInfo(devName string) (map[string]string, error) { 8 | return nil, nil 9 | } 10 | -------------------------------------------------------------------------------- /plugins/inputs/sql/drivers.go: -------------------------------------------------------------------------------- 1 | package sql 2 | 3 | import ( 4 | // Blank imports to register the drivers 5 | _ "github.com/denisenkom/go-mssqldb" 6 | _ "github.com/go-sql-driver/mysql" 7 | _ "github.com/jackc/pgx/v4/stdlib" 8 | ) 9 | -------------------------------------------------------------------------------- /plugins/inputs/tail/testdata/test-patterns: -------------------------------------------------------------------------------- 1 | # Test multiline 2 | # [04/Jun/2016:12:41:45 +0100] DEBUG HelloExample: This is debug 3 | TEST_LOG_MULTILINE \[%{HTTPDATE:timestamp:ts-httpd}\] %{WORD:loglevel:tag} %{GREEDYDATA:message} 4 | -------------------------------------------------------------------------------- /cmd/telegraf/telegraf_posix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package main 4 | 5 | func run(inputFilters, outputFilters []string) { 6 | stop = make(chan struct{}) 7 | reloadLoop( 8 | inputFilters, 9 | outputFilters, 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/cgroup_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package cgroup 4 | 5 | import ( 6 | "github.com/influxdata/telegraf" 7 | ) 8 | 9 | func (g *CGroup) Gather(acc telegraf.Accumulator) error { 10 | return nil 11 | } 12 | -------------------------------------------------------------------------------- /plugins/inputs/file/dev/testfiles/grok_a.log: -------------------------------------------------------------------------------- 1 | 127.0.0.1 user-identifier frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 2 | 128.0.0.1 user-identifier tony [10/Oct/2000:13:55:36 -0800] "GET /apache_pb.gif HTTP/1.0" 300 45 -------------------------------------------------------------------------------- /plugins/inputs/processes/processes.go: -------------------------------------------------------------------------------- 1 | package processes 2 | 3 | func (p *Processes) Description() string { 4 | return "Get the number of processes and group them by status" 5 | } 6 | 7 | func (p *Processes) SampleConfig() string { return "" } 8 | -------------------------------------------------------------------------------- /scripts/deb/pre-remove.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BIN_DIR=/usr/bin 4 | 5 | if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then 6 | deb-systemd-invoke stop telegraf.service 7 | else 8 | # Assuming sysv 9 | invoke-rc.d telegraf stop 10 | fi 11 | -------------------------------------------------------------------------------- /plugins/inputs/postfix/stat_none.go: -------------------------------------------------------------------------------- 1 | // +build !dragonfly,!linux,!netbsd,!openbsd,!solaris,!darwin,!freebsd 2 | 3 | package postfix 4 | 5 | import ( 6 | "time" 7 | ) 8 | 9 | func statCTime(_ interface{}) time.Time { 10 | return time.Time{} 11 | } 12 | -------------------------------------------------------------------------------- /plugins/inputs/burrow/testdata/v3_kafka.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": false, 3 | "message": "cluster list returned", 4 | "clusters": [ 5 | "clustername1" 6 | ], 7 | "request": { 8 | "url": "/v3/kafka", 9 | "host": "example.com" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/inputs/registry.go: -------------------------------------------------------------------------------- 1 | package inputs 2 | 3 | import "github.com/influxdata/telegraf" 4 | 5 | type Creator func() telegraf.Input 6 | 7 | var Inputs = map[string]Creator{} 8 | 9 | func Add(name string, creator Creator) { 10 | Inputs[name] = creator 11 | } 12 | -------------------------------------------------------------------------------- /plugins/inputs/couchdb/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | interval="1s" 3 | flush_interval="1s" 4 | 5 | [[inputs.couchdb]] 6 | hosts = ["http://couchdb16:5984/_stats", "http://couchdb22:5984/_node/_local/_stats"] 7 | 8 | [[outputs.file]] 9 | files = ["stdout"] 10 | -------------------------------------------------------------------------------- /plugins/inputs/execd/examples/count.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ## Example in bash using STDIN signaling 4 | 5 | counter=0 6 | 7 | while read LINE; do 8 | echo "counter_bash count=${counter}" 9 | counter=$((counter+1)) 10 | done 11 | 12 | trap "echo terminate 1>&2" EXIT -------------------------------------------------------------------------------- /plugins/inputs/procstat/win_service_notwindows.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package procstat 4 | 5 | import ( 6 | "fmt" 7 | ) 8 | 9 | func queryPidWithWinServiceName(_ string) (uint32, error) { 10 | return 0, fmt.Errorf("os not support win_service option") 11 | } 12 | -------------------------------------------------------------------------------- /plugins/inputs/tcp_listener/README.md: -------------------------------------------------------------------------------- 1 | # TCP Listener Input Plugin 2 | 3 | > DEPRECATED: As of version 1.3 the TCP listener plugin has been deprecated in favor of the 4 | > [socket_listener plugin](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/socket_listener) 5 | -------------------------------------------------------------------------------- /plugins/inputs/udp_listener/README.md: -------------------------------------------------------------------------------- 1 | # UDP Listener Input Plugin 2 | 3 | > DEPRECATED: As of version 1.3 the UDP listener plugin has been deprecated in favor of the 4 | > [socket_listener plugin](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/socket_listener) 5 | -------------------------------------------------------------------------------- /plugins/processors/port_name/services_path.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package portname 4 | 5 | import ( 6 | "os" 7 | "path/filepath" 8 | ) 9 | 10 | func servicesPath() string { 11 | return filepath.Join(os.Getenv("WINDIR"), `system32\drivers\etc\services`) 12 | } 13 | -------------------------------------------------------------------------------- /plugins/inputs/burrow/testdata/v3_kafka_clustername1_topic.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": false, 3 | "message": "topic list returned", 4 | "topics": [ 5 | "topicA" 6 | ], 7 | "request": { 8 | "url": "/v3/kafka/clustername1/topic", 9 | "host": "example.com" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/outputs/registry.go: -------------------------------------------------------------------------------- 1 | package outputs 2 | 3 | import ( 4 | "github.com/influxdata/telegraf" 5 | ) 6 | 7 | type Creator func() telegraf.Output 8 | 9 | var Outputs = map[string]Creator{} 10 | 11 | func Add(name string, creator Creator) { 12 | Outputs[name] = creator 13 | } 14 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/fields_and_tags_complex/expected.out: -------------------------------------------------------------------------------- 1 | bart_json_v2,name=Powell\ St. minutes=9i 2 | bart_json_v2,name=Powell\ St. minutes=40i 3 | bart_json_v2,name=Powell\ St. minutes=70i 4 | bart_json_v2,name=Powell\ St. minutes=12i 5 | bart_json_v2,name=Powell\ St. minutes=42i 6 | -------------------------------------------------------------------------------- /agent/agent_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package agent 4 | 5 | import "os" 6 | 7 | func watchForFlushSignal(flushRequested chan os.Signal) { 8 | // not supported 9 | } 10 | 11 | func stopListeningForFlushSignal(flushRequested chan os.Signal) { 12 | // not supported 13 | } 14 | -------------------------------------------------------------------------------- /plugins/aggregators/registry.go: -------------------------------------------------------------------------------- 1 | package aggregators 2 | 3 | import "github.com/influxdata/telegraf" 4 | 5 | type Creator func() telegraf.Aggregator 6 | 7 | var Aggregators = map[string]Creator{} 8 | 9 | func Add(name string, creator Creator) { 10 | Aggregators[name] = creator 11 | } 12 | -------------------------------------------------------------------------------- /plugins/inputs/burrow/testdata/error.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": true, 3 | "message": "Detailed error message", 4 | "request": { 5 | "uri": "/invalid/request", 6 | "host": "responding.host.example.com", 7 | "cluster": "", 8 | "group": "", 9 | "topic": "" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/inputs/logparser/dev/test.log: -------------------------------------------------------------------------------- 1 | 127.0.0.1 ident auth [10/Oct/2000:13:55:36 -0700] "GET /anything HTTP/1.0" 200 2326 "http://localhost:8083/" "Chrome/51.0.2704.84" 2 | 127.0.0.1 ident auth [2018-02-21 13:10:34,555] "GET /peter HTTP/1.0" 200 2326 "http://localhost:8083/" "Chrome/51.0.2704.84" 3 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/large_numbers/expected.out: -------------------------------------------------------------------------------- 1 | file large=4294967296i,larger=9007199254740991i,largest=9223372036854775807i 2 | file large=9007199254740991u,larger=9223372036854775807u,largest=18446744073709551615u 3 | file large=4294967296,larger=4.294967296663e+09,largest=9007199254740991 4 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/timestamp/expected.out: -------------------------------------------------------------------------------- 1 | file,name=temperature,units=℃ value=23.4 1555745371450794118 2 | file,name=moisture,units=% value=5 1555745371450794118 3 | file,name=light,units=lux value=10118 1555745371450794118 4 | file,name=fertility,units=us/cm value=0 1555745371450794118 5 | -------------------------------------------------------------------------------- /plugins/inputs/burrow/testdata/v3_kafka_clustername1_consumer.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": false, 3 | "message": "consumer list returned", 4 | "consumers": [ 5 | "group1" 6 | ], 7 | "request": { 8 | "url": "/v3/kafka/clustername1/consumer", 9 | "host": "example.com" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/outputs/execd/examples/file/telegraf.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | interval = "1s" 3 | 4 | [[inputs.execd]] 5 | command = ["ruby", "plugins/inputs/execd/examples/count.rb"] 6 | 7 | [[outputs.execd]] 8 | command = ["sh", "plugins/outputs/execd/examples/file/file.sh"] 9 | data_format = "json" 10 | -------------------------------------------------------------------------------- /config/testdata/inline_table.toml: -------------------------------------------------------------------------------- 1 | [[outputs.http]] 2 | headers = { Authorization = "Token $TOKEN",Content-Type = "application/json" } 3 | taginclude = ["org_id"] 4 | 5 | [[outputs.http]] 6 | headers = { Authorization = "Token $TOKEN",Content-Type = "application/json" } 7 | taginclude = ["org_id"] 8 | -------------------------------------------------------------------------------- /plugins/inputs/cgroup/testdata/memory/memory.numa_stat: -------------------------------------------------------------------------------- 1 | total=858067 N0=858067 2 | file=406254 N0=406254 3 | anon=451792 N0=451792 4 | unevictable=21 N0=21 5 | hierarchical_total=858067 N0=858067 6 | hierarchical_file=406254 N0=406254 7 | hierarchical_anon=451792 N0=451792 8 | hierarchical_unevictable=21 N0=21 9 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/multiple_timestamps/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "events": [ 3 | { 4 | "name": "fire", 5 | "time": "1555745371410" 6 | }, 7 | { 8 | "name": "flood", 9 | "time": "1555745371410" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /plugins/inputs/docker/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | interval="1s" 3 | flush_interval="1s" 4 | 5 | [[inputs.docker]] 6 | endpoint = "unix:///var/run/docker.sock" 7 | timeout = "5s" 8 | perdevice = true 9 | total = false 10 | container_names = [] 11 | 12 | [[outputs.file]] 13 | files = ["stdout"] 14 | -------------------------------------------------------------------------------- /plugins/inputs/tail/testdata/cpu-utf-8.influx: -------------------------------------------------------------------------------- 1 | cpu,cpu=cpu0 usage_active=11.9 1594084375000000000 2 | cpu,cpu=cpu1 usage_active=26.0 1594084375000000000 3 | cpu,cpu=cpu2 usage_active=14.0 1594084375000000000 4 | cpu,cpu=cpu3 usage_active=20.4 1594084375000000000 5 | cpu,cpu=cpu-total usage_active=18.4 1594084375000000000 6 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/nested_tags_complex/expected.out: -------------------------------------------------------------------------------- 1 | file,Firmware=LDGSW07G,Model=WDC\ WUH721414ALE604,Serial=9JHNGTUT Count=0,Errors=0 2 | file,Firmware=LDGSW07G,Model=WDC\ WUH721414ALE604,Serial=9JHNGHJBT Errors=0,Count=2 3 | file,Firmware=LDGSW07G,Model=WDC\ WUH721414ALE604,Serial=9JHLPW9T Errors=0,Count=0 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "gomod" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | ignore: 8 | # Dependabot isn't able to update this packages that do not match the source, so anything with a version 9 | - dependency-name: "*.v*" 10 | -------------------------------------------------------------------------------- /plugins/inputs/dmcache/dmcache_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package dmcache 4 | 5 | import ( 6 | "github.com/influxdata/telegraf" 7 | ) 8 | 9 | func (c *DMCache) Gather(acc telegraf.Accumulator) error { 10 | return nil 11 | } 12 | 13 | func dmSetupStatus() ([]string, error) { 14 | return []string{}, nil 15 | } 16 | -------------------------------------------------------------------------------- /plugins/outputs/discard/README.md: -------------------------------------------------------------------------------- 1 | # discard Output Plugin 2 | 3 | This output plugin simply drops all metrics that are sent to it. It is only 4 | meant to be used for testing purposes. 5 | 6 | ### Configuration: 7 | 8 | ```toml 9 | # Send metrics to nowhere at all 10 | [[outputs.discard]] 11 | # no configuration 12 | ``` 13 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/array_of_objects/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | { 4 | "properties": { 5 | "mag": 5.17 6 | } 7 | }, 8 | { 9 | "properties": { 10 | "mag": 6.2 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /internal/templating/template_test.go: -------------------------------------------------------------------------------- 1 | package templating 2 | 3 | import "testing" 4 | 5 | func BenchmarkTemplateLess(b *testing.B) { 6 | a := templateSpec{ 7 | template: "aa|bb|cc|dd|ee|ff", 8 | separator: "|", 9 | } 10 | specs := templateSpecs{a, a} 11 | for i := 0; i < b.N; i++ { 12 | specs.Less(0, 1) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /plugins/inputs/file/dev/testfiles/json_a.log: -------------------------------------------------------------------------------- 1 | { 2 | "parent": { 3 | "child": 3.0, 4 | "ignored_child": "hi" 5 | }, 6 | "ignored_null": null, 7 | "integer": 4, 8 | "list": [3, 4], 9 | "ignored_parent": { 10 | "another_ignored_null": null, 11 | "ignored_string": "hello, world!" 12 | }, 13 | "another_list": [4] 14 | } 15 | -------------------------------------------------------------------------------- /plugins/inputs/postfix/stat_ctimespec.go: -------------------------------------------------------------------------------- 1 | // +build darwin freebsd 2 | 3 | package postfix 4 | 5 | import ( 6 | "syscall" 7 | "time" 8 | ) 9 | 10 | func statCTime(sys interface{}) time.Time { 11 | stat, ok := sys.(*syscall.Stat_t) 12 | if !ok { 13 | return time.Time{} 14 | } 15 | return time.Unix(stat.Ctimespec.Unix()) 16 | } 17 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/null/expected.out: -------------------------------------------------------------------------------- 1 | file,id=ak0217l8ue0x,type=Feature detail="https://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ak0217l8ue0x.geojson",mag=1.5,place="63 km N of Petersville, Alaska",status="automatic",time=1623708726566,updated=1623709998223,url="https://earthquake.usgs.gov/earthquakes/eventpage/ak0217l8ue0x" 2 | -------------------------------------------------------------------------------- /plugins/inputs/burrow/testdata/v3_kafka_clustername1_topic_topicA.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": false, 3 | "message": "topic offsets returned", 4 | "offsets": [ 5 | 459178195, 6 | 459178022, 7 | 456491598 8 | ], 9 | "request": { 10 | "url": "/v3/kafka/clustername1/topic/topicA", 11 | "host": "example.com" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/object/expected.out: -------------------------------------------------------------------------------- 1 | bart_json_v2,destination=Antioch,name=Colma minutes=13i 2 | bart_json_v2,destination=Antioch,name=Colma minutes=43i 3 | bart_json_v2,destination=Millbrae,name=Colma minutes=19i 4 | bart_json_v2,destination=Millbrae,name=Colma minutes=49i 5 | bart_json_v2,destination=Millbrae,name=Colma minutes=79i 6 | -------------------------------------------------------------------------------- /internal/process/process_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package process 4 | 5 | import ( 6 | "context" 7 | "os/exec" 8 | "time" 9 | ) 10 | 11 | func gracefulStop(ctx context.Context, cmd *exec.Cmd, timeout time.Duration) { 12 | select { 13 | case <-time.After(timeout): 14 | cmd.Process.Kill() 15 | case <-ctx.Done(): 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/null/telegraf.conf: -------------------------------------------------------------------------------- 1 | [[inputs.file]] 2 | files = ["./testdata/null/input.json"] 3 | data_format = "json_v2" 4 | [[inputs.file.json_v2]] 5 | [[inputs.file.json_v2.object]] 6 | path = "features" 7 | tags = ["type", "id"] 8 | disable_prepend_keys = true 9 | -------------------------------------------------------------------------------- /plugins/inputs/postfix/stat_ctim.go: -------------------------------------------------------------------------------- 1 | // +build dragonfly linux netbsd openbsd solaris 2 | 3 | package postfix 4 | 5 | import ( 6 | "syscall" 7 | "time" 8 | ) 9 | 10 | func statCTime(sys interface{}) time.Time { 11 | stat, ok := sys.(*syscall.Stat_t) 12 | if !ok { 13 | return time.Time{} 14 | } 15 | return time.Unix(stat.Ctim.Unix()) 16 | } 17 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/nested_array_of_objects/expected.out: -------------------------------------------------------------------------------- 1 | new_metric,name=partition LogEndOffset=339238i,LogStartOffset=339238i,NumLogSegments=1i,Size=0i,UnderReplicatedPartitions=0i 1610056029037925000 2 | new_metric,name=partition LogEndOffset=33914i,LogStartOffset=33238i,NumLogSegments=1i,Size=2i,UnderReplicatedPartitions=5i 1610056029037956000 3 | -------------------------------------------------------------------------------- /plugins/processors/printer/README.md: -------------------------------------------------------------------------------- 1 | # Printer Processor Plugin 2 | 3 | The printer processor plugin simple prints every metric passing through it. 4 | 5 | ### Configuration: 6 | 7 | ```toml 8 | # Print all metrics that pass through this filter. 9 | [[processors.printer]] 10 | ``` 11 | 12 | ### Tags: 13 | 14 | No tags are applied by this processor. 15 | -------------------------------------------------------------------------------- /docs/developers/CODE_STYLE.md: -------------------------------------------------------------------------------- 1 | # Code Style 2 | Code is required to be formatted using `gofmt`, this covers most code style 3 | requirements. It is also highly recommended to use `goimports` to 4 | automatically order imports. 5 | 6 | Please try to keep lines length under 80 characters, the exact number of 7 | characters is not strict but it generally helps with readability. 8 | -------------------------------------------------------------------------------- /plugins/outputs/sql/sqlite.go: -------------------------------------------------------------------------------- 1 | // +build linux,freebsd,darwin 2 | // +build !mips !mips64 3 | 4 | package sql 5 | 6 | // The modernc.org sqlite driver isn't supported on all 7 | // platforms. Register it with build constraints to prevent build 8 | // failures on unsupported platforms. 9 | import ( 10 | _ "modernc.org/sqlite" // Register sqlite sql driver 11 | ) 12 | -------------------------------------------------------------------------------- /config/testdata/single_plugin.toml: -------------------------------------------------------------------------------- 1 | [[inputs.memcached]] 2 | servers = ["localhost"] 3 | namepass = ["metricname1"] 4 | namedrop = ["metricname2"] 5 | fieldpass = ["some", "strings"] 6 | fielddrop = ["other", "stuff"] 7 | interval = "5s" 8 | [inputs.memcached.tagpass] 9 | goodtag = ["mytag"] 10 | [inputs.memcached.tagdrop] 11 | badtag = ["othertag"] 12 | -------------------------------------------------------------------------------- /config/testdata/subconfig/memcached.conf: -------------------------------------------------------------------------------- 1 | [[inputs.memcached]] 2 | servers = ["192.168.1.1"] 3 | namepass = ["metricname1"] 4 | namedrop = ["metricname2"] 5 | pass = ["some", "strings"] 6 | drop = ["other", "stuff"] 7 | interval = "5s" 8 | [inputs.memcached.tagpass] 9 | goodtag = ["mytag"] 10 | [inputs.memcached.tagdrop] 11 | badtag = ["othertag"] 12 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/array_of_objects/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example taken from: https://github.com/influxdata/telegraf/issues/5940 2 | 3 | [[inputs.file]] 4 | files = ["./testdata/array_of_objects/input.json"] 5 | data_format = "json_v2" 6 | [[inputs.file.json_v2]] 7 | [[inputs.file.json_v2.object]] 8 | path = "features" 9 | 10 | -------------------------------------------------------------------------------- /plugins/inputs/clickhouse/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | ### ClickHouse input plugin 2 | 3 | [[inputs.clickhouse]] 4 | timeout = 2 5 | username = "default" 6 | servers = ["http://127.0.0.1:8123"] 7 | auto_discovery = true 8 | cluster_include = [] 9 | cluster_exclude = ["test_shard_localhost"] 10 | 11 | [[outputs.file]] 12 | files = ["stdout"] 13 | -------------------------------------------------------------------------------- /plugins/inputs/opentelemetry/logger.go: -------------------------------------------------------------------------------- 1 | package opentelemetry 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/influxdata/telegraf" 7 | ) 8 | 9 | type otelLogger struct { 10 | telegraf.Logger 11 | } 12 | 13 | func (l otelLogger) Debug(msg string, kv ...interface{}) { 14 | format := msg + strings.Repeat(" %s=%q", len(kv)/2) 15 | l.Logger.Debugf(format, kv...) 16 | } 17 | -------------------------------------------------------------------------------- /plugins/inputs/file/dev/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | telegraf: 5 | image: glinton/scratch 6 | volumes: 7 | - ./telegraf.conf:/telegraf.conf 8 | - ../../../../telegraf:/telegraf 9 | - ./dev/json_a.log:/var/log/test.log 10 | entrypoint: 11 | - /telegraf 12 | - --config 13 | - /telegraf.conf 14 | -------------------------------------------------------------------------------- /plugins/inputs/zfs/zfs_other.go: -------------------------------------------------------------------------------- 1 | // +build !linux,!freebsd 2 | 3 | package zfs 4 | 5 | import ( 6 | "github.com/influxdata/telegraf" 7 | "github.com/influxdata/telegraf/plugins/inputs" 8 | ) 9 | 10 | func (z *Zfs) Gather(acc telegraf.Accumulator) error { 11 | return nil 12 | } 13 | 14 | func init() { 15 | inputs.Add("zfs", func() telegraf.Input { 16 | return &Zfs{} 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /plugins/inputs/logparser/dev/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | telegraf: 5 | image: glinton/scratch 6 | volumes: 7 | - ./telegraf.conf:/telegraf.conf 8 | - ../../../../telegraf:/telegraf 9 | - ./test.log:/var/log/test.log 10 | entrypoint: 11 | - /telegraf 12 | - --config 13 | - /telegraf.conf 14 | -------------------------------------------------------------------------------- /plugins/outputs/application_insights/mocks/diagnostics_message_listener.go: -------------------------------------------------------------------------------- 1 | package mocks 2 | 3 | import mock "github.com/stretchr/testify/mock" 4 | 5 | // DiagnosticsMessageSubscriber is an autogenerated mock type for the DiagnosticsMessageSubscriber type 6 | type DiagnosticsMessageListener struct { 7 | mock.Mock 8 | } 9 | 10 | func (_m *DiagnosticsMessageListener) Remove() { 11 | _m.Called() 12 | } 13 | -------------------------------------------------------------------------------- /plugins/inputs/execd/examples/count.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Example using HUP signaling 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | "os/signal" 9 | "syscall" 10 | ) 11 | 12 | func main() { 13 | c := make(chan os.Signal, 1) 14 | signal.Notify(c, syscall.SIGHUP) 15 | 16 | counter := 0 17 | 18 | for { 19 | <-c 20 | 21 | fmt.Printf("counter_go count=%d\n", counter) 22 | counter++ 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /plugins/outputs/health/contains.go: -------------------------------------------------------------------------------- 1 | package health 2 | 3 | import "github.com/influxdata/telegraf" 4 | 5 | type Contains struct { 6 | Field string `toml:"field"` 7 | } 8 | 9 | func (c *Contains) Check(metrics []telegraf.Metric) bool { 10 | success := false 11 | for _, m := range metrics { 12 | ok := m.HasField(c.Field) 13 | if ok { 14 | success = true 15 | } 16 | } 17 | 18 | return success 19 | } 20 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/complex_nesting/telegraf.conf: -------------------------------------------------------------------------------- 1 | [[inputs.file]] 2 | files = ["./testdata/complex_nesting/input.json"] 3 | data_format = "json_v2" 4 | [[inputs.file.json_v2]] 5 | [[inputs.file.json_v2.object]] 6 | path = "features" 7 | timestamp_key = "properties_time" 8 | timestamp_format = "unix_ms" 9 | tags = ["properties_place"] 10 | -------------------------------------------------------------------------------- /agent/agent_posix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package agent 4 | 5 | import ( 6 | "os" 7 | "os/signal" 8 | "syscall" 9 | ) 10 | 11 | const flushSignal = syscall.SIGUSR1 12 | 13 | func watchForFlushSignal(flushRequested chan os.Signal) { 14 | signal.Notify(flushRequested, flushSignal) 15 | } 16 | 17 | func stopListeningForFlushSignal(flushRequested chan os.Signal) { 18 | defer signal.Stop(flushRequested) 19 | } 20 | -------------------------------------------------------------------------------- /plugins/outputs/amon/README.md: -------------------------------------------------------------------------------- 1 | # Amon Output Plugin 2 | 3 | This plugin writes to [Amon](https://www.amon.cx) 4 | and requires an `serverkey` and `amoninstance` URL which can be obtained [here](https://www.amon.cx/docs/monitoring/) 5 | for the account. 6 | 7 | If the point value being sent cannot be converted to a float64, the metric is skipped. 8 | 9 | Metrics are grouped by converting any `_` characters to `.` in the Point Name. -------------------------------------------------------------------------------- /plugins/parsers/xpath/testcases/multisensor_explicit_basic.conf: -------------------------------------------------------------------------------- 1 | # Simple example for using the xml-parser. 2 | # 3 | # File: 4 | # testcases/multisensor.xml 5 | # 6 | # Expected Output: 7 | # xml,gateway=Main seqnr=12i,ok=true 8 | # 9 | 10 | [tags] 11 | gateway = "substring-before(/Gateway/Name, ' ')" 12 | 13 | [fields_int] 14 | seqnr = "/Gateway/Sequence" 15 | 16 | [fields] 17 | ok = "/Gateway/Status = 'ok'" 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | labels: feature request 4 | about: Suggest an idea for this project 5 | 6 | --- 7 | 8 | ## Feature Request 9 | 10 | Opening a feature request kicks off a discussion. 11 | 12 | ### Proposal: 13 | 14 | ### Current behavior: 15 | 16 | ### Desired behavior: 17 | 18 | ### Use case: 19 | -------------------------------------------------------------------------------- /config/testdata/single_plugin_env_vars.toml: -------------------------------------------------------------------------------- 1 | [[inputs.memcached]] 2 | servers = ["$MY_TEST_SERVER"] 3 | namepass = ["metricname1", "ip_${MY_TEST_SERVER}_name"] 4 | namedrop = ["metricname2"] 5 | fieldpass = ["some", "strings"] 6 | fielddrop = ["other", "stuff"] 7 | interval = "$TEST_INTERVAL" 8 | [inputs.memcached.tagpass] 9 | goodtag = ["mytag"] 10 | [inputs.memcached.tagdrop] 11 | badtag = ["othertag"] 12 | -------------------------------------------------------------------------------- /plugins/inputs/zookeeper/dev/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | zoo: 4 | image: zookeeper 5 | 6 | telegraf: 7 | image: glinton/scratch 8 | volumes: 9 | - ./telegraf.conf:/telegraf.conf 10 | - ../../../../telegraf:/telegraf 11 | depends_on: 12 | - zoo 13 | entrypoint: 14 | - /telegraf 15 | - --config 16 | - /telegraf.conf 17 | network_mode: service:zoo 18 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/measurement_name_int/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example taken from: https://github.com/influxdata/feature-requests/issues/160 2 | 3 | [[inputs.file]] 4 | files = ["./testdata/measurement_name_int/input.json"] 5 | data_format = "json_v2" 6 | [[inputs.file.json_v2]] 7 | measurement_name_path = "class_id" 8 | [[inputs.file.json_v2.field]] 9 | path = "label" 10 | -------------------------------------------------------------------------------- /plugins/processors/execd/examples/multiplier_line_protocol/multiplier.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | interval = "10s" 3 | 4 | [[inputs.execd]] 5 | command = ["ruby", "plugins/inputs/execd/examples/count.rb"] 6 | 7 | [[processors.execd]] 8 | command = ["ruby", "plugins/processors/execd/examples/multiplier_line_protocol/multiplier_line_protocol.rb"] 9 | 10 | 11 | [[outputs.file]] 12 | files = ["stdout"] 13 | data_format = "influx" 14 | 15 | -------------------------------------------------------------------------------- /plugins/inputs/execd/examples/count.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | ## Example in Ruby not using any signaling 4 | 5 | counter = 0 6 | 7 | def time_ns_str(t) 8 | ns = t.nsec.to_s 9 | (9 - ns.size).times do 10 | ns = "0" + ns # left pad 11 | end 12 | t.to_i.to_s + ns 13 | end 14 | 15 | loop do 16 | puts "counter_ruby count=#{counter} #{time_ns_str(Time.now)}" 17 | STDOUT.flush 18 | counter += 1 19 | 20 | sleep 1 21 | end 22 | -------------------------------------------------------------------------------- /plugins/inputs/mongodb/dev/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | mongodb: 4 | image: mongo 5 | 6 | telegraf: 7 | image: glinton/scratch 8 | volumes: 9 | - ./telegraf.conf:/telegraf.conf 10 | - ../../../../telegraf:/telegraf 11 | depends_on: 12 | - mongodb 13 | entrypoint: 14 | - /telegraf 15 | - --config 16 | - /telegraf.conf 17 | -------------------------------------------------------------------------------- /plugins/outputs/execd/examples/redis/telegraf.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | flush_interval = "1s" 3 | interval = "1s" 4 | 5 | [[inputs.execd]] 6 | command = ["ruby", "plugins/inputs/execd/examples/count.rb"] 7 | signal = "none" 8 | 9 | [[outputs.execd]] 10 | command = ["ruby", "plugins/outputs/execd/examples/redis/redis_influx.rb"] 11 | data_format = "influx" 12 | 13 | # [[outputs.file]] 14 | # files = ["stdout"] 15 | # data_format = "influx" 16 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/multiple_timestamps/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example taken from: https://github.com/influxdata/telegraf/issues/5940 2 | 3 | [[inputs.file]] 4 | files = ["./testdata/multiple_timestamps/input.json"] 5 | data_format = "json_v2" 6 | [[inputs.file.json_v2]] 7 | [[inputs.file.json_v2.object]] 8 | path = "events" 9 | timestamp_key = "time" 10 | timestamp_format = "unix_ms" 11 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/nested_tags/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "device0": { 3 | "Count": 0, 4 | "Errors": 0, 5 | "Serial": "9JHNGTUT", 6 | "Model": "WDC WUH721414ALE604", 7 | "Firmware": "LDGSW07G" 8 | }, 9 | "device1": { 10 | "Count": 0, 11 | "Errors": 0, 12 | "Serial": "9JHLPW9T", 13 | "Model": "WDC WUH721414ALE604", 14 | "Firmware": "LDGSW07G" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/drop_string_fields.star: -------------------------------------------------------------------------------- 1 | # Drop fields if they contain a string. 2 | # 3 | # Example Input: 4 | # measurement,host=hostname a=1,b="somestring" 1597255410000000000 5 | # 6 | # Example Output: 7 | # measurement,host=hostname a=1 1597255410000000000 8 | 9 | def apply(metric): 10 | for k, v in metric.fields.items(): 11 | if type(v) == "string": 12 | metric.fields.pop(k) 13 | 14 | return metric 15 | -------------------------------------------------------------------------------- /plugins/outputs/application_insights/diagnostic_message_subscriber.go: -------------------------------------------------------------------------------- 1 | package application_insights 2 | 3 | import ( 4 | "github.com/microsoft/ApplicationInsights-Go/appinsights" 5 | ) 6 | 7 | type diagnosticsMessageSubscriber struct { 8 | } 9 | 10 | func (ms diagnosticsMessageSubscriber) Subscribe(handler appinsights.DiagnosticsMessageHandler) appinsights.DiagnosticsMessageListener { 11 | return appinsights.NewDiagnosticsMessageListener(handler) 12 | } 13 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/time_set_timestamp.star: -------------------------------------------------------------------------------- 1 | # Example of setting the metric timestamp to the current time. 2 | # 3 | # Example Input: 4 | # time result="OK" 1515581000000000000 5 | # 6 | # Example Output: 7 | # time result="OK" 1618488000000000999 8 | 9 | load('time.star', 'time') 10 | 11 | def apply(metric): 12 | # You can set the timestamp by using the current time. 13 | metric.time = time.now().unix_nano 14 | 15 | return metric -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/large_numbers/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "int": { 3 | "large": 4294967296, 4 | "larger": 9007199254740991, 5 | "largest": 9223372036854775807 6 | }, 7 | "uint": { 8 | "large": 9007199254740991, 9 | "larger": 9223372036854775807, 10 | "largest": 18446744073709551615 11 | }, 12 | "float": { 13 | "large": 4294967296, 14 | "larger": 4.294967296663e+09, 15 | "largest": 9007199254740991 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /plugins/inputs/tail/testdata/test_multiline.log: -------------------------------------------------------------------------------- 1 | [04/Jun/2016:12:41:45 +0100] DEBUG HelloExample: This is debug 2 | [04/Jun/2016:12:41:48 +0100] INFO HelloExample: This is info 3 | [04/Jun/2016:12:41:46 +0100] ERROR HelloExample: Sorry, something wrong! 4 | java.lang.ArithmeticException: / by zero 5 | at com.foo.HelloExample2.divide(HelloExample2.java:24) 6 | at com.foo.HelloExample2.main(HelloExample2.java:14) 7 | [04/Jun/2016:12:41:48 +0100] WARN HelloExample: This is warn 8 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/timestamp/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example taken from: https://github.com/influxdata/telegraf/issues/5940 2 | 3 | [[inputs.file]] 4 | files = ["./testdata/timestamp/input.json"] 5 | data_format = "json_v2" 6 | [[inputs.file.json_v2]] 7 | timestamp_path = "time" 8 | timestamp_format = "unix_ms" 9 | [[inputs.file.json_v2.object]] 10 | path = "measurements" 11 | tags = ["name", "units"] 12 | -------------------------------------------------------------------------------- /plugins/inputs/docker/errors.go: -------------------------------------------------------------------------------- 1 | package docker 2 | 3 | import "errors" 4 | 5 | var ( 6 | errInfoTimeout = errors.New("timeout retrieving docker engine info") 7 | errStatsTimeout = errors.New("timeout retrieving container stats") 8 | errInspectTimeout = errors.New("timeout retrieving container environment") 9 | errListTimeout = errors.New("timeout retrieving container list") 10 | errServiceTimeout = errors.New("timeout retrieving swarm service list") 11 | ) 12 | -------------------------------------------------------------------------------- /plugins/inputs/kubernetes/kubernetes_pods.go: -------------------------------------------------------------------------------- 1 | package kubernetes 2 | 3 | type Pods struct { 4 | Kind string `json:"kind"` 5 | APIVersion string `json:"apiVersion"` 6 | Items []Item `json:"items"` 7 | } 8 | 9 | type Item struct { 10 | Metadata Metadata `json:"metadata"` 11 | } 12 | 13 | type Metadata struct { 14 | Name string `json:"name"` 15 | Namespace string `json:"namespace"` 16 | Labels map[string]string `json:"labels"` 17 | } 18 | -------------------------------------------------------------------------------- /plugins/inputs/nsq/README.md: -------------------------------------------------------------------------------- 1 | # NSQ Input Plugin 2 | 3 | ### Configuration: 4 | 5 | ```toml 6 | # Description 7 | [[inputs.nsq]] 8 | ## An array of NSQD HTTP API endpoints 9 | endpoints = ["http://localhost:4151"] 10 | 11 | ## Optional TLS Config 12 | # tls_ca = "/etc/telegraf/ca.pem" 13 | # tls_cert = "/etc/telegraf/cert.pem" 14 | # tls_key = "/etc/telegraf/key.pem" 15 | ## Use TLS but skip chain & host verification 16 | # insecure_skip_verify = false 17 | ``` 18 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/fields_and_tags_complex/telegraf.conf: -------------------------------------------------------------------------------- 1 | [[inputs.file]] 2 | files = ["./testdata/fields_and_tags_complex/input.json"] 3 | data_format = "json_v2" 4 | [[inputs.file.json_v2]] 5 | measurement_name = "bart_json_v2" 6 | [[inputs.file.json_v2.tag]] 7 | path = "root.station.#.name" 8 | [[inputs.file.json_v2.field]] 9 | path = "root.station.#.etd.#.estimate.#.minutes" 10 | type = "int" 11 | -------------------------------------------------------------------------------- /internal/process/process_posix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package process 4 | 5 | import ( 6 | "context" 7 | "os/exec" 8 | "syscall" 9 | "time" 10 | ) 11 | 12 | func gracefulStop(ctx context.Context, cmd *exec.Cmd, timeout time.Duration) { 13 | select { 14 | case <-time.After(timeout): 15 | cmd.Process.Signal(syscall.SIGTERM) 16 | case <-ctx.Done(): 17 | } 18 | select { 19 | case <-time.After(timeout): 20 | cmd.Process.Kill() 21 | case <-ctx.Done(): 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /plugins/inputs/file/testdata/mtr-utf-8.csv: -------------------------------------------------------------------------------- 1 | Mtr_Version,Start_Time,Status,Host,Hop,Ip,Loss%,Snt, ,Last,Avg,Best,Wrst,StDev, 2 | MTR.0.87,1593667013,OK,example.org,1,12.122.114.5,0.00,10,0,21.86,21.55,19.34,26.83,2.05 3 | MTR.0.87,1593667013,OK,example.org,2,192.205.32.238,0.00,10,0,32.83,25.11,20.80,38.85,6.03 4 | MTR.0.87,1593667013,OK,example.org,3,152.195.85.133,0.00,10,0,19.75,20.18,19.75,20.78,0.00 5 | MTR.0.87,1593667013,OK,example.org,4,93.184.216.34,0.00,10,0,19.75,24.02,19.75,32.41,4.67 6 | -------------------------------------------------------------------------------- /scripts/buster.docker: -------------------------------------------------------------------------------- 1 | FROM golang:1.16.6-buster as builder 2 | WORKDIR /go/src/github.com/influxdata/telegraf 3 | 4 | COPY . /go/src/github.com/influxdata/telegraf 5 | RUN make go-install 6 | 7 | FROM buildpack-deps:buster-curl 8 | COPY --from=builder /go/bin/* /usr/bin/ 9 | COPY etc/telegraf.conf /etc/telegraf/telegraf.conf 10 | 11 | EXPOSE 8125/udp 8092/udp 8094 12 | 13 | COPY scripts/docker-entrypoint.sh /entrypoint.sh 14 | ENTRYPOINT ["/entrypoint.sh"] 15 | CMD ["telegraf"] 16 | -------------------------------------------------------------------------------- /scripts/stretch.docker: -------------------------------------------------------------------------------- 1 | FROM golang:1.14.9-stretch as builder 2 | WORKDIR /go/src/github.com/influxdata/telegraf 3 | 4 | COPY . /go/src/github.com/influxdata/telegraf 5 | RUN make go-install 6 | 7 | FROM buildpack-deps:stretch-curl 8 | COPY --from=builder /go/bin/* /usr/bin/ 9 | COPY etc/telegraf.conf /etc/telegraf/telegraf.conf 10 | 11 | EXPOSE 8125/udp 8092/udp 8094 12 | 13 | COPY scripts/docker-entrypoint.sh /entrypoint.sh 14 | ENTRYPOINT ["/entrypoint.sh"] 15 | CMD ["telegraf"] 16 | -------------------------------------------------------------------------------- /plugins/inputs/filecount/testdata/qux: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 2 | eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad 3 | minim veniam, quis nostrud exercitation ullamco laboris nisi ut 4 | aliquip ex ea commodo consequat. Duis aute irure dolor in 5 | reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 6 | pariatur. Excepteur sint occaecat cupidatat non proident, sunt in 7 | culpa qui officia deserunt mollit anim id est laborum. 8 | -------------------------------------------------------------------------------- /scripts/telegraf_entry_mac: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | currentDir="$( cd "$(dirname "$0")" ; pwd -P )" 3 | 4 | if [[ $currentDir == *"AppTranslocation"* || $currentDir == *"Volumes"* ]]; then 5 | osascript -e "display alert \"Please copy Telegraf to somewhere on your machine. It can't be run from the image.\" as critical" 6 | else 7 | cd $currentDir 8 | osascript< 2 | 3 | system 4 | part_log
5 | 7500 6 | 7 | event_date 8 | 9 | 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /plugins/inputs/execd/shim/input.go: -------------------------------------------------------------------------------- 1 | package shim 2 | 3 | import "github.com/influxdata/telegraf" 4 | 5 | // inputShim implements the MetricMaker interface. 6 | type inputShim struct { 7 | Input telegraf.Input 8 | } 9 | 10 | func (i inputShim) LogName() string { 11 | return "" 12 | } 13 | 14 | func (i inputShim) MakeMetric(m telegraf.Metric) telegraf.Metric { 15 | return m // don't need to do anything to it. 16 | } 17 | 18 | func (i inputShim) Log() telegraf.Logger { 19 | return nil 20 | } 21 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/math.star: -------------------------------------------------------------------------------- 1 | # Example showing how the math module can be used to compute the value of a field. 2 | # 3 | # Example Input: 4 | # math value=10000i 1465839830100400201 5 | # 6 | # Example Output: 7 | # math result=4 1465839830100400201 8 | 9 | load('math.star', 'math') 10 | # loads all the functions and constants defined in the math module 11 | 12 | def apply(metric): 13 | metric.fields["result"] = math.log(metric.fields.pop('value'), 10) 14 | return metric 15 | -------------------------------------------------------------------------------- /plugins/inputs/filecount/testdata/subdir/nested2/qux: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do 2 | eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad 3 | minim veniam, quis nostrud exercitation ullamco laboris nisi ut 4 | aliquip ex ea commodo consequat. Duis aute irure dolor in 5 | reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 6 | pariatur. Excepteur sint occaecat cupidatat non proident, sunt in 7 | culpa qui officia deserunt mollit anim id est laborum. 8 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/multiple_arrays_in_object/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example getting nested fields with duplicate names 2 | # Example taken from: https://github.com/influxdata/telegraf/issues/1363 3 | 4 | [[inputs.file]] 5 | files = ["./testdata/multiple_arrays_in_object/input.json"] 6 | data_format = "json_v2" 7 | [[inputs.file.json_v2]] 8 | [[inputs.file.json_v2.object]] 9 | path = "book" 10 | tags = ["title"] 11 | disable_prepend_keys = true 12 | -------------------------------------------------------------------------------- /scripts/ci-1.15.docker: -------------------------------------------------------------------------------- 1 | FROM golang:1.15.8 2 | 3 | RUN chmod -R 755 "$GOPATH" 4 | 5 | RUN DEBIAN_FRONTEND=noninteractive \ 6 | apt update && apt install -y --no-install-recommends \ 7 | autoconf \ 8 | git \ 9 | libtool \ 10 | locales \ 11 | make \ 12 | awscli \ 13 | rpm \ 14 | ruby \ 15 | ruby-dev \ 16 | zip && \ 17 | rm -rf /var/lib/apt/lists/* 18 | 19 | RUN ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime 20 | RUN locale-gen C.UTF-8 || true 21 | ENV LANG=C.UTF-8 22 | 23 | RUN gem install fpm 24 | -------------------------------------------------------------------------------- /scripts/ci-1.16.docker: -------------------------------------------------------------------------------- 1 | FROM golang:1.16.6 2 | 3 | RUN chmod -R 755 "$GOPATH" 4 | 5 | RUN DEBIAN_FRONTEND=noninteractive \ 6 | apt update && apt install -y --no-install-recommends \ 7 | autoconf \ 8 | git \ 9 | libtool \ 10 | locales \ 11 | make \ 12 | awscli \ 13 | rpm \ 14 | ruby \ 15 | ruby-dev \ 16 | zip && \ 17 | rm -rf /var/lib/apt/lists/* 18 | 19 | RUN ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime 20 | RUN locale-gen C.UTF-8 || true 21 | ENV LANG=C.UTF-8 22 | 23 | RUN gem install fpm 24 | -------------------------------------------------------------------------------- /plugins/outputs/execd/examples/redis/redis_influx.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # An example of funneling metrics to Redis pub/sub. 4 | # 5 | # to run this, you may need to: 6 | # gem install redis 7 | # 8 | require 'redis' 9 | 10 | r = Redis.new(host: "127.0.0.1", port: 6379, db: 1) 11 | 12 | loop do 13 | # example input: "counter_ruby count=0 1591741648101185000" 14 | line = STDIN.readline.chomp 15 | 16 | key = line.split(" ")[0] 17 | key = key.split(",")[0] 18 | r.publish(key, line) 19 | end 20 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/measurement_name_int/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "value_id": "52-32-1-0", 3 | "node_id": 52, 4 | "class_id": 32, 5 | "type": "byte", 6 | "genre": "basic", 7 | "instance": 1, 8 | "index": 0, 9 | "label": "Basic", 10 | "units": "", 11 | "help": "Basic status of the node", 12 | "read_only": false, 13 | "write_only": false, 14 | "min": 0, 15 | "max": 255, 16 | "is_polled": false, 17 | "value": 0, 18 | "lastUpdate": 1584636017962 19 | } 20 | -------------------------------------------------------------------------------- /plugins/inputs/clickhouse/dev/text_log.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | notice 4 | system 5 | text_log
6 | 7500 7 | 8 | event_date 9 | 10 | 11 |
12 |
13 | -------------------------------------------------------------------------------- /plugins/inputs/ethtool/ethtool_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package ethtool 4 | 5 | import ( 6 | "github.com/influxdata/telegraf" 7 | "github.com/influxdata/telegraf/plugins/inputs" 8 | ) 9 | 10 | func (e *Ethtool) Init() error { 11 | e.Log.Warn("Current platform is not supported") 12 | return nil 13 | } 14 | 15 | func (e *Ethtool) Gather(acc telegraf.Accumulator) error { 16 | return nil 17 | } 18 | 19 | func init() { 20 | inputs.Add(pluginName, func() telegraf.Input { 21 | return &Ethtool{} 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /plugins/inputs/ravendb/testdata/collections_min.json: -------------------------------------------------------------------------------- 1 | { 2 | "PublicServerUrl": null, 3 | "NodeTag": "A", 4 | "Results": [ 5 | { 6 | "DatabaseName": "db1", 7 | "Collections": [ 8 | { 9 | "CollectionName": "Orders", 10 | "DocumentsCount": 830, 11 | "TotalSizeInBytes": 2744320, 12 | "DocumentsSizeInBytes": 868352, 13 | "TombstonesSizeInBytes": 122880, 14 | "RevisionsSizeInBytes": 1753088 15 | } 16 | ] 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleExecutable 6 | telegraf_entry_mac 7 | CFBundleIconFile 8 | icon.icns 9 | CFBundleIdentifier 10 | com.influxdata.telegraf 11 | NSHighResolutionCapable 12 | 13 | LSUIElement 14 | 15 | 16 | -------------------------------------------------------------------------------- /plugins/inputs/synproxy/synproxy_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package synproxy 4 | 5 | import ( 6 | "github.com/influxdata/telegraf" 7 | "github.com/influxdata/telegraf/plugins/inputs" 8 | ) 9 | 10 | func (k *Synproxy) Init() error { 11 | k.Log.Warn("Current platform is not supported") 12 | return nil 13 | } 14 | 15 | func (k *Synproxy) Gather(acc telegraf.Accumulator) error { 16 | return nil 17 | } 18 | 19 | func init() { 20 | inputs.Add("synproxy", func() telegraf.Input { 21 | return &Synproxy{} 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /plugins/inputs/wireless/wireless_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package wireless 4 | 5 | import ( 6 | "github.com/influxdata/telegraf" 7 | "github.com/influxdata/telegraf/plugins/inputs" 8 | ) 9 | 10 | func (w *Wireless) Init() error { 11 | w.Log.Warn("Current platform is not supported") 12 | return nil 13 | } 14 | 15 | func (w *Wireless) Gather(acc telegraf.Accumulator) error { 16 | return nil 17 | } 18 | 19 | func init() { 20 | inputs.Add("wireless", func() telegraf.Input { 21 | return &Wireless{} 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/nested_tags/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example taken from: https://github.com/influxdata/telegraf/issues/6853 2 | 3 | [[inputs.file]] 4 | files = ["./testdata/nested_tags/input.json"] 5 | data_format = "json_v2" 6 | [[inputs.file.json_v2]] 7 | [[inputs.file.json_v2.object]] 8 | path = "device0" 9 | tags = ["Firmware", "Model", "Serial"] 10 | [[inputs.file.json_v2.object]] 11 | path = "device1" 12 | tags = ["Firmware", "Model", "Serial"] 13 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/scale.star: -------------------------------------------------------------------------------- 1 | # Multiply any float fields by 10 2 | # 3 | # Example Input: 4 | # modbus,host=hostname Current=1.22,Energy=0,Frequency=60i,Power=0,Voltage=123.9000015258789 1554079521000000000 5 | # 6 | # Example Output: 7 | # modbus,host=hostname Current=12.2,Energy=0,Frequency=60i,Power=0,Voltage=1239.000015258789 1554079521000000000 8 | 9 | def apply(metric): 10 | for k, v in metric.fields.items(): 11 | if type(v) == "float": 12 | metric.fields[k] = v * 10 13 | return metric 14 | -------------------------------------------------------------------------------- /plugins/inputs/execd/shim/goshim_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package shim 4 | 5 | import ( 6 | "context" 7 | "os" 8 | "os/signal" 9 | "syscall" 10 | ) 11 | 12 | func listenForCollectMetricsSignals(ctx context.Context, collectMetricsPrompt chan os.Signal) { 13 | signal.Notify(collectMetricsPrompt, syscall.SIGHUP) 14 | 15 | go func() { 16 | select { 17 | case <-ctx.Done(): 18 | // context done. stop to signals to avoid pushing messages to a closed channel 19 | signal.Stop(collectMetricsPrompt) 20 | } 21 | }() 22 | } 23 | -------------------------------------------------------------------------------- /plugins/inputs/infiniband/infiniband_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package infiniband 4 | 5 | import ( 6 | "github.com/influxdata/telegraf" 7 | "github.com/influxdata/telegraf/plugins/inputs" 8 | ) 9 | 10 | func (i *Infiniband) Init() error { 11 | i.Log.Warn("Current platform is not supported") 12 | return nil 13 | } 14 | 15 | func (_ *Infiniband) Gather(acc telegraf.Accumulator) error { 16 | return nil 17 | } 18 | 19 | func init() { 20 | inputs.Add("infiniband", func() telegraf.Input { 21 | return &Infiniband{} 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /plugins/inputs/linux_sysctl_fs/README.md: -------------------------------------------------------------------------------- 1 | # Linux Sysctl FS Input Plugin 2 | 3 | The linux_sysctl_fs input provides Linux system level file metrics. The documentation on these fields can be found at https://www.kernel.org/doc/Documentation/sysctl/fs.txt. 4 | 5 | Example output: 6 | 7 | ``` 8 | > linux_sysctl_fs,host=foo dentry-want-pages=0i,file-max=44222i,aio-max-nr=65536i,inode-preshrink-nr=0i,dentry-nr=64340i,dentry-unused-nr=55274i,file-nr=1568i,aio-nr=0i,inode-nr=35952i,inode-free-nr=12957i,dentry-age-limit=45i 1490982022000000000 9 | ``` 10 | -------------------------------------------------------------------------------- /plugins/inputs/ravendb/testdata/collections_full.json: -------------------------------------------------------------------------------- 1 | { 2 | "PublicServerUrl": "http://localhost:8080", 3 | "NodeTag": "A", 4 | "Results": [ 5 | { 6 | "DatabaseName": "db1", 7 | "Collections": [ 8 | { 9 | "CollectionName": "Orders", 10 | "DocumentsCount": 830, 11 | "TotalSizeInBytes": 2744320, 12 | "DocumentsSizeInBytes": 868352, 13 | "TombstonesSizeInBytes": 122880, 14 | "RevisionsSizeInBytes": 1753088 15 | } 16 | ] 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /plugins/inputs/clickhouse/dev/telegraf_ssl.conf: -------------------------------------------------------------------------------- 1 | ### ClickHouse input plugin 2 | 3 | [[inputs.clickhouse]] 4 | timeout = 2 5 | username = "default" 6 | servers = ["https://127.0.0.1:8443"] 7 | auto_discovery = true 8 | cluster_include = [] 9 | cluster_exclude = ["test_shard_localhost"] 10 | insecure_skip_verify = false 11 | tls_cert = "./testutil/pki/clientcert.pem" 12 | tls_key = "./testutil/pki/clientkey.pem" 13 | tls_ca = "./testutil/pki/cacert.pem" 14 | 15 | [[outputs.file]] 16 | files = ["stdout"] 17 | -------------------------------------------------------------------------------- /plugins/inputs/webhooks/filestack/filestack_webhooks_events.go: -------------------------------------------------------------------------------- 1 | package filestack 2 | 3 | import "strconv" 4 | 5 | type FilestackEvent struct { 6 | Action string `json:"action"` 7 | TimeStamp int64 `json:"timestamp"` 8 | ID int `json:"id"` 9 | } 10 | 11 | func (fe *FilestackEvent) Tags() map[string]string { 12 | return map[string]string{ 13 | "action": fe.Action, 14 | } 15 | } 16 | 17 | func (fe *FilestackEvent) Fields() map[string]interface{} { 18 | return map[string]interface{}{ 19 | "id": strconv.Itoa(fe.ID), 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /plugins/parsers/nagios/README.md: -------------------------------------------------------------------------------- 1 | # Nagios 2 | 3 | The `nagios` data format parses the output of nagios plugins. 4 | 5 | ### Configuration 6 | 7 | ```toml 8 | [[inputs.exec]] 9 | ## Commands array 10 | commands = ["/usr/lib/nagios/plugins/check_load -w 5,6,7 -c 7,8,9"] 11 | 12 | ## Data format to consume. 13 | ## Each data format has its own unique set of configuration options, read 14 | ## more about them here: 15 | ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md 16 | data_format = "nagios" 17 | ``` 18 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/fail.star: -------------------------------------------------------------------------------- 1 | # Example of the way to return a custom error thanks to the built-in function fail 2 | # Returning an error will drop the current metric. Consider using logging instead if you want to keep the metric. 3 | # 4 | # Example Input: 5 | # fail value=1 1465839830100400201 6 | # 7 | # Example Output Error: 8 | # fail: The field value should be greater than 1 9 | 10 | def apply(metric): 11 | if metric.fields["value"] <= 1: 12 | return fail("The field value should be greater than 1") 13 | return metric 14 | -------------------------------------------------------------------------------- /models/log_test.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/influxdata/telegraf/selfstat" 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestErrorCounting(t *testing.T) { 11 | reg := selfstat.Register( 12 | "gather", 13 | "errors", 14 | map[string]string{"input": "test"}, 15 | ) 16 | iLog := Logger{Name: "inputs.test"} 17 | iLog.OnErr(func() { 18 | reg.Incr(1) 19 | }) 20 | iLog.Error("something went wrong") 21 | iLog.Errorf("something went wrong") 22 | 23 | require.Equal(t, int64(2), reg.Get()) 24 | } 25 | -------------------------------------------------------------------------------- /plugins/processors/ifname/cache_test.go: -------------------------------------------------------------------------------- 1 | package ifname 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | ) 8 | 9 | func TestCache(t *testing.T) { 10 | c := NewLRUCache(2) 11 | 12 | c.Put("ones", LRUValType{val: nameMap{1: "one"}}) 13 | twoMap := LRUValType{val: nameMap{2: "two"}} 14 | c.Put("twos", twoMap) 15 | c.Put("threes", LRUValType{val: nameMap{3: "three"}}) 16 | 17 | _, ok := c.Get("ones") 18 | require.False(t, ok) 19 | 20 | v, ok := c.Get("twos") 21 | require.True(t, ok) 22 | require.Equal(t, twoMap, v) 23 | } 24 | -------------------------------------------------------------------------------- /plugins/inputs/jolokia2/jolokia.go: -------------------------------------------------------------------------------- 1 | package jolokia2 2 | 3 | import ( 4 | "github.com/influxdata/telegraf" 5 | "github.com/influxdata/telegraf/plugins/inputs" 6 | ) 7 | 8 | func init() { 9 | inputs.Add("jolokia2_agent", func() telegraf.Input { 10 | return &JolokiaAgent{ 11 | Metrics: []MetricConfig{}, 12 | DefaultFieldSeparator: ".", 13 | } 14 | }) 15 | inputs.Add("jolokia2_proxy", func() telegraf.Input { 16 | return &JolokiaProxy{ 17 | Metrics: []MetricConfig{}, 18 | DefaultFieldSeparator: ".", 19 | } 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /plugins/outputs/execd/examples/redis/redis_json.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # An example of funneling metrics to Redis pub/sub. 4 | # 5 | # to run this, you may need to: 6 | # gem install redis 7 | # 8 | require 'redis' 9 | require 'json' 10 | 11 | r = Redis.new(host: "127.0.0.1", port: 6379, db: 1) 12 | 13 | loop do 14 | # example input: "{"fields":{"count":0},"name":"counter_ruby","tags":{"host":"localhost"},"timestamp":1586374982}" 15 | line = STDIN.readline.chomp 16 | 17 | l = JSON.parse(line) 18 | 19 | key = l["name"] 20 | r.publish(key, line) 21 | end 22 | -------------------------------------------------------------------------------- /scripts/telegraf.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=The plugin-driven server agent for reporting metrics into InfluxDB 3 | Documentation=https://github.com/influxdata/telegraf 4 | After=network.target 5 | 6 | [Service] 7 | EnvironmentFile=-/etc/default/telegraf 8 | User=telegraf 9 | ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d $TELEGRAF_OPTS 10 | ExecReload=/bin/kill -HUP $MAINPID 11 | Restart=on-failure 12 | RestartForceExitStatus=SIGPIPE 13 | KillMode=control-group 14 | 15 | [Install] 16 | WantedBy=multi-user.target 17 | -------------------------------------------------------------------------------- /plugins/outputs/riemann_legacy/riemann_test.go: -------------------------------------------------------------------------------- 1 | package riemann_legacy 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/influxdata/telegraf/testutil" 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestConnectAndWrite(t *testing.T) { 11 | t.Skip("Skipping legacy integration test") 12 | 13 | url := testutil.GetLocalHost() + ":5555" 14 | 15 | r := &Riemann{ 16 | URL: url, 17 | Transport: "tcp", 18 | } 19 | 20 | err := r.Connect() 21 | require.NoError(t, err) 22 | 23 | err = r.Write(testutil.MockMetrics()) 24 | require.NoError(t, err) 25 | } 26 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/pivot.star: -------------------------------------------------------------------------------- 1 | ''' 2 | Pivots a key's value to be the key for another key. 3 | In this example it pivots the value of key `sensor` 4 | to be the key of the value in key `value` 5 | 6 | Example Input: 7 | temperature sensor="001A0",value=111.48 1618488000000000999 8 | 9 | Example Output: 10 | temperature 001A0=111.48 1618488000000000999 11 | ''' 12 | 13 | def apply(metric): 14 | metric.fields[str(metric.fields['sensor'])] = metric.fields['value'] 15 | metric.fields.pop('value',None) 16 | metric.fields.pop('sensor',None) 17 | return metric 18 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/number_logic.star: -------------------------------------------------------------------------------- 1 | # Set a logic function to transform a numerical value to another numerical value 2 | # Example: Set any 'status' field between 1 and 6 to a value of 0 3 | # 4 | # Example Input: 5 | # lb,http_method=GET status=5i 1465839830100400201 6 | # 7 | # Example Output: 8 | # lb,http_method=GET status=0i 1465839830100400201 9 | 10 | 11 | def apply(metric): 12 | v = metric.fields.get('status') 13 | if v == None: 14 | return metric 15 | if 1 < v and v < 6: 16 | metric.fields['status'] = 0 17 | return metric 18 | -------------------------------------------------------------------------------- /plugins/inputs/clickhouse/dev/zookeeper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | zookeeper 5 | 2181 6 | 7 | 8 | 9 | 10 | 11 | 1 12 | 13 | localhost 14 | 9000 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /plugins/inputs/logparser/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | interval="1s" 3 | flush_interval="1s" 4 | 5 | [[inputs.logparser]] 6 | files = ["/var/log/test.log"] 7 | from_beginning = true 8 | [inputs.logparser.grok] 9 | patterns = [ "%{COMBINED_LOG_FORMAT}", "%{CLIENT:client_ip} %{NOTSPACE:ident} %{NOTSPACE:auth} \\[%{TIMESTAMP_ISO8601:timestamp}\\] \"(?:%{WORD:verb:tag} %{NOTSPACE:request}(?: HTTP/%{NUMBER:http_version:float})?|%{DATA})\" %{NUMBER:resp_code:tag} (?:%{NUMBER:resp_bytes:int}|-) %{QS:referrer} %{QS:agent}"] 10 | 11 | [[outputs.file]] 12 | files = ["stdout"] 13 | -------------------------------------------------------------------------------- /plugins/outputs/librato/README.md: -------------------------------------------------------------------------------- 1 | # Librato Output Plugin 2 | 3 | This plugin writes to the [Librato Metrics API](http://dev.librato.com/v1/metrics#metrics) 4 | and requires an `api_user` and `api_token` which can be obtained [here](https://metrics.librato.com/account/api_tokens) 5 | for the account. 6 | 7 | The `source_tag` option in the Configuration file is used to send contextual information from 8 | Point Tags to the API. 9 | 10 | If the point value being sent cannot be converted to a float64, the metric is skipped. 11 | 12 | Currently, the plugin does not send any associated Point Tags. -------------------------------------------------------------------------------- /plugins/inputs/suricata/testdata/test3.json: -------------------------------------------------------------------------------- 1 | {"timestamp":"2021-05-30T20:07:13.208777+0200","flow_id":1696236471136137,"in_iface":"s1-suricata","event_type":"alert","src_ip":"10.0.0.5","src_port":18715,"dest_ip":"179.60.192.3","dest_port":80,"proto":"TCP","alert":{"action":"allowed","gid":1,"source":{"ip":"10.0.0.5","port":18715},"target":{"ip":"179.60.192.3","port":80},"signature_id":6,"rev":0,"signature":"Corrupted HTTP body","severity": 3,"category":"Misc activity","severity":3},"flow":{"pkts_toserver":1,"pkts_toclient":0,"bytes_toserver":174,"bytes_toclient":0,"start":"2021-05-30T20:07:13.208777+0200"}} 2 | -------------------------------------------------------------------------------- /plugins/outputs/graylog/README.md: -------------------------------------------------------------------------------- 1 | # Graylog Output Plugin 2 | 3 | This plugin writes to a Graylog instance using the "[GELF][]" format. 4 | 5 | [GELF]: https://docs.graylog.org/en/3.1/pages/gelf.html#gelf-payload-specification 6 | 7 | ### Configuration: 8 | 9 | ```toml 10 | [[outputs.graylog]] 11 | ## UDP endpoint for your graylog instances. 12 | servers = ["127.0.0.1:12201"] 13 | 14 | ## The field to use as the GELF short_message, if unset the static string 15 | ## "telegraf" will be used. 16 | ## example: short_message_field = "message" 17 | # short_message_field = "" 18 | ``` 19 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/object/telegraf.conf: -------------------------------------------------------------------------------- 1 | [[inputs.file]] 2 | files = ["./testdata/object/input.json"] 3 | data_format = "json_v2" 4 | [[inputs.file.json_v2]] 5 | measurement_name = "bart_json_v2" 6 | [[inputs.file.json_v2.object]] 7 | path = "root.station" 8 | disable_prepend_keys = true 9 | included_keys = ["etd_estimate_minutes"] 10 | tags = ["name", "etd_destination"] 11 | [inputs.file.json_v2.object.fields] 12 | etd_estimate_minutes = "int" 13 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/complex_nesting/expected.out: -------------------------------------------------------------------------------- 1 | file,properties_place=Antelope\ Valley\,\ CA geometry_coordinates=-119.4998333,geometry_type="Point",id="nc73584926",properties_mag=6,properties_updated=1.626277167263e+12,type="Feature" 2 | file,properties_place=Antelope\ Valley\,\ CA geometry_coordinates=38.5075,geometry_type="Point",id="nc73584926",properties_mag=6,properties_updated=1.626277167263e+12,type="Feature" 3 | file,properties_place=Antelope\ Valley\,\ CA geometry_coordinates=7.45,geometry_type="Point",id="nc73584926",properties_mag=6,properties_updated=1.626277167263e+12,type="Feature" 4 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/fields_and_tags/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example taken from: https://github.com/influxdata/telegraf/issues/1363 2 | 3 | [[inputs.file]] 4 | files = ["./testdata/fields_and_tags/input.json"] 5 | data_format = "json_v2" 6 | [[inputs.file.json_v2]] 7 | [[inputs.file.json_v2.tag]] 8 | path = "fields.status" 9 | [[inputs.file.json_v2.field]] 10 | path = "fields.json.#.duration" 11 | rename = "json_duration" 12 | [[inputs.file.json_v2.field]] 13 | path = "fields.duration" 14 | type = "int" 15 | -------------------------------------------------------------------------------- /plugins/inputs/processes/processes_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package processes 4 | 5 | import ( 6 | "github.com/influxdata/telegraf" 7 | "github.com/influxdata/telegraf/plugins/inputs" 8 | ) 9 | 10 | type Processes struct { 11 | Log telegraf.Logger 12 | } 13 | 14 | func (e *Processes) Init() error { 15 | e.Log.Warn("Current platform is not supported") 16 | return nil 17 | } 18 | 19 | func (e *Processes) Gather(acc telegraf.Accumulator) error { 20 | return nil 21 | } 22 | 23 | func init() { 24 | inputs.Add("processes", func() telegraf.Input { 25 | return &Processes{} 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /plugins/inputs/rabbitmq/testdata/set1/exchanges.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "message_stats": { 4 | "publish_in_details": { 5 | "rate": 3.2 6 | }, 7 | "publish_in": 3678, 8 | "publish_out_details": { 9 | "rate": 5.1 10 | }, 11 | "publish_out": 3677 12 | }, 13 | "user_who_performed_action": "mistral_testuser_1", 14 | "arguments": {}, 15 | "internal": false, 16 | "auto_delete": true, 17 | "durable": false, 18 | "type": "direct", 19 | "vhost": "sorandomsorandom", 20 | "name": "reply_a716f0523cd44941ad2ea6ce4a3869c3" 21 | } 22 | ] -------------------------------------------------------------------------------- /plugins/parsers/xpath/testcases/addressbook.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package addressbook; 4 | 5 | message Person { 6 | string name = 1; 7 | int32 id = 2; // Unique ID number for this person. 8 | string email = 3; 9 | uint32 age = 4; 10 | 11 | enum PhoneType { 12 | MOBILE = 0; 13 | HOME = 1; 14 | WORK = 2; 15 | } 16 | 17 | message PhoneNumber { 18 | string number = 1; 19 | PhoneType type = 2; 20 | } 21 | 22 | repeated PhoneNumber phones = 5; 23 | } 24 | 25 | message AddressBook { 26 | repeated Person people = 1; 27 | repeated string tags = 2; 28 | } 29 | -------------------------------------------------------------------------------- /plugins/inputs/kernel/kernel_notlinux.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package kernel 4 | 5 | import ( 6 | "github.com/influxdata/telegraf" 7 | "github.com/influxdata/telegraf/plugins/inputs" 8 | ) 9 | 10 | type Kernel struct { 11 | } 12 | 13 | func (k *Kernel) Description() string { 14 | return "Get kernel statistics from /proc/stat" 15 | } 16 | 17 | func (k *Kernel) SampleConfig() string { return "" } 18 | 19 | func (k *Kernel) Gather(acc telegraf.Accumulator) error { 20 | return nil 21 | } 22 | 23 | func init() { 24 | inputs.Add("kernel", func() telegraf.Input { 25 | return &Kernel{} 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /plugins/inputs/webhooks/mandrill/mandrill_webhooks_events.go: -------------------------------------------------------------------------------- 1 | package mandrill 2 | 3 | type Event interface { 4 | Tags() map[string]string 5 | Fields() map[string]interface{} 6 | } 7 | 8 | type MandrillEvent struct { 9 | EventName string `json:"event"` 10 | TimeStamp int64 `json:"ts"` 11 | ID string `json:"_id"` 12 | } 13 | 14 | func (me *MandrillEvent) Tags() map[string]string { 15 | return map[string]string{ 16 | "event": me.EventName, 17 | } 18 | } 19 | 20 | func (me *MandrillEvent) Fields() map[string]interface{} { 21 | return map[string]interface{}{ 22 | "id": me.ID, 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /aggregator.go: -------------------------------------------------------------------------------- 1 | package telegraf 2 | 3 | // Aggregator is an interface for implementing an Aggregator plugin. 4 | // the RunningAggregator wraps this interface and guarantees that 5 | // Add, Push, and Reset can not be called concurrently, so locking is not 6 | // required when implementing an Aggregator plugin. 7 | type Aggregator interface { 8 | PluginDescriber 9 | 10 | // Add the metric to the aggregator. 11 | Add(in Metric) 12 | 13 | // Push pushes the current aggregates to the accumulator. 14 | Push(acc Accumulator) 15 | 16 | // Reset resets the aggregators caches and aggregates. 17 | Reset() 18 | } 19 | -------------------------------------------------------------------------------- /plugins/common/proxy/proxy.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "net/url" 7 | ) 8 | 9 | type HTTPProxy struct { 10 | HTTPProxyURL string `toml:"http_proxy_url"` 11 | } 12 | 13 | type proxyFunc func(req *http.Request) (*url.URL, error) 14 | 15 | func (p *HTTPProxy) Proxy() (proxyFunc, error) { 16 | if len(p.HTTPProxyURL) > 0 { 17 | url, err := url.Parse(p.HTTPProxyURL) 18 | if err != nil { 19 | return nil, fmt.Errorf("error parsing proxy url %q: %w", p.HTTPProxyURL, err) 20 | } 21 | return http.ProxyURL(url), nil 22 | } 23 | return http.ProxyFromEnvironment, nil 24 | } 25 | -------------------------------------------------------------------------------- /plugins/inputs/execd/shim/goshim_posix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package shim 4 | 5 | import ( 6 | "context" 7 | "os" 8 | "os/signal" 9 | "syscall" 10 | ) 11 | 12 | func listenForCollectMetricsSignals(ctx context.Context, collectMetricsPrompt chan os.Signal) { 13 | // just listen to all the signals. 14 | signal.Notify(collectMetricsPrompt, syscall.SIGHUP, syscall.SIGUSR1, syscall.SIGUSR2) 15 | 16 | go func() { 17 | select { 18 | case <-ctx.Done(): 19 | // context done. stop to signals to avoid pushing messages to a closed channel 20 | signal.Stop(collectMetricsPrompt) 21 | } 22 | }() 23 | } 24 | -------------------------------------------------------------------------------- /plugins/inputs/infiniband/infiniband.go: -------------------------------------------------------------------------------- 1 | package infiniband 2 | 3 | import ( 4 | "github.com/influxdata/telegraf" 5 | ) 6 | 7 | // Stores the configuration values for the infiniband plugin - as there are no 8 | // config values, this is intentionally empty 9 | type Infiniband struct { 10 | Log telegraf.Logger `toml:"-"` 11 | } 12 | 13 | // Sample configuration for plugin 14 | var InfinibandConfig = `` 15 | 16 | func (i *Infiniband) SampleConfig() string { 17 | return InfinibandConfig 18 | } 19 | 20 | func (i *Infiniband) Description() string { 21 | return "Gets counters from all InfiniBand cards and ports installed" 22 | } 23 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/ratio.star: -------------------------------------------------------------------------------- 1 | # Compute the ratio of two integer fields. 2 | # 3 | # Example: A new field 'usage' from an existing fields 'used' and 'total' 4 | # 5 | # Example Input: 6 | # memory,host=hostname used=11038756864.4948,total=17179869184.1221 1597255082000000000 7 | # 8 | # Example Output: 9 | # memory,host=hostname used=11038756864.4948,total=17179869184.1221,usage=64.25402164701573 1597255082000000000 10 | 11 | def apply(metric): 12 | used = float(metric.fields['used']) 13 | total = float(metric.fields['total']) 14 | metric.fields['usage'] = (used / total) * 100 15 | return metric 16 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/types/expected.out: -------------------------------------------------------------------------------- 1 | file explicitstringtypeName="Bilbo",defaultstringtypeName="Baggins",convertbooltostringName="true",convertinttostringName="1",convertfloattostringName="1.1" 2 | file defaultinttypeName=2,convertfloatointName=3i,convertstringtointName=4i,convertbooltointName=0i,explicitinttypeName=1i,uinttype=1u 3 | file convertstringtofloatName=4.1,explicitfloattypeName=1.1,defaultfloattypeName=2.1,convertintotfloatName=3 4 | file explicitbooltypeName=true,defaultbooltypeName=false,convertinttoboolName=true,convertstringtoboolName=false,convertintstringtoboolTrueName=true,convertintstringtoboolFalseName=false 5 | -------------------------------------------------------------------------------- /plugins/inputs/procstat/native_finder_test.go: -------------------------------------------------------------------------------- 1 | package procstat 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | ) 8 | 9 | func BenchmarkPattern(b *testing.B) { 10 | f, err := NewNativeFinder() 11 | require.NoError(b, err) 12 | for n := 0; n < b.N; n++ { 13 | _, err := f.Pattern(".*") 14 | if err != nil { 15 | panic(err) 16 | } 17 | } 18 | } 19 | 20 | func BenchmarkFullPattern(b *testing.B) { 21 | f, err := NewNativeFinder() 22 | require.NoError(b, err) 23 | for n := 0; n < b.N; n++ { 24 | _, err := f.FullPattern(".*") 25 | if err != nil { 26 | panic(err) 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/nested_array_of_objects/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example taken from: https://github.com/influxdata/feature-requests/issues/160 2 | 3 | [[inputs.file]] 4 | files = ["./testdata/nested_array_of_objects/input.json"] 5 | data_format = "json_v2" 6 | [[inputs.file.json_v2]] 7 | measurement_name = "new_metric" 8 | [[inputs.file.json_v2.object]] 9 | path = "@this" 10 | disable_prepend_keys = true 11 | excluded_keys = ["tags", "timestamp"] 12 | tags = ["name"] 13 | [inputs.file.json_v2.object.fields] 14 | data = "int" 15 | 16 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/timestamp/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "time": 1555745371410, 3 | "measurements": [ 4 | { 5 | "name": "temperature", 6 | "value": 23.4, 7 | "units": "℃" 8 | }, 9 | { 10 | "name": "moisture", 11 | "value": 5, 12 | "units": "%" 13 | }, 14 | { 15 | "name": "light", 16 | "value": 10118, 17 | "units": "lux" 18 | }, 19 | { 20 | "name": "fertility", 21 | "value": 0, 22 | "units": "us/cm" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/logging.star: -------------------------------------------------------------------------------- 1 | # Example of the way to log a message with all the supported levels 2 | # using the logger of Telegraf. 3 | # 4 | # Example Input: 5 | # log debug="a debug message" 1465839830100400201 6 | # 7 | # Example Output: 8 | # log debug="a debug message" 1465839830100400201 9 | 10 | load("logging.star", "log") 11 | # loads log.debug(), log.info(), log.warn(), log.error() 12 | 13 | def apply(metric): 14 | log.debug("debug: {}".format(metric.fields["debug"])) 15 | log.info("an info message") 16 | log.warn("a warning message") 17 | log.error("an error message") 18 | return metric 19 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Telegraf 2 | 3 | - Concepts 4 | - [Metrics][metrics] 5 | - [Input Data Formats][parsers] 6 | - [Output Data Formats][serializers] 7 | - [Aggregators & Processors][aggproc] 8 | - Administration 9 | - [Configuration][conf] 10 | - [Profiling][profiling] 11 | - [Windows Service][winsvc] 12 | - [FAQ][faq] 13 | 14 | [conf]: /docs/CONFIGURATION.md 15 | [metrics]: /docs/METRICS.md 16 | [parsers]: /docs/DATA_FORMATS_INPUT.md 17 | [serializers]: /docs/DATA_FORMATS_OUTPUT.md 18 | [aggproc]: /docs/AGGREGATORS_AND_PROCESSORS.md 19 | [profiling]: /docs/PROFILING.md 20 | [winsvc]: /docs/WINDOWS_SERVICE.md 21 | [faq]: /docs/FAQ.md 22 | -------------------------------------------------------------------------------- /plugins/inputs/jolokia2/examples/zookeeper.conf: -------------------------------------------------------------------------------- 1 | [[inputs.jolokia2_agent]] 2 | urls = ["http://localhost:8080/jolokia"] 3 | name_prefix = "zk_" 4 | 5 | [[inputs.jolokia2_agent.metric]] 6 | name = "quorum" 7 | mbean = "org.apache.ZooKeeperService:name0=*" 8 | tag_keys = ["name0"] 9 | 10 | [[inputs.jolokia2_agent.metric]] 11 | name = "leader" 12 | mbean = "org.apache.ZooKeeperService:name0=*,name1=*,name2=Leader" 13 | tag_keys = ["name1"] 14 | 15 | [[inputs.jolokia2_agent.metric]] 16 | name = "follower" 17 | mbean = "org.apache.ZooKeeperService:name0=*,name1=*,name2=Follower" 18 | tag_keys = ["name1"] 19 | -------------------------------------------------------------------------------- /plugins/outputs/discard/discard.go: -------------------------------------------------------------------------------- 1 | package discard 2 | 3 | import ( 4 | "github.com/influxdata/telegraf" 5 | "github.com/influxdata/telegraf/plugins/outputs" 6 | ) 7 | 8 | type Discard struct{} 9 | 10 | func (d *Discard) Connect() error { return nil } 11 | func (d *Discard) Close() error { return nil } 12 | func (d *Discard) SampleConfig() string { return "" } 13 | func (d *Discard) Description() string { return "Send metrics to nowhere at all" } 14 | func (d *Discard) Write(_ []telegraf.Metric) error { 15 | return nil 16 | } 17 | 18 | func init() { 19 | outputs.Add("discard", func() telegraf.Output { return &Discard{} }) 20 | } 21 | -------------------------------------------------------------------------------- /scripts/alpine.docker: -------------------------------------------------------------------------------- 1 | FROM golang:1.16.6 as builder 2 | WORKDIR /go/src/github.com/influxdata/telegraf 3 | 4 | COPY . /go/src/github.com/influxdata/telegraf 5 | RUN CGO_ENABLED=0 make go-install 6 | 7 | FROM alpine:3.12 8 | RUN echo 'hosts: files dns' >> /etc/nsswitch.conf 9 | RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors && \ 10 | update-ca-certificates 11 | COPY --from=builder /go/bin/* /usr/bin/ 12 | COPY etc/telegraf.conf /etc/telegraf/telegraf.conf 13 | 14 | EXPOSE 8125/udp 8092/udp 8094 15 | 16 | COPY scripts/docker-entrypoint.sh /entrypoint.sh 17 | ENTRYPOINT ["/entrypoint.sh"] 18 | CMD ["telegraf"] 19 | -------------------------------------------------------------------------------- /plugins/processors/template/template_metric.go: -------------------------------------------------------------------------------- 1 | package template 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/influxdata/telegraf" 7 | ) 8 | 9 | type TemplateMetric struct { 10 | metric telegraf.Metric 11 | } 12 | 13 | func (m *TemplateMetric) Name() string { 14 | return m.metric.Name() 15 | } 16 | 17 | func (m *TemplateMetric) Tag(key string) string { 18 | tagString, _ := m.metric.GetTag(key) 19 | return tagString 20 | } 21 | 22 | func (m *TemplateMetric) Field(key string) interface{} { 23 | field, _ := m.metric.GetField(key) 24 | return field 25 | } 26 | 27 | func (m *TemplateMetric) Time() time.Time { 28 | return m.metric.Time() 29 | } 30 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/multiple_arrays_in_object/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "book": { 3 | "title": "The Lord Of The Rings", 4 | "chapters": [ 5 | "A Long-expected Party", 6 | "The Shadow of the Past" 7 | ], 8 | "author": "Tolkien", 9 | "characters": [ 10 | { 11 | "name": "Bilbo", 12 | "species": "hobbit" 13 | }, 14 | { 15 | "name": "Frodo", 16 | "species": "hobbit" 17 | } 18 | ], 19 | "random": [ 20 | 1, 21 | 2 22 | ] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/value_filter.star: -------------------------------------------------------------------------------- 1 | # Filter metrics by value 2 | ''' 3 | In this example we look at the `value` field of the metric. 4 | If the value is zeor, we delete all the fields, effectively dropping the metric. 5 | 6 | Example Input: 7 | temperature sensor="001A0",value=111.48 1618488000000000999 8 | temperature sensor="001B0",value=0.0 1618488000000000999 9 | 10 | Example Output: 11 | temperature sensor="001A0",value=111.48 1618488000000000999 12 | ''' 13 | 14 | def apply(metric): 15 | if metric.fields["value"] == 0.0: 16 | # removing all fields deletes a metric 17 | metric.fields.clear() 18 | return metric 19 | -------------------------------------------------------------------------------- /plugins/aggregators/all/all.go: -------------------------------------------------------------------------------- 1 | package all 2 | 3 | import ( 4 | //Blank imports for plugins to register themselves 5 | _ "github.com/influxdata/telegraf/plugins/aggregators/basicstats" 6 | _ "github.com/influxdata/telegraf/plugins/aggregators/derivative" 7 | _ "github.com/influxdata/telegraf/plugins/aggregators/final" 8 | _ "github.com/influxdata/telegraf/plugins/aggregators/histogram" 9 | _ "github.com/influxdata/telegraf/plugins/aggregators/merge" 10 | _ "github.com/influxdata/telegraf/plugins/aggregators/minmax" 11 | _ "github.com/influxdata/telegraf/plugins/aggregators/quantile" 12 | _ "github.com/influxdata/telegraf/plugins/aggregators/valuecounter" 13 | ) 14 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/nested_and_nonnested_tags/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example taken from: https://github.com/influxdata/telegraf/issues/6437 2 | 3 | # Parse String types from JSON 4 | [[inputs.file]] 5 | files = ["./testdata/nested_and_nonnested_tags/input.json"] 6 | data_format = "json_v2" 7 | [[inputs.file.json_v2]] 8 | [[inputs.file.json_v2.object]] 9 | disable_prepend_keys = true 10 | path = "@this" 11 | included_keys = [ 12 | "systemVoltage", 13 | "systemCurrent", 14 | "tables", 15 | ] 16 | tags = ["hostname", "tables_outputname"] 17 | -------------------------------------------------------------------------------- /plugins/inputs/snmp/testdata/snmpd.conf: -------------------------------------------------------------------------------- 1 | # This config provides the data represented in the plugin documentation 2 | # Requires net-snmp >= 5.7 3 | 4 | #agentaddress UDP:127.0.0.1:1161 5 | rocommunity public 6 | 7 | override .1.0.0.0.1.1.0 octet_str "foo" 8 | override .1.0.0.0.1.1.1 octet_str "bar" 9 | override .1.0.0.0.1.102 octet_str "bad" 10 | override .1.0.0.0.1.2.0 integer 1 11 | override .1.0.0.0.1.2.1 integer 2 12 | override .1.0.0.0.1.3.0 octet_str "0.123" 13 | override .1.0.0.0.1.3.1 octet_str "0.456" 14 | override .1.0.0.0.1.3.2 octet_str "9.999" 15 | override .1.0.0.1.1 octet_str "baz" 16 | override .1.0.0.1.2 uinteger 54321 17 | override .1.0.0.1.3 uinteger 234 18 | -------------------------------------------------------------------------------- /plugins/parsers/influx/README.md: -------------------------------------------------------------------------------- 1 | # InfluxDB Line Protocol 2 | 3 | There are no additional configuration options for InfluxDB [line protocol][]. The 4 | metrics are parsed directly into Telegraf metrics. 5 | 6 | [line protocol]: https://docs.influxdata.com/influxdb/latest/reference/syntax/line-protocol/ 7 | 8 | ### Configuration 9 | 10 | ```toml 11 | [[inputs.file]] 12 | files = ["example"] 13 | 14 | ## Data format to consume. 15 | ## Each data format has its own unique set of configuration options, read 16 | ## more about them here: 17 | ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md 18 | data_format = "influx" 19 | ``` 20 | 21 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/json.star: -------------------------------------------------------------------------------- 1 | # Example of parsing json out of a field and modifying the metric with it. 2 | # this is great to use in conjunction with the value parser. 3 | # 4 | # Example Input: 5 | # json value="{\"label\": \"hero\", \"count\": 14}" 1465839830100400201 6 | # 7 | # Example Output: 8 | # json,label=hero count=14i 1465839830100400201 9 | 10 | load("json.star", "json") 11 | # loads json.encode(), json.decode(), json.indent() 12 | 13 | def apply(metric): 14 | j = json.decode(metric.fields.get('value')) 15 | metric.fields.pop('value') 16 | metric.tags["label"] = j["label"] 17 | metric.fields["count"] = j["count"] 18 | return metric 19 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/time_duration.star: -------------------------------------------------------------------------------- 1 | # Example of parsing a duration out of a field and modifying the metric to inject the equivalent in seconds. 2 | # 3 | # Example Input: 4 | # time value="3m35s" 1465839830100400201 5 | # 6 | # Example Output: 7 | # time seconds=215 1465839830100400201 8 | 9 | load('time.star', 'time') 10 | # loads time.parse_duration(), time.is_valid_timezone(), time.now(), time.time(), 11 | # time.parse_time() and time.from_timestamp() 12 | 13 | def apply(metric): 14 | duration = time.parse_duration(metric.fields.get('value')) 15 | metric.fields.pop('value') 16 | metric.fields["seconds"] = duration.seconds 17 | return metric 18 | -------------------------------------------------------------------------------- /plugins/inputs/knx_listener/knx_dummy_interface.go: -------------------------------------------------------------------------------- 1 | package knx_listener 2 | 3 | import ( 4 | "github.com/vapourismo/knx-go/knx" 5 | ) 6 | 7 | type KNXDummyInterface struct { 8 | inbound chan knx.GroupEvent 9 | } 10 | 11 | func NewDummyInterface() (di KNXDummyInterface, err error) { 12 | di, err = KNXDummyInterface{}, nil 13 | di.inbound = make(chan knx.GroupEvent) 14 | 15 | return di, err 16 | } 17 | 18 | func (di *KNXDummyInterface) Send(event knx.GroupEvent) { 19 | di.inbound <- event 20 | } 21 | 22 | func (di *KNXDummyInterface) Inbound() <-chan knx.GroupEvent { 23 | return di.inbound 24 | } 25 | 26 | func (di *KNXDummyInterface) Close() { 27 | close(di.inbound) 28 | } 29 | -------------------------------------------------------------------------------- /plugins/parsers/xpath/testcases/tracker_msgpack.conf: -------------------------------------------------------------------------------- 1 | # Example for parsing openweathermap five-day-forecast data. 2 | # 3 | # File: 4 | # testcases/tracker.msg xpath_msgpack 5 | # 6 | # Expected Output: 7 | # tracker,device=TrackerA,fixation=true serial="123abc456def",lat=37.78980863758897,lon=-122.39931057256935,quality=2i 1624528552000000000 8 | # 9 | 10 | metric_name = "'tracker'" 11 | timestamp = "timestamp" 12 | timestamp_format = "unix" 13 | 14 | [tags] 15 | device = "device" 16 | fixation = "info/fix" 17 | 18 | [fields_int] 19 | quality = "info/quality" 20 | 21 | [fields] 22 | serial = "info/serial_number" 23 | lat = "number(/geo/*[1])" 24 | lon = "number(/geo/*[2])" 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Support.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Support request 3 | labels: support 4 | about: Open a support request 5 | 6 | --- 7 | 8 | 23 | -------------------------------------------------------------------------------- /plugins/inputs/suricata/testdata/test2.json: -------------------------------------------------------------------------------- 1 | { 2 | "timestamp": "2021-06-08T06:34:49.237367+0000", 3 | "event_type": "stats", 4 | "stats": { 5 | "threads": { 6 | "W#01-ens2f1": { 7 | "detect": { 8 | "engines": [ 9 | { 10 | "id": 0, 11 | "last_reload": "2021-06-08T06:33:05.084872+0000", 12 | "rules_loaded": 22712, 13 | "rules_failed": 0 14 | } 15 | ], 16 | "alert": 0 17 | } 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /plugins/inputs/trig/trig_test.go: -------------------------------------------------------------------------------- 1 | package trig 2 | 3 | import ( 4 | "math" 5 | "testing" 6 | 7 | "github.com/influxdata/telegraf/testutil" 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestTrig(t *testing.T) { 12 | s := &Trig{ 13 | Amplitude: 10.0, 14 | } 15 | 16 | for i := 0.0; i < 10.0; i++ { 17 | var acc testutil.Accumulator 18 | 19 | sine := math.Sin((i*math.Pi)/5.0) * s.Amplitude 20 | cosine := math.Cos((i*math.Pi)/5.0) * s.Amplitude 21 | 22 | require.NoError(t, s.Gather(&acc)) 23 | 24 | fields := make(map[string]interface{}) 25 | fields["sine"] = sine 26 | fields["cosine"] = cosine 27 | 28 | acc.AssertContainsFields(t, "trig", fields) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/nested_tags_complex/telegraf.conf: -------------------------------------------------------------------------------- 1 | # Example taken from: https://github.com/influxdata/telegraf/issues/6853 2 | 3 | [[inputs.file]] 4 | files = ["./testdata/nested_tags_complex/input.json"] 5 | data_format = "json_v2" 6 | [[inputs.file.json_v2]] 7 | [[inputs.file.json_v2.object]] 8 | path = "Group A" 9 | disable_prepend_keys = true 10 | tags = ["Sub-group_1_Firmware", "Sub-group_1_Model", "Sub-group_1_Serial"] 11 | [[inputs.file.json_v2.object]] 12 | path = "Group B" 13 | disable_prepend_keys = true 14 | tags = ["Sub-group_1_Firmware", "Sub-group_1_Model", "Sub-group_1_Serial"] 15 | -------------------------------------------------------------------------------- /plugins/inputs/ravendb/testdata/indexes_min.json: -------------------------------------------------------------------------------- 1 | { 2 | "PublicServerUrl": null, 3 | "NodeTag": "A", 4 | "Results": [ 5 | { 6 | "DatabaseName": "db1", 7 | "Indexes": [ 8 | { 9 | "IndexName": "Product/Rating", 10 | "Priority": "Normal", 11 | "State": "Normal", 12 | "Errors": 0, 13 | "TimeSinceLastQueryInSec": null, 14 | "TimeSinceLastIndexingInSec": null, 15 | "LockMode": "Unlock", 16 | "IsInvalid": false, 17 | "Status": "Running", 18 | "MappedPerSec": 102.34, 19 | "ReducedPerSec": 593.23, 20 | "Type": "MapReduce" 21 | } 22 | ] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /plugins/inputs/webhooks/filestack/README.md: -------------------------------------------------------------------------------- 1 | # Filestack webhook 2 | 3 | You should configure your Filestack's Webhooks to point at the `webhooks` service. To do this go to [filestack.com](https://www.filestack.com/), select your app and click `Credentials > Webhooks`. In the resulting page, set the `URL` to `http://:1619/filestack`, and click on `Add`. 4 | 5 | ## Events 6 | 7 | See the [webhook doc](https://www.filestack.com/docs/webhooks). 8 | 9 | *Limitations*: It stores all events except video conversions events. 10 | 11 | All events for logs the original timestamp, the action and the id. 12 | 13 | **Tags:** 14 | * 'action' = `event.action` string 15 | 16 | **Fields:** 17 | * 'id' = `event.id` string 18 | -------------------------------------------------------------------------------- /metric/series_grouper_test.go: -------------------------------------------------------------------------------- 1 | package metric 2 | 3 | import ( 4 | "hash/maphash" 5 | "testing" 6 | "time" 7 | ) 8 | 9 | var m = New( 10 | "mymetric", 11 | map[string]string{ 12 | "host": "host.example.com", 13 | "mykey": "myvalue", 14 | "another key": "another value", 15 | }, 16 | map[string]interface{}{ 17 | "f1": 1, 18 | "f2": 2, 19 | "f3": 3, 20 | "f4": 4, 21 | "f5": 5, 22 | "f6": 6, 23 | "f7": 7, 24 | "f8": 8, 25 | }, 26 | time.Now(), 27 | ) 28 | 29 | var result uint64 30 | 31 | var hashSeed = maphash.MakeSeed() 32 | 33 | func BenchmarkGroupID(b *testing.B) { 34 | for n := 0; n < b.N; n++ { 35 | result = groupID(hashSeed, m.Name(), m.TagList(), m.Time()) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /plugins/processors/dedup/README.md: -------------------------------------------------------------------------------- 1 | # Dedup Processor Plugin 2 | 3 | Filter metrics whose field values are exact repetitions of the previous values. 4 | 5 | ### Configuration 6 | 7 | ```toml 8 | [[processors.dedup]] 9 | ## Maximum time to suppress output 10 | dedup_interval = "600s" 11 | ``` 12 | 13 | ### Example 14 | 15 | ```diff 16 | - cpu,cpu=cpu0 time_idle=42i,time_guest=1i 17 | - cpu,cpu=cpu0 time_idle=42i,time_guest=2i 18 | - cpu,cpu=cpu0 time_idle=42i,time_guest=2i 19 | - cpu,cpu=cpu0 time_idle=44i,time_guest=2i 20 | - cpu,cpu=cpu0 time_idle=44i,time_guest=2i 21 | + cpu,cpu=cpu0 time_idle=42i,time_guest=1i 22 | + cpu,cpu=cpu0 time_idle=42i,time_guest=2i 23 | + cpu,cpu=cpu0 time_idle=44i,time_guest=2i 24 | ``` 25 | -------------------------------------------------------------------------------- /plugins/parsers/wavefront/README.md: -------------------------------------------------------------------------------- 1 | # Wavefront 2 | 3 | Wavefront Data Format is metrics are parsed directly into Telegraf metrics. 4 | For more information about the Wavefront Data Format see 5 | [here](https://docs.wavefront.com/wavefront_data_format.html). 6 | 7 | ### Configuration 8 | 9 | There are no additional configuration options for Wavefront Data Format line-protocol. 10 | 11 | ```toml 12 | [[inputs.file]] 13 | files = ["example"] 14 | 15 | ## Data format to consume. 16 | ## Each data format has its own unique set of configuration options, read 17 | ## more about them here: 18 | ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md 19 | data_format = "wavefront" 20 | ``` 21 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/rename.star: -------------------------------------------------------------------------------- 1 | # Rename any tags using the mapping in the renames dict. 2 | # 3 | # Example Input: 4 | # measurement,host=hostname lower=0,upper=100 1597255410000000000 5 | # 6 | # Example Output: 7 | # measurement,host=hostname min=0,max=100 1597255410000000000 8 | 9 | renames = { 10 | 'lower': 'min', 11 | 'upper': 'max', 12 | } 13 | 14 | def apply(metric): 15 | for k, v in metric.tags.items(): 16 | if k in renames: 17 | metric.tags[renames[k]] = v 18 | metric.tags.pop(k) 19 | for k, v in metric.fields.items(): 20 | if k in renames: 21 | metric.fields[renames[k]] = v 22 | metric.fields.pop(k) 23 | return metric 24 | -------------------------------------------------------------------------------- /plugins/inputs/kube_inventory/client_test.go: -------------------------------------------------------------------------------- 1 | package kube_inventory 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | "github.com/influxdata/telegraf/plugins/common/tls" 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | type mockHandler struct { 12 | responseMap map[string]interface{} 13 | } 14 | 15 | func toStrPtr(s string) *string { 16 | return &s 17 | } 18 | 19 | func toInt32Ptr(i int32) *int32 { 20 | return &i 21 | } 22 | 23 | func toBoolPtr(b bool) *bool { 24 | return &b 25 | } 26 | 27 | func TestNewClient(t *testing.T) { 28 | _, err := newClient("https://127.0.0.1:443/", "default", "abc123", time.Second, tls.ClientConfig{}) 29 | require.NoErrorf(t, err, "Failed to create new client - %v", err) 30 | } 31 | -------------------------------------------------------------------------------- /plugins/inputs/ravendb/testdata/indexes_full.json: -------------------------------------------------------------------------------- 1 | { 2 | "PublicServerUrl": "http://localhost:8080", 3 | "NodeTag": "A", 4 | "Results": [ 5 | { 6 | "DatabaseName": "db1", 7 | "Indexes": [ 8 | { 9 | "IndexName": "Product/Rating", 10 | "Priority": "Normal", 11 | "State": "Normal", 12 | "Errors": 0, 13 | "TimeSinceLastQueryInSec": 3.4712567, 14 | "TimeSinceLastIndexingInSec": 3.4642612, 15 | "LockMode": "Unlock", 16 | "IsInvalid": true, 17 | "Status": "Running", 18 | "MappedPerSec": 102.34, 19 | "ReducedPerSec": 593.23, 20 | "Type": "MapReduce" 21 | } 22 | ] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /plugins/inputs/exec/dev/telegraf.conf: -------------------------------------------------------------------------------- 1 | [agent] 2 | interval="1s" 3 | flush_interval="1s" 4 | 5 | [[inputs.exec]] 6 | timeout = "1s" 7 | data_format = "influx" 8 | commands = [ 9 | "echo 'deal,computer_name=hosta message=\"stuff\" 1530654676316265790'", 10 | "echo 'deal,computer_name=hostb message=\"stuff\" 1530654676316265790'", 11 | ] 12 | 13 | [[processors.regex]] 14 | [[processors.regex.tags]] 15 | key = "computer_name" 16 | pattern = "^(.*?)a$" 17 | replacement = "${1}" 18 | result_key = "server_name" 19 | [[processors.regex.tags]] 20 | key = "computer_name" 21 | pattern = "^(.*?)b$" 22 | replacement = "${1}" 23 | result_key = "server_name" 24 | 25 | [[outputs.file]] 26 | files = ["stdout"] 27 | -------------------------------------------------------------------------------- /testutil/pki/cacert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB0TCCATqgAwIBAgIJAMgbq6rkA4b/MA0GCSqGSIb3DQEBCwUAMBsxGTAXBgNV 3 | BAMMEFRlbGVncmFmIFRlc3QgQ0EwHhcNMTgwNTAzMDEwNTI5WhcNMjgwNDMwMDEw 4 | NTI5WjAbMRkwFwYDVQQDDBBUZWxlZ3JhZiBUZXN0IENBMIGfMA0GCSqGSIb3DQEB 5 | AQUAA4GNADCBiQKBgQDTySxyXeyQQjCOtNQ/7cKtXN91sp4B1k7whPKBO6yXEFFR 6 | rYaw76xY5CTTPTJaAPBJ+amHPdPGfmGq6yX10tjAaWQQYV26Axngfpti6F14ci0/ 7 | X/sTay8ii/4Du5DRr9f9rHVimPASR1fkgK+IFhXnONn1R+pNbHYmGS4OVNyoPwID 8 | AQABox0wGzAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIBBjANBgkqhkiG9w0BAQsF 9 | AAOBgQA9v3eMU33q+bGPEd65kKQcVddPEFdSqmuUJMeO2VQmUFc/ejkP48u42eDK 10 | Y1GAR+209XgkuWItEBH8HJysOU2plunuIPXpnPcxyP30tpFVLaWzWTQvUehhYpfQ 11 | C0v9Re3jdLfLORxiaAPyyKogMpAQrjGX+u1aMSOCkcTD2Hjvbw== 12 | -----END CERTIFICATE----- 13 | -------------------------------------------------------------------------------- /input.go: -------------------------------------------------------------------------------- 1 | package telegraf 2 | 3 | type Input interface { 4 | PluginDescriber 5 | 6 | // Gather takes in an accumulator and adds the metrics that the Input 7 | // gathers. This is called every agent.interval 8 | Gather(Accumulator) error 9 | } 10 | 11 | type ServiceInput interface { 12 | Input 13 | 14 | // Start the ServiceInput. The Accumulator may be retained and used until 15 | // Stop returns. 16 | Start(Accumulator) error 17 | 18 | // Stop stops the services and closes any necessary channels and connections. 19 | // Metrics should not be written out to the accumulator once stop returns, so 20 | // Stop() should stop reading and wait for any in-flight metrics to write out 21 | // to the accumulator before returning. 22 | Stop() 23 | } 24 | -------------------------------------------------------------------------------- /plugins/inputs/execd/execd_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package execd 4 | 5 | import ( 6 | "fmt" 7 | "io" 8 | "os" 9 | "time" 10 | 11 | "github.com/influxdata/telegraf" 12 | ) 13 | 14 | func (e *Execd) Gather(acc telegraf.Accumulator) error { 15 | if e.process == nil { 16 | return nil 17 | } 18 | 19 | switch e.Signal { 20 | case "STDIN": 21 | if osStdin, ok := e.process.Stdin.(*os.File); ok { 22 | osStdin.SetWriteDeadline(time.Now().Add(1 * time.Second)) 23 | } 24 | if _, err := io.WriteString(e.process.Stdin, "\n"); err != nil { 25 | return fmt.Errorf("Error writing to stdin: %s", err) 26 | } 27 | case "none": 28 | default: 29 | return fmt.Errorf("invalid signal: %s", e.Signal) 30 | } 31 | 32 | return nil 33 | } 34 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/types/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "explicitstringtype": "Bilbo", 3 | "defaultstringtype": "Baggins", 4 | "convertbooltostring": true, 5 | "convertinttostring": 1, 6 | "convertfloattostring": 1.1, 7 | "explicitinttype": 1, 8 | "defaultinttype": 2, 9 | "convertfloatoint": 3.1, 10 | "convertstringtoint": "4", 11 | "convertbooltoint": false, 12 | "explicitfloattype": 1.1, 13 | "defaultfloattype": 2.1, 14 | "convertintotfloat": 3, 15 | "convertstringtofloat": "4.1", 16 | "explicitbooltype": true, 17 | "defaultbooltype": false, 18 | "convertinttobool": 1, 19 | "convertstringtobool": "false", 20 | "convertintstringtoboolTrue": "1", 21 | "convertintstringtoboolFalse": "0" 22 | } 23 | -------------------------------------------------------------------------------- /plugins/inputs/rabbitmq/testdata/set1/memory.json: -------------------------------------------------------------------------------- 1 | { 2 | "memory": { 3 | "connection_readers": 1234, 4 | "connection_writers": 5678, 5 | "connection_channels": 1133, 6 | "connection_other": 2840, 7 | "queue_procs": 2840, 8 | "queue_slave_procs": 0, 9 | "plugins": 1755976, 10 | "other_proc": 23056584, 11 | "metrics": 196536, 12 | "mgmt_db": 491272, 13 | "mnesia": 115600, 14 | "other_ets": 2121872, 15 | "binary": 418848, 16 | "msg_index": 42848, 17 | "code": 25179322, 18 | "atom": 1041593, 19 | "other_system": 14741981, 20 | "allocated_unused": 38208528, 21 | "reserved_unallocated": 0, 22 | "total": 83025920 23 | } 24 | } -------------------------------------------------------------------------------- /plugins/inputs/webhooks/mandrill/README.md: -------------------------------------------------------------------------------- 1 | # mandrill webhook 2 | 3 | You should configure your Mandrill's Webhooks to point at the `webhooks` service. To do this go to [mandrillapp.com](https://mandrillapp.com) and click `Settings > Webhooks`. In the resulting page, click on `Add a Webhook`, select all events, and set the `URL` to `http://:1619/mandrill`, and click on `Create Webhook`. 4 | 5 | ## Events 6 | 7 | See the [webhook doc](https://mandrill.zendesk.com/hc/en-us/articles/205583307-Message-Event-Webhook-format). 8 | 9 | All events for logs the original timestamp, the event name and the unique identifier of the message that generated the event. 10 | 11 | **Tags:** 12 | * 'event' = `event.event` string 13 | 14 | **Fields:** 15 | * 'id' = `event._id` string 16 | -------------------------------------------------------------------------------- /plugins/processors/unpivot/README.md: -------------------------------------------------------------------------------- 1 | # Unpivot Processor 2 | 3 | You can use the `unpivot` processor to rotate a multi field series into single valued metrics. This transformation often results in data that is more easy to aggregate across fields. 4 | 5 | To perform the reverse operation use the [pivot] processor. 6 | 7 | ### Configuration 8 | 9 | ```toml 10 | [[processors.unpivot]] 11 | ## Tag to use for the name. 12 | tag_key = "name" 13 | ## Field to use for the name of the value. 14 | value_key = "value" 15 | ``` 16 | 17 | ### Example 18 | 19 | ```diff 20 | - cpu,cpu=cpu0 time_idle=42i,time_user=43i 21 | + cpu,cpu=cpu0,name=time_idle value=42i 22 | + cpu,cpu=cpu0,name=time_user value=43i 23 | ``` 24 | 25 | [pivot]: /plugins/processors/pivot/README.md 26 | 27 | -------------------------------------------------------------------------------- /plugins/inputs/procstat/native_finder_windows.go: -------------------------------------------------------------------------------- 1 | package procstat 2 | 3 | import ( 4 | "regexp" 5 | ) 6 | 7 | // Pattern matches on the process name 8 | func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { 9 | var pids []PID 10 | regxPattern, err := regexp.Compile(pattern) 11 | if err != nil { 12 | return pids, err 13 | } 14 | procs, err := pg.FastProcessList() 15 | if err != nil { 16 | return pids, err 17 | } 18 | for _, p := range procs { 19 | name, err := p.Name() 20 | if err != nil { 21 | //skip, this can be caused by the pid no longer existing 22 | //or you having no permissions to access it 23 | continue 24 | } 25 | if regxPattern.MatchString(name) { 26 | pids = append(pids, PID(p.Pid)) 27 | } 28 | } 29 | return pids, err 30 | } 31 | -------------------------------------------------------------------------------- /plugins/inputs/zipkin/testdata/json/distributed_trace_sample.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "trace_id": 6802735349851856000, 3 | "name": "main.dud", 4 | "id": 6802735349851856000, 5 | "parent_id": null, 6 | "annotations": [ 7 | { 8 | "timestamp": 1433330263415871, 9 | "value": "cs", 10 | "host": { 11 | "ipv4": 0, 12 | "port": 9410, 13 | "service_name": "go-zipkin-testclient" 14 | }, 15 | "duration": null 16 | }, 17 | { 18 | "timestamp": 1433330263415872, 19 | "value": "cr", 20 | "host": { 21 | "ipv4": 0, 22 | "port": 9410, 23 | "service_name": "go-zipkin-testclient" 24 | }, 25 | "duration": null 26 | } 27 | ], 28 | "binary_annotations": [], 29 | "debug": true 30 | }] 31 | -------------------------------------------------------------------------------- /scripts/check-file-changes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # To prevent the tests/builds to run for only a doc change, this script checks what files have changed in a pull request. 3 | 4 | BRANCH="$(git rev-parse --abbrev-ref HEAD)" 5 | echo $BRANCH 6 | if [[ "$BRANCH" != "master" ]] && [[ "$BRANCH" != release* ]]; then # This should never skip for master and release branches 7 | # Ask git for all the differences between this branch and master 8 | # Then use grep to look for changes in the .circleci/ directory, anything named *.go or *.mod or *.sum or *.sh or Makefile 9 | # If no match is found, then circleci step halt will stop the CI job but mark it successful 10 | git diff master --name-only --no-color | egrep -e "^(\.circleci\/.*)$|^(.*\.(go|mod|sum|sh))$|^Makefile$" || circleci step halt; 11 | fi 12 | -------------------------------------------------------------------------------- /testutil/pki/clientcert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB+TCCAWKgAwIBAgIBAjANBgkqhkiG9w0BAQsFADAbMRkwFwYDVQQDDBBUZWxl 3 | Z3JhZiBUZXN0IENBMB4XDTE4MDUwMzAxMDUyOVoXDTI4MDQzMDAxMDUyOVowHTEb 4 | MBkGA1UEAwwSY2xpZW50LmxvY2FsZG9tYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GN 5 | ADCBiQKBgQDX7Plvu0MJtA9TrusYtQnAogsdiYJZd9wfFIjH5FxE3SWJ4KAIE+yR 6 | WRqcqX8XnpieQLaNsfXhDPWLkWngTDydk4NO/jlAQk0e6+9+NeiZ2ViIHmtXERb9 7 | CyiiWUmo+YCd69lhzSEIMK9EPBSDHQTgQMtEfGak03G5rx3MCakE1QIDAQABo0sw 8 | STAJBgNVHRMEAjAAMAsGA1UdDwQEAwIHgDAaBgNVHREEEzARgglsb2NhbGhvc3SH 9 | BH8AAAEwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQELBQADgYEAVry0 10 | L07oTN+FMLncY/Be9BzFB3b3mnbxbZr58OgI4WHuOeYBuvDI033FIIIzpwb8XYpG 11 | HJkZlSbviqq19lAh/Cktl35BCNrA6Uc+dgW7QWhnYS2tZandVTo/8FFstJTNiiLw 12 | uiz/Hr3mRXUIDi5OygJHY1IZr8hFTOOJY+0ws3E= 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /testutil/pki/servercert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB+TCCAWKgAwIBAgIBATANBgkqhkiG9w0BAQsFADAbMRkwFwYDVQQDDBBUZWxl 3 | Z3JhZiBUZXN0IENBMB4XDTE4MDUwMzAxMDUyOVoXDTI4MDQzMDAxMDUyOVowHTEb 4 | MBkGA1UEAwwSc2VydmVyLmxvY2FsZG9tYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GN 5 | ADCBiQKBgQDTBmLJ0pBFUxnPkkx38sBnOKvs+OinVqxTnVcc1iCyQJQleB37uY6D 6 | L55mSsPvnad/oDpyGpHt4RVtrhmyC6ptSrWLyk7mraeAo30Cooqr5tA9A+6yj0ij 7 | ySLlYimTMQy8tbnVNWLwKbxgT9N4NlUzwyqxLWUMfRzLfmefqzk5bQIDAQABo0sw 8 | STAJBgNVHRMEAjAAMBoGA1UdEQQTMBGCCWxvY2FsaG9zdIcEfwAAATALBgNVHQ8E 9 | BAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADgYEATNnM 10 | ol0s29lJ+WkP+HUFtKaXxQ+kXLADqfhsk2G1/kZAVRHsYUDlJ+GkHnWIHlg/ggIP 11 | JS+z44iwMPOtzJQI7MvAFYVKpYAEdIFTjXf6GafLjUfoXYi0vwHoVJHtQu3Kpm9L 12 | Ugm02h0ycIadN8RdWAAFUf6XpVKUJa0YYLuyaXY= 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /plugins/inputs/procstat/native_finder_notwindows.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package procstat 4 | 5 | import ( 6 | "regexp" 7 | ) 8 | 9 | //Pattern matches on the process name 10 | func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { 11 | var pids []PID 12 | regxPattern, err := regexp.Compile(pattern) 13 | if err != nil { 14 | return pids, err 15 | } 16 | procs, err := pg.FastProcessList() 17 | if err != nil { 18 | return pids, err 19 | } 20 | for _, p := range procs { 21 | name, err := p.Exe() 22 | if err != nil { 23 | //skip, this can be caused by the pid no longer existing 24 | //or you having no permissions to access it 25 | continue 26 | } 27 | if regxPattern.MatchString(name) { 28 | pids = append(pids, PID(p.Pid)) 29 | } 30 | } 31 | return pids, err 32 | } 33 | -------------------------------------------------------------------------------- /plugins/inputs/dmcache/dmcache.go: -------------------------------------------------------------------------------- 1 | package dmcache 2 | 3 | import ( 4 | "github.com/influxdata/telegraf" 5 | "github.com/influxdata/telegraf/plugins/inputs" 6 | ) 7 | 8 | type DMCache struct { 9 | PerDevice bool `toml:"per_device"` 10 | getCurrentStatus func() ([]string, error) 11 | } 12 | 13 | var sampleConfig = ` 14 | ## Whether to report per-device stats or not 15 | per_device = true 16 | ` 17 | 18 | func (c *DMCache) SampleConfig() string { 19 | return sampleConfig 20 | } 21 | 22 | func (c *DMCache) Description() string { 23 | return "Provide a native collection for dmsetup based statistics for dm-cache" 24 | } 25 | 26 | func init() { 27 | inputs.Add("dmcache", func() telegraf.Input { 28 | return &DMCache{ 29 | PerDevice: true, 30 | getCurrentStatus: dmSetupStatus, 31 | } 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/rename_prometheus_remote_write.star: -------------------------------------------------------------------------------- 1 | # Specifically for prometheus remote write - renames the measurement name to the fieldname. Renames the fieldname to value. 2 | # Assumes there is only one field as is the case for prometheus remote write. 3 | # 4 | # Example Input: 5 | # prometheus_remote_write,instance=localhost:9090,job=prometheus,quantile=0.99 go_gc_duration_seconds=4.63 1618488000000000999 6 | # 7 | # Example Output: 8 | # go_gc_duration_seconds,instance=localhost:9090,job=prometheus,quantile=0.99 value=4.63 1618488000000000999 9 | 10 | def apply(metric): 11 | if metric.name == "prometheus_remote_write": 12 | for k, v in metric.fields.items(): 13 | metric.name = k 14 | metric.fields["value"] = v 15 | metric.fields.pop(k) 16 | return metric -------------------------------------------------------------------------------- /plugins/inputs/puppetagent/last_run_summary.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | events: 3 | failure: 0 4 | total: 0 5 | success: 0 6 | resources: 7 | failed: 0 8 | scheduled: 0 9 | changed: 0 10 | skipped: 0 11 | total: 109 12 | failed_to_restart: 0 13 | restarted: 0 14 | out_of_sync: 0 15 | changes: 16 | total: 0 17 | time: 18 | user: 0.004331 19 | schedule: 0.001123 20 | filebucket: 0.000353 21 | file: 0.441472 22 | exec: 0.508123 23 | anchor: 0.000555 24 | yumrepo: 0.006989 25 | ssh_authorized_key: 0.000764 26 | service: 1.807795 27 | package: 1.325788 28 | total: 8.85354707064819 29 | config_retrieval: 4.75567007064819 30 | last_run: 1444936531 31 | cron: 0.000584 32 | version: 33 | config: "environment:d6018ce" 34 | puppet: "3.7.5" 35 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/time_date.star: -------------------------------------------------------------------------------- 1 | # Example of parsing a date out of a field and modifying the metric to inject the year, month and day. 2 | # 3 | # Example Input: 4 | # time value="2009-06-12T12:06:10.000000099" 1465839830100400201 5 | # 6 | # Example Output: 7 | # time year=2009i,month=6i,day=12i 1465839830100400201 8 | 9 | load('time.star', 'time') 10 | # loads time.parse_duration(), time.is_valid_timezone(), time.now(), time.time(), 11 | # time.parse_time() and time.from_timestamp() 12 | 13 | def apply(metric): 14 | date = time.parse_time(metric.fields.get('value'), format="2006-01-02T15:04:05.999999999", location="UTC") 15 | metric.fields.pop('value') 16 | metric.fields["year"] = date.year 17 | metric.fields["month"] = date.month 18 | metric.fields["day"] = date.day 19 | return metric 20 | -------------------------------------------------------------------------------- /scripts/deb/post-remove.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function disable_systemd { 4 | systemctl disable telegraf 5 | rm -f $1 6 | } 7 | 8 | function disable_update_rcd { 9 | update-rc.d -f telegraf remove 10 | rm -f /etc/init.d/telegraf 11 | } 12 | 13 | function disable_chkconfig { 14 | chkconfig --del telegraf 15 | rm -f /etc/init.d/telegraf 16 | } 17 | 18 | if [ "$1" == "remove" -o "$1" == "purge" ]; then 19 | # Remove/purge 20 | rm -f /etc/default/telegraf 21 | 22 | if [[ "$(readlink /proc/1/exe)" == */systemd ]]; then 23 | disable_systemd /lib/systemd/system/telegraf.service 24 | else 25 | # Assuming sysv 26 | # Run update-rc.d or fallback to chkconfig if not available 27 | if which update-rc.d &>/dev/null; then 28 | disable_update_rcd 29 | else 30 | disable_chkconfig 31 | fi 32 | fi 33 | fi 34 | -------------------------------------------------------------------------------- /plugins/outputs/mqtt/mqtt_test.go: -------------------------------------------------------------------------------- 1 | package mqtt 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/influxdata/telegraf/plugins/serializers" 7 | "github.com/influxdata/telegraf/testutil" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestConnectAndWriteIntegration(t *testing.T) { 13 | if testing.Short() { 14 | t.Skip("Skipping integration test in short mode") 15 | } 16 | 17 | var url = testutil.GetLocalHost() + ":1883" 18 | s, _ := serializers.NewInfluxSerializer() 19 | m := &MQTT{ 20 | Servers: []string{url}, 21 | serializer: s, 22 | } 23 | 24 | // Verify that we can connect to the MQTT broker 25 | err := m.Connect() 26 | require.NoError(t, err) 27 | 28 | // Verify that we can successfully write data to the mqtt broker 29 | err = m.Write(testutil.MockMetrics()) 30 | require.NoError(t, err) 31 | } 32 | -------------------------------------------------------------------------------- /plugins/parsers/prometheus/README.md: -------------------------------------------------------------------------------- 1 | # Prometheus Text-Based Format 2 | 3 | There are no additional configuration options for [Prometheus Text-Based Format][]. The metrics are parsed directly into Telegraf metrics. It is used internally in [prometheus input](/plugins/inputs/prometheus) or can be used in [http_listener_v2](/plugins/inputs/http_listener_v2) to simulate Pushgateway. 4 | 5 | [Prometheus Text-Based Format]: https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format 6 | 7 | ```toml 8 | [[inputs.file]] 9 | files = ["example"] 10 | 11 | ## Data format to consume. 12 | ## Each data format has its own unique set of configuration options, read 13 | ## more about them here: 14 | ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md 15 | data_format = "prometheus" 16 | 17 | ``` 18 | -------------------------------------------------------------------------------- /plugins/inputs/clickhouse/dev/dhparam.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN DH PARAMETERS----- 2 | MIICCAKCAgEAoo1x7wI5K57P1/AkHUmVWzKNfy46b/ni/QtClomTB78Ks1FP8dzs 3 | CQBW/pfL8yidxTialNhMRCZO1J+uPjTvd8dG8SFZzVylkF41LBNrUD+MLyh/b6Nr 4 | 8uWf3tqYCtsiqsQsnq/oU7C29wn6UjhPPVbRRDPGyJUFOgp0ebPR0L2gOc5HhXSF 5 | Tt0fuWnvgZJBKGvyodby3p2CSheu8K6ZteVc8ZgHuanhCQA30nVN+yNQzyozlB2H 6 | B9jxTDPJy8+/4Mui3iiNyXg6FaiI9lWdH7xgKoZlHi8BWlLz5Se9JVNYg0dPrMTz 7 | K0itQyyTKUlK73x+1uPm6q1AJwz08EZiCXNbk58/Sf+pdwDmAO2QSRrERC73vnvc 8 | B1+4+Kf7RS7oYpAHknKm/MFnkCJLVIq1b6kikYcIgVCYe+Z1UytSmG1QfwdgL8QQ 9 | TVYVHBg4w07+s3/IJ1ekvNhdxpkmmevYt7GjohWu8vKkip4se+reNdo+sqLsgFKf 10 | 1IuDMD36zn9FVukvs7e3BwZCTkdosGHvHGjA7zm2DwPPO16hCvJ4mE6ULLpp2NEw 11 | EBYWm3Tv6M/xtrF5Afyh0gAh7eL767/qsarbx6jlqs+dnh3LptqsE3WerWK54+0B 12 | 3Hr5CVfgYbeXuW2HeFb+fS6CNUWmiAsq1XRiz5p16hpeMGYN/qyF1IsCAQI= 13 | -----END DH PARAMETERS----- 14 | -------------------------------------------------------------------------------- /plugins/parsers/wavefront/token.go: -------------------------------------------------------------------------------- 1 | package wavefront 2 | 3 | type Token int 4 | 5 | const ( 6 | // Special tokens 7 | Illegal Token = iota 8 | EOF 9 | Ws 10 | 11 | // Literals 12 | literalBeg 13 | Letter // metric name, source/point tags 14 | Number 15 | MinusSign 16 | Underscore 17 | Dot 18 | Slash 19 | Backslash 20 | Comma 21 | Delta 22 | literalEnd 23 | 24 | // Misc characters 25 | Quotes 26 | Equals 27 | Newline 28 | ) 29 | 30 | func isWhitespace(ch rune) bool { 31 | return ch == ' ' || ch == '\t' || ch == '\n' 32 | } 33 | 34 | func isLetter(ch rune) bool { 35 | return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') 36 | } 37 | 38 | func isNumber(ch rune) bool { 39 | return ch >= '0' && ch <= '9' 40 | } 41 | 42 | func isDelta(ch rune) bool { 43 | return ch == '\u2206' || ch == '\u0394' 44 | } 45 | 46 | var eof = rune(0) 47 | -------------------------------------------------------------------------------- /docs/PROFILING.md: -------------------------------------------------------------------------------- 1 | # Telegraf profiling 2 | 3 | Telegraf uses the standard package `net/http/pprof`. This package serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool. 4 | 5 | By default, the profiling is turned off. 6 | 7 | To enable profiling you need to specify address to config parameter `pprof-addr`, for example: 8 | 9 | ``` 10 | telegraf --config telegraf.conf --pprof-addr localhost:6060 11 | ``` 12 | 13 | There are several paths to get different profiling information: 14 | 15 | To look at the heap profile: 16 | 17 | `go tool pprof http://localhost:6060/debug/pprof/heap` 18 | 19 | or to look at a 30-second CPU profile: 20 | 21 | `go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30` 22 | 23 | To view all available profiles, open `http://localhost:6060/debug/pprof/` in your browser. 24 | 25 | -------------------------------------------------------------------------------- /plugins/aggregators/merge/README.md: -------------------------------------------------------------------------------- 1 | # Merge Aggregator 2 | 3 | Merge metrics together into a metric with multiple fields into the most memory 4 | and network transfer efficient form. 5 | 6 | Use this plugin when fields are split over multiple metrics, with the same 7 | measurement, tag set and timestamp. By merging into a single metric they can 8 | be handled more efficiently by the output. 9 | 10 | ### Configuration 11 | 12 | ```toml 13 | [[aggregators.merge]] 14 | ## If true, the original metric will be dropped by the 15 | ## aggregator and will not get sent to the output plugins. 16 | drop_original = true 17 | ``` 18 | 19 | ### Example 20 | 21 | ```diff 22 | - cpu,host=localhost usage_time=42 1567562620000000000 23 | - cpu,host=localhost idle_time=42 1567562620000000000 24 | + cpu,host=localhost idle_time=42,usage_time=42 1567562620000000000 25 | ``` 26 | -------------------------------------------------------------------------------- /plugins/outputs/application_insights/transmitter.go: -------------------------------------------------------------------------------- 1 | package application_insights 2 | 3 | import ( 4 | "github.com/microsoft/ApplicationInsights-Go/appinsights" 5 | ) 6 | 7 | type Transmitter struct { 8 | client appinsights.TelemetryClient 9 | } 10 | 11 | func NewTransmitter(ikey string, endpointURL string) *Transmitter { 12 | if len(endpointURL) == 0 { 13 | return &Transmitter{client: appinsights.NewTelemetryClient(ikey)} 14 | } 15 | 16 | telemetryConfig := appinsights.NewTelemetryConfiguration(ikey) 17 | telemetryConfig.EndpointUrl = endpointURL 18 | return &Transmitter{client: appinsights.NewTelemetryClientFromConfig(telemetryConfig)} 19 | } 20 | 21 | func (t *Transmitter) Track(telemetry appinsights.Telemetry) { 22 | t.client.Track(telemetry) 23 | } 24 | 25 | func (t *Transmitter) Close() <-chan struct{} { 26 | return t.client.Channel().Close(0) 27 | } 28 | -------------------------------------------------------------------------------- /plugins/outputs/nsq/nsq_test.go: -------------------------------------------------------------------------------- 1 | package nsq 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/influxdata/telegraf/plugins/serializers" 7 | "github.com/influxdata/telegraf/testutil" 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestConnectAndWriteIntegration(t *testing.T) { 12 | if testing.Short() { 13 | t.Skip("Skipping integration test in short mode") 14 | } 15 | 16 | server := []string{testutil.GetLocalHost() + ":4150"} 17 | s, _ := serializers.NewInfluxSerializer() 18 | n := &NSQ{ 19 | Server: server[0], 20 | Topic: "telegraf", 21 | serializer: s, 22 | } 23 | 24 | // Verify that we can connect to the NSQ daemon 25 | err := n.Connect() 26 | require.NoError(t, err) 27 | 28 | // Verify that we can successfully write data to the NSQ daemon 29 | err = n.Write(testutil.MockMetrics()) 30 | require.NoError(t, err) 31 | } 32 | -------------------------------------------------------------------------------- /testutil/testutil_test.go: -------------------------------------------------------------------------------- 1 | package testutil 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | ) 7 | 8 | func TestDockerHost(t *testing.T) { 9 | os.Unsetenv("DOCKER_HOST") 10 | 11 | host := GetLocalHost() 12 | 13 | if host != localhost { 14 | t.Fatalf("Host should be localhost when DOCKER_HOST is not set. Current value [%s]", host) 15 | } 16 | 17 | os.Setenv("DOCKER_HOST", "1.1.1.1") 18 | 19 | host = GetLocalHost() 20 | 21 | if host != "1.1.1.1" { 22 | t.Fatalf("Host should take DOCKER_HOST value when set. Current value is [%s] and DOCKER_HOST is [%s]", host, os.Getenv("DOCKER_HOST")) 23 | } 24 | 25 | os.Setenv("DOCKER_HOST", "tcp://1.1.1.1:8080") 26 | 27 | host = GetLocalHost() 28 | 29 | if host != "1.1.1.1" { 30 | t.Fatalf("Host should take DOCKER_HOST value when set. Current value is [%s] and DOCKER_HOST is [%s]", host, os.Getenv("DOCKER_HOST")) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /plugins/common/logrus/hook.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "io/ioutil" 5 | "log" 6 | "strings" 7 | "sync" 8 | 9 | "github.com/sirupsen/logrus" 10 | ) 11 | 12 | var once sync.Once 13 | 14 | type LogHook struct { 15 | } 16 | 17 | // Install a logging hook into the logrus standard logger, diverting all logs 18 | // through the Telegraf logger at debug level. This is useful for libraries 19 | // that directly log to the logrus system without providing an override method. 20 | func InstallHook() { 21 | once.Do(func() { 22 | logrus.SetOutput(ioutil.Discard) 23 | logrus.AddHook(&LogHook{}) 24 | }) 25 | } 26 | 27 | func (h *LogHook) Fire(entry *logrus.Entry) error { 28 | msg := strings.ReplaceAll(entry.Message, "\n", " ") 29 | log.Print("D! [logrus] ", msg) 30 | return nil 31 | } 32 | 33 | func (h *LogHook) Levels() []logrus.Level { 34 | return logrus.AllLevels 35 | } 36 | -------------------------------------------------------------------------------- /plugins/parsers/xpath/testcases/multisensor_selection_batch.conf: -------------------------------------------------------------------------------- 1 | # Example for batch selecting fields from a bunch of selected metrics. 2 | # 3 | # File: 4 | # testcases/multisensor.xml 5 | # 6 | # Expected Output: 7 | # sensors,name=Facility\ A consumers=3,frequency=49.78,power=123.4,temperature=20 1596294243000000000 8 | # sensors,name=Facility\ B consumers=1,frequency=49.78,power=14.3,temperature=23.1 1596294243000000000 9 | # sensors,name=Facility\ C consumers=0,frequency=49.78,power=0.02,temperature=19.7 1596294243000000000 10 | # 11 | 12 | metric_selection = "/Bus/child::Sensor" 13 | metric_name = "string('sensors')" 14 | 15 | timestamp = "/Gateway/Timestamp" 16 | timestamp_format = "2006-01-02T15:04:05Z" 17 | 18 | field_selection = "child::Variable" 19 | field_name = "name(@*[1])" 20 | field_value = "number(@*[1])" 21 | 22 | [tags] 23 | name = "substring-after(@name, ' ')" 24 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/large_numbers/telegraf.conf: -------------------------------------------------------------------------------- 1 | [[inputs.file]] 2 | files = ["./testdata/large_numbers/input.json"] 3 | data_format = "json_v2" 4 | [[inputs.file.json_v2]] 5 | [[inputs.file.json_v2.object]] 6 | path = "int" 7 | [inputs.file.json_v2.object.fields] 8 | large = "int" 9 | larger = "int" 10 | largest = "int" 11 | [[inputs.file.json_v2.object]] 12 | path = "uint" 13 | [inputs.file.json_v2.object.fields] 14 | large = "uint" 15 | larger = "uint" 16 | largest = "uint" 17 | [[inputs.file.json_v2.object]] 18 | path = "float" 19 | [inputs.file.json_v2.object.fields] 20 | large = "float" 21 | larger = "float" 22 | largest = "float" 23 | -------------------------------------------------------------------------------- /selfstat/stat.go: -------------------------------------------------------------------------------- 1 | package selfstat 2 | 3 | import ( 4 | "sync/atomic" 5 | ) 6 | 7 | type stat struct { 8 | v int64 9 | measurement string 10 | field string 11 | tags map[string]string 12 | } 13 | 14 | func (s *stat) Incr(v int64) { 15 | atomic.AddInt64(&s.v, v) 16 | } 17 | 18 | func (s *stat) Set(v int64) { 19 | atomic.StoreInt64(&s.v, v) 20 | } 21 | 22 | func (s *stat) Get() int64 { 23 | return atomic.LoadInt64(&s.v) 24 | } 25 | 26 | func (s *stat) Name() string { 27 | return s.measurement 28 | } 29 | 30 | func (s *stat) FieldName() string { 31 | return s.field 32 | } 33 | 34 | // Tags returns a copy of the stat's tags. 35 | // NOTE this allocates a new map every time it is called. 36 | func (s *stat) Tags() map[string]string { 37 | m := make(map[string]string, len(s.tags)) 38 | for k, v := range s.tags { 39 | m[k] = v 40 | } 41 | return m 42 | } 43 | -------------------------------------------------------------------------------- /plugins/outputs/exec/README.md: -------------------------------------------------------------------------------- 1 | # Exec Output Plugin 2 | 3 | This plugin sends telegraf metrics to an external application over stdin. 4 | 5 | The command should be defined similar to docker's `exec` form: 6 | 7 | ["executable", "param1", "param2"] 8 | 9 | On non-zero exit stderr will be logged at error level. 10 | 11 | For better performance, consider execd, which runs continuously. 12 | 13 | ### Configuration 14 | 15 | ```toml 16 | [[outputs.exec]] 17 | ## Command to ingest metrics via stdin. 18 | command = ["tee", "-a", "/dev/null"] 19 | 20 | ## Timeout for command to complete. 21 | # timeout = "5s" 22 | 23 | ## Data format to output. 24 | ## Each data format has its own unique set of configuration options, read 25 | ## more about them here: 26 | ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md 27 | # data_format = "influx" 28 | ``` 29 | -------------------------------------------------------------------------------- /plugins/inputs/rabbitmq/testdata/set2/memory.json: -------------------------------------------------------------------------------- 1 | { 2 | "memory": { 3 | "connection_readers": 1246768, 4 | "connection_writers": 72108, 5 | "connection_channels": 308588, 6 | "connection_other": 4883596, 7 | "queue_procs": 780996, 8 | "queue_slave_procs": 0, 9 | "quorum_queue_procs": 0, 10 | "plugins": 11932828, 11 | "other_proc": 39203520, 12 | "metrics": 626932, 13 | "mgmt_db": 3341264, 14 | "mnesia": 396016, 15 | "quorum_ets": 47920, 16 | "other_ets": 3771384, 17 | "binary": 209324208, 18 | "msg_index": 32648, 19 | "code": 32810827, 20 | "atom": 1458513, 21 | "other_system": 14284124, 22 | "allocated_unused": 61026048, 23 | "reserved_unallocated": 0, 24 | "strategy": "rss", 25 | "total": { 26 | "erlang": 324522240, 27 | "rss": 385548288, 28 | "allocated": 385548288 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /plugins/inputs/synproxy/synproxy.go: -------------------------------------------------------------------------------- 1 | package synproxy 2 | 3 | import ( 4 | "os" 5 | "path" 6 | 7 | "github.com/influxdata/telegraf" 8 | "github.com/influxdata/telegraf/plugins/inputs" 9 | ) 10 | 11 | type Synproxy struct { 12 | Log telegraf.Logger `toml:"-"` 13 | 14 | // Synproxy stats filename (proc filesystem) 15 | statFile string 16 | } 17 | 18 | func (k *Synproxy) Description() string { 19 | return "Get synproxy counter statistics from procfs" 20 | } 21 | 22 | func (k *Synproxy) SampleConfig() string { 23 | return "" 24 | } 25 | 26 | func getHostProc() string { 27 | procPath := "/proc" 28 | if os.Getenv("HOST_PROC") != "" { 29 | procPath = os.Getenv("HOST_PROC") 30 | } 31 | return procPath 32 | } 33 | 34 | func init() { 35 | inputs.Add("synproxy", func() telegraf.Input { 36 | return &Synproxy{ 37 | statFile: path.Join(getHostProc(), "/net/stat/synproxy"), 38 | } 39 | }) 40 | } 41 | -------------------------------------------------------------------------------- /plugins/inputs/intel_rdt/processes.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package intel_rdt 4 | 5 | import "github.com/prometheus/procfs" 6 | 7 | type ProcessesHandler interface { 8 | getAllProcesses() ([]Process, error) 9 | } 10 | 11 | type Process struct { 12 | Name string 13 | PID int 14 | } 15 | 16 | type ProcessManager struct{} 17 | 18 | func NewProcessor() ProcessesHandler { 19 | return &ProcessManager{} 20 | } 21 | 22 | func (p *ProcessManager) getAllProcesses() ([]Process, error) { 23 | var processes []Process 24 | allProcesses, err := procfs.AllProcs() 25 | if err != nil { 26 | return nil, err 27 | } 28 | for _, proc := range allProcesses { 29 | procComm, err := proc.Comm() 30 | if err != nil { 31 | continue 32 | } 33 | newProcess := Process{ 34 | PID: proc.PID, 35 | Name: procComm, 36 | } 37 | processes = append(processes, newProcess) 38 | } 39 | return processes, nil 40 | } 41 | -------------------------------------------------------------------------------- /plugins/outputs/nats/nats_test.go: -------------------------------------------------------------------------------- 1 | package nats 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/influxdata/telegraf/plugins/serializers" 7 | "github.com/influxdata/telegraf/testutil" 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestConnectAndWriteIntegration(t *testing.T) { 12 | if testing.Short() { 13 | t.Skip("Skipping integration test in short mode") 14 | } 15 | 16 | server := []string{"nats://" + testutil.GetLocalHost() + ":4222"} 17 | s, _ := serializers.NewInfluxSerializer() 18 | n := &NATS{ 19 | Servers: server, 20 | Name: "telegraf", 21 | Subject: "telegraf", 22 | serializer: s, 23 | } 24 | 25 | // Verify that we can connect to the NATS daemon 26 | err := n.Connect() 27 | require.NoError(t, err) 28 | 29 | // Verify that we can successfully write data to the NATS daemon 30 | err = n.Write(testutil.MockMetrics()) 31 | require.NoError(t, err) 32 | } 33 | -------------------------------------------------------------------------------- /plugins/outputs/signalfx/README.md: -------------------------------------------------------------------------------- 1 | # SignalFx Output Plugin 2 | 3 | The SignalFx output plugin sends metrics to [SignalFx](https://docs.signalfx.com/en/latest/). 4 | 5 | ### Configuration 6 | ```toml 7 | [[outputs.signalfx]] 8 | ## SignalFx Org Access Token 9 | access_token = "my-secret-token" 10 | 11 | ## The SignalFx realm that your organization resides in 12 | signalfx_realm = "us9" # Required if ingest_url is not set 13 | 14 | ## You can optionally provide a custom ingest url instead of the 15 | ## signalfx_realm option above if you are using a gateway or proxy 16 | ## instance. This option takes precident over signalfx_realm. 17 | ingest_url = "https://my-custom-ingest/" 18 | 19 | ## Event typed metrics are omitted by default, 20 | ## If you require an event typed metric you must specify the 21 | ## metric name in the following list. 22 | included_event_names = ["plugin.metric_name"] 23 | ``` 24 | -------------------------------------------------------------------------------- /plugins/parsers/xpath/testcases/addressbook.conf: -------------------------------------------------------------------------------- 1 | # Example for parsing an example protocol buffer data. 2 | # 3 | # File: 4 | # testcases/addressbook.dat xpath_protobuf 5 | # 6 | # Protobuf: 7 | # testcases/addressbook.proto addressbook.AddressBook 8 | # 9 | # Expected Output: 10 | # addresses,id=101,name=John\ Doe age=42i,email="john@example.com" 1621430181000000000 11 | # addresses,id=102,name=Jane\ Doe age=40i 1621430181000000000 12 | # addresses,id=201,name=Jack\ Doe age=12i,email="jack@example.com" 1621430181000000000 13 | # addresses,id=301,name=Jack\ Buck age=19i,email="buck@example.com" 1621430181000000000 14 | # addresses,id=1001,name=Janet\ Doe age=16i,email="janet@example.com" 1621430181000000000 15 | # 16 | 17 | metric_name = "'addresses'" 18 | metric_selection = "//people" 19 | 20 | [tags] 21 | id = "id" 22 | name = "name" 23 | 24 | [fields_int] 25 | age = "age" 26 | 27 | [fields] 28 | email = "email" 29 | -------------------------------------------------------------------------------- /plugins/inputs/wireless/wireless.go: -------------------------------------------------------------------------------- 1 | package wireless 2 | 3 | import ( 4 | "github.com/influxdata/telegraf" 5 | "github.com/influxdata/telegraf/plugins/inputs" 6 | ) 7 | 8 | // Wireless is used to store configuration values. 9 | type Wireless struct { 10 | HostProc string `toml:"host_proc"` 11 | Log telegraf.Logger `toml:"-"` 12 | } 13 | 14 | var sampleConfig = ` 15 | ## Sets 'proc' directory path 16 | ## If not specified, then default is /proc 17 | # host_proc = "/proc" 18 | ` 19 | 20 | // Description returns information about the plugin. 21 | func (w *Wireless) Description() string { 22 | return "Monitor wifi signal strength and quality" 23 | } 24 | 25 | // SampleConfig displays configuration instructions. 26 | func (w *Wireless) SampleConfig() string { 27 | return sampleConfig 28 | } 29 | 30 | func init() { 31 | inputs.Add("wireless", func() telegraf.Input { 32 | return &Wireless{} 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /plugins/outputs/application_insights/mocks/transmitter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | package mocks 3 | 4 | import appinsights "github.com/microsoft/ApplicationInsights-Go/appinsights" 5 | 6 | import mock "github.com/stretchr/testify/mock" 7 | 8 | // Transmitter is an autogenerated mock type for the Transmitter type 9 | type Transmitter struct { 10 | mock.Mock 11 | } 12 | 13 | // Close provides a mock function with given fields: 14 | func (_m *Transmitter) Close() <-chan struct{} { 15 | ret := _m.Called() 16 | 17 | var r0 <-chan struct{} 18 | if rf, ok := ret.Get(0).(func() <-chan struct{}); ok { 19 | r0 = rf() 20 | } else { 21 | if ret.Get(0) != nil { 22 | r0 = ret.Get(0).(<-chan struct{}) 23 | } 24 | } 25 | 26 | return r0 27 | } 28 | 29 | // Track provides a mock function with given fields: _a0 30 | func (_m *Transmitter) Track(_a0 appinsights.Telemetry) { 31 | _m.Called(_a0) 32 | } 33 | -------------------------------------------------------------------------------- /plugins/parsers/prometheus/common/helpers.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "github.com/influxdata/telegraf" 5 | dto "github.com/prometheus/client_model/go" 6 | ) 7 | 8 | func ValueType(mt dto.MetricType) telegraf.ValueType { 9 | switch mt { 10 | case dto.MetricType_COUNTER: 11 | return telegraf.Counter 12 | case dto.MetricType_GAUGE: 13 | return telegraf.Gauge 14 | case dto.MetricType_SUMMARY: 15 | return telegraf.Summary 16 | case dto.MetricType_HISTOGRAM: 17 | return telegraf.Histogram 18 | default: 19 | return telegraf.Untyped 20 | } 21 | } 22 | 23 | // Get labels from metric 24 | func MakeLabels(m *dto.Metric, defaultTags map[string]string) map[string]string { 25 | result := map[string]string{} 26 | 27 | for key, value := range defaultTags { 28 | result[key] = value 29 | } 30 | 31 | for _, lp := range m.Label { 32 | result[lp.GetName()] = lp.GetValue() 33 | } 34 | 35 | return result 36 | } 37 | -------------------------------------------------------------------------------- /plugins/parsers/grok/testdata/test-patterns: -------------------------------------------------------------------------------- 1 | # Test A log line: 2 | # [04/Jun/2016:12:41:45 +0100] 1.25 200 192.168.1.1 5.432µs 101 3 | DURATION %{NUMBER}[nuµm]?s 4 | RESPONSE_CODE %{NUMBER:response_code:tag} 5 | RESPONSE_TIME %{DURATION:response_time:duration} 6 | TEST_LOG_A \[%{HTTPDATE:timestamp:ts-httpd}\] %{NUMBER:myfloat:float} %{RESPONSE_CODE} %{IPORHOST:clientip} %{RESPONSE_TIME} %{NUMBER:myint:int} 7 | 8 | # Test B log line: 9 | # [04/06/2016--12:41:45] 1.25 mystring dropme nomodifier 10 | TEST_TIMESTAMP %{MONTHDAY}/%{MONTHNUM}/%{YEAR}--%{TIME} 11 | TEST_LOG_B \[%{TEST_TIMESTAMP:timestamp:ts-"02/01/2006--15:04:05"}\] %{NUMBER:myfloat:float} %{WORD:mystring:string} %{WORD:dropme:drop} %{WORD:nomodifier} 12 | 13 | TEST_TIMESTAMP %{MONTHDAY}/%{MONTHNUM}/%{YEAR}--%{TIME} 14 | TEST_LOG_BAD \[%{TEST_TIMESTAMP:timestamp:ts-"02/01/2006--15:04:05"}\] %{NUMBER:myfloat:float} %{WORD:mystring:int} %{WORD:dropme:drop} %{WORD:nomodifier} 15 | -------------------------------------------------------------------------------- /plugins/common/oauth/config.go: -------------------------------------------------------------------------------- 1 | package oauth 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | 7 | "golang.org/x/oauth2" 8 | "golang.org/x/oauth2/clientcredentials" 9 | ) 10 | 11 | type OAuth2Config struct { 12 | // OAuth2 Credentials 13 | ClientID string `toml:"client_id"` 14 | ClientSecret string `toml:"client_secret"` 15 | TokenURL string `toml:"token_url"` 16 | Scopes []string `toml:"scopes"` 17 | } 18 | 19 | func (o *OAuth2Config) CreateOauth2Client(ctx context.Context, client *http.Client) *http.Client { 20 | if o.ClientID != "" && o.ClientSecret != "" && o.TokenURL != "" { 21 | oauthConfig := clientcredentials.Config{ 22 | ClientID: o.ClientID, 23 | ClientSecret: o.ClientSecret, 24 | TokenURL: o.TokenURL, 25 | Scopes: o.Scopes, 26 | } 27 | ctx = context.WithValue(ctx, oauth2.HTTPClient, client) 28 | client = oauthConfig.Client(ctx) 29 | } 30 | 31 | return client 32 | } 33 | -------------------------------------------------------------------------------- /plugins/processors/registry.go: -------------------------------------------------------------------------------- 1 | package processors 2 | 3 | import "github.com/influxdata/telegraf" 4 | 5 | type Creator func() telegraf.Processor 6 | type StreamingCreator func() telegraf.StreamingProcessor 7 | 8 | // all processors are streaming processors. 9 | // telegraf.Processor processors are upgraded to telegraf.StreamingProcessor 10 | var Processors = map[string]StreamingCreator{} 11 | 12 | // Add adds a telegraf.Processor processor 13 | func Add(name string, creator Creator) { 14 | Processors[name] = upgradeToStreamingProcessor(creator) 15 | } 16 | 17 | // AddStreaming adds a telegraf.StreamingProcessor streaming processor 18 | func AddStreaming(name string, creator StreamingCreator) { 19 | Processors[name] = creator 20 | } 21 | 22 | func upgradeToStreamingProcessor(oldCreator Creator) StreamingCreator { 23 | return func() telegraf.StreamingProcessor { 24 | return NewStreamingProcessorFromProcessor(oldCreator()) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /plugins/processors/pivot/README.md: -------------------------------------------------------------------------------- 1 | # Pivot Processor 2 | 3 | You can use the `pivot` processor to rotate single valued metrics into a multi 4 | field metric. This transformation often results in data that is more easily 5 | to apply mathematical operators and comparisons between, and flatten into a 6 | more compact representation for write operations with some output data 7 | formats. 8 | 9 | To perform the reverse operation use the [unpivot] processor. 10 | 11 | ### Configuration 12 | 13 | ```toml 14 | [[processors.pivot]] 15 | ## Tag to use for naming the new field. 16 | tag_key = "name" 17 | ## Field to use as the value of the new field. 18 | value_key = "value" 19 | ``` 20 | 21 | ### Example 22 | 23 | ```diff 24 | - cpu,cpu=cpu0,name=time_idle value=42i 25 | - cpu,cpu=cpu0,name=time_user value=43i 26 | + cpu,cpu=cpu0 time_idle=42i 27 | + cpu,cpu=cpu0 time_user=43i 28 | ``` 29 | 30 | [unpivot]: /plugins/processors/unpivot/README.md 31 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/multiple_metrics.star: -------------------------------------------------------------------------------- 1 | # Example showing how to create several metrics using the Starlark processor. 2 | # 3 | # Example Input: 4 | # mm value="a" 1465839830100400201 5 | # 6 | # Example Output: 7 | # mm2 value="b" 1465839830100400201 8 | # mm1 value="a" 1465839830100400201 9 | 10 | def apply(metric): 11 | # Initialize a list of metrics 12 | metrics = [] 13 | # Create a new metric whose name is "mm2" 14 | metric2 = Metric("mm2") 15 | # Set the field "value" to b 16 | metric2.fields["value"] = "b" 17 | # Reset the time (only needed for testing purpose) 18 | metric2.time = metric.time 19 | # Add metric2 to the list of metrics 20 | metrics.append(metric2) 21 | # Rename the original metric to "mm1" 22 | metric.name = "mm1" 23 | # Add metric to the list of metrics 24 | metrics.append(metric) 25 | # Return the created list of metrics 26 | return metrics 27 | -------------------------------------------------------------------------------- /plugins/outputs/execd/README.md: -------------------------------------------------------------------------------- 1 | # Execd Output Plugin 2 | 3 | The `execd` plugin runs an external program as a daemon. 4 | 5 | Telegraf minimum version: Telegraf 1.15.0 6 | 7 | ### Configuration: 8 | 9 | ```toml 10 | [[outputs.execd]] 11 | ## One program to run as daemon. 12 | ## NOTE: process and each argument should each be their own string 13 | command = ["my-telegraf-output", "--some-flag", "value"] 14 | 15 | ## Delay before the process is restarted after an unexpected termination 16 | restart_delay = "10s" 17 | 18 | ## Data format to export. 19 | ## Each data format has its own unique set of configuration options, read 20 | ## more about them here: 21 | ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md 22 | data_format = "influx" 23 | ``` 24 | 25 | ### Example 26 | 27 | see [examples][] 28 | 29 | [examples]: https://github.com/influxdata/telegraf/blob/master/plugins/outputs/execd/examples/ 30 | -------------------------------------------------------------------------------- /plugins/parsers/xpath/testcases/multisensor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Main Gateway 4 | 2020-08-01T15:04:03Z 5 | 12 6 | ok 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | busy 16 | 17 | 18 | 19 | 20 | 21 | 22 | standby 23 | 24 | 25 | 26 | 27 | 28 | 29 | error 30 | 31 | 32 | -------------------------------------------------------------------------------- /internal/docker/docker.go: -------------------------------------------------------------------------------- 1 | package docker 2 | 3 | import "strings" 4 | 5 | // Adapts some of the logic from the actual Docker library's image parsing 6 | // routines: 7 | // https://github.com/docker/distribution/blob/release/2.7/reference/normalize.go 8 | func ParseImage(image string) (string, string) { 9 | domain := "" 10 | remainder := "" 11 | 12 | i := strings.IndexRune(image, '/') 13 | 14 | if i == -1 || (!strings.ContainsAny(image[:i], ".:") && image[:i] != "localhost") { 15 | remainder = image 16 | } else { 17 | domain, remainder = image[:i], image[i+1:] 18 | } 19 | 20 | imageName := "" 21 | imageVersion := "unknown" 22 | 23 | i = strings.LastIndex(remainder, ":") 24 | if i > -1 { 25 | imageVersion = remainder[i+1:] 26 | imageName = remainder[:i] 27 | } else { 28 | imageName = remainder 29 | } 30 | 31 | if domain != "" { 32 | imageName = domain + "/" + imageName 33 | } 34 | 35 | return imageName, imageVersion 36 | } 37 | -------------------------------------------------------------------------------- /plugins/outputs/yandex_cloud_monitoring/README.md: -------------------------------------------------------------------------------- 1 | # Yandex Cloud Monitoring 2 | 3 | This plugin will send custom metrics to Yandex Cloud Monitoring. 4 | https://cloud.yandex.com/services/monitoring 5 | 6 | ### Configuration: 7 | 8 | ```toml 9 | [[outputs.yandex_cloud_monitoring]] 10 | ## Timeout for HTTP writes. 11 | # timeout = "20s" 12 | 13 | ## Yandex.Cloud monitoring API endpoint. Normally should not be changed 14 | # endpoint_url = "https://monitoring.api.cloud.yandex.net/monitoring/v2/data/write" 15 | 16 | ## All user metrics should be sent with "custom" service specified. Normally should not be changed 17 | # service = "custom" 18 | ``` 19 | 20 | ### Authentication 21 | 22 | This plugin currently support only YC.Compute metadata based authentication. 23 | 24 | When plugin is working inside a YC.Compute instance it will take IAM token and Folder ID from instance metadata. 25 | 26 | Other authentication methods will be added later. 27 | -------------------------------------------------------------------------------- /testutil/pki/clientkey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQDX7Plvu0MJtA9TrusYtQnAogsdiYJZd9wfFIjH5FxE3SWJ4KAI 3 | E+yRWRqcqX8XnpieQLaNsfXhDPWLkWngTDydk4NO/jlAQk0e6+9+NeiZ2ViIHmtX 4 | ERb9CyiiWUmo+YCd69lhzSEIMK9EPBSDHQTgQMtEfGak03G5rx3MCakE1QIDAQAB 5 | AoGAOjRU4Lt3zKvO3d3u3ZAfet+zY1jn3DolCfO9EzUJcj6ymcIFIWhNgrikJcrC 6 | yZkkxrPnAbcQ8oNNxTuDcMTcKZbnyUnlQj5NtVuty5Q+zgf3/Q2pRhaE+TwrpOJ+ 7 | ETtVp9R/PrPN2NC5wPo289fPNWFYkd4DPbdWZp5AJHz1XYECQQD3kKpinJxMYp9F 8 | Q1Qj1OkxGln0KPgdqRYjjW/rXI4/hUodfg+xXWHPFSGj3AgEjQIvuengbOAeH3qo 9 | wF1uxVTlAkEA30hXM3EbboMCDQzNRNkkV9EiZ0MZXhj1aIGl+sQZOmOeFdcdjGkD 10 | dsA42nmaYqXCD9KAvc+S/tGJaa0Qg0VhMQJAb2+TAqh0Qn3yK39PFIH2JcAy1ZDL 11 | fq5p5L75rfwPm9AnuHbSIYhjSo+8gMG+ai3+2fTZrcfUajrJP8S3SfFRcQJBANQQ 12 | POHatxcKzlPeqMaPBXlyY553mAxK4CnVmPLGdL+EBYzwtlu5EVUj09uMSxkOHXYx 13 | k5yzHQVvtXbsrBZBOsECQBJLlkMjJmXrIIdLPmHQWL3bm9MMg1PqzupSEwz6cyrG 14 | uIIm/X91pDyxCHaKYWp38FXBkYAgohI8ow5/sgRvU5w= 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /testutil/pki/serverkey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXQIBAAKBgQDTBmLJ0pBFUxnPkkx38sBnOKvs+OinVqxTnVcc1iCyQJQleB37 3 | uY6DL55mSsPvnad/oDpyGpHt4RVtrhmyC6ptSrWLyk7mraeAo30Cooqr5tA9A+6y 4 | j0ijySLlYimTMQy8tbnVNWLwKbxgT9N4NlUzwyqxLWUMfRzLfmefqzk5bQIDAQAB 5 | AoGBALWQAgFJxM2QwV1hr59oYnitPudmBa6smRpb/q6V4Y3cmFpgrdN+hIqEtxGl 6 | 9E0+5PWfI4o3KCV2itxSdlNFTDyqTZkM+BT8PPKISzAewkdqnKjbWgAmluzOJH4O 7 | hc1zBfIOuT5+cfx5JR5/j9BhWVC7BJ+EiREkd/Z8ZnAMeItVAkEA8bhcC+8luiFQ 8 | 6kytXx2XfbKKh4Q99+KEQHqSGeuHZOcnWfjX99jo67CIxpwBRENslpZOw78fBmi4 9 | 4kf8j+dgLwJBAN99zyRxYzKc8TSsy/fF+3V/Ex75HYGGS/eOWcwPFXpGNA63hIa8 10 | fJ/2pDnLzCqLZ9vWdBF39NtkacJS7bo6XSMCQQCZgN2bipSn3k53bJhRJga1gXOt 11 | 2dJMoGIiXHR513QVJSJ9ZaUpNWu9eU9y6VF4m2TTQMLmVnIKbOi0csi2TlZrAkAi 12 | 7URsC5RXGpPPiZmutTAhIqTYWFI2JcjFfWenLkxK+aG1ExURAW/wh9kOdz0HARZQ 13 | Eum8uSR5DO5CQjeIvQpFAkAgZJXAwRxuts/p1EoLuPCJTaDkIY2vc0AJzzr5nuAs 14 | pyjnLYCYqSBUJ+3nDDBqNYpgxCJddzmjNxGuO7mef9Ue 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /plugins/processors/ifname/ttl_cache_test.go: -------------------------------------------------------------------------------- 1 | package ifname 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestTTLCacheExpire(t *testing.T) { 11 | c := NewTTLCache(1*time.Second, 100) 12 | 13 | c.now = func() time.Time { 14 | return time.Unix(0, 0) 15 | } 16 | 17 | c.Put("ones", nameMap{1: "one"}) 18 | require.Len(t, c.lru.m, 1) 19 | 20 | c.now = func() time.Time { 21 | return time.Unix(1, 0) 22 | } 23 | 24 | _, ok, _ := c.Get("ones") 25 | require.False(t, ok) 26 | require.Len(t, c.lru.m, 0) 27 | require.Equal(t, c.lru.l.Len(), 0) 28 | } 29 | 30 | func TestTTLCache(t *testing.T) { 31 | c := NewTTLCache(1*time.Second, 100) 32 | 33 | c.now = func() time.Time { 34 | return time.Unix(0, 0) 35 | } 36 | 37 | expected := nameMap{1: "one"} 38 | c.Put("ones", expected) 39 | 40 | actual, ok, _ := c.Get("ones") 41 | require.True(t, ok) 42 | require.Equal(t, expected, actual) 43 | } 44 | -------------------------------------------------------------------------------- /models/makemetric.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "github.com/influxdata/telegraf" 5 | ) 6 | 7 | // Makemetric applies new metric plugin and agent measurement and tag 8 | // settings. 9 | func makemetric( 10 | metric telegraf.Metric, 11 | nameOverride string, 12 | namePrefix string, 13 | nameSuffix string, 14 | tags map[string]string, 15 | globalTags map[string]string, 16 | ) telegraf.Metric { 17 | if len(nameOverride) != 0 { 18 | metric.SetName(nameOverride) 19 | } 20 | 21 | if len(namePrefix) != 0 { 22 | metric.AddPrefix(namePrefix) 23 | } 24 | if len(nameSuffix) != 0 { 25 | metric.AddSuffix(nameSuffix) 26 | } 27 | 28 | // Apply plugin-wide tags 29 | for k, v := range tags { 30 | if _, ok := metric.GetTag(k); !ok { 31 | metric.AddTag(k, v) 32 | } 33 | } 34 | // Apply global tags 35 | for k, v := range globalTags { 36 | if _, ok := metric.GetTag(k); !ok { 37 | metric.AddTag(k, v) 38 | } 39 | } 40 | 41 | return metric 42 | } 43 | -------------------------------------------------------------------------------- /plugins/inputs/sflow/binaryio/minreader_test.go: -------------------------------------------------------------------------------- 1 | package binaryio 2 | 3 | import ( 4 | "bytes" 5 | "testing" 6 | ) 7 | 8 | func TestMinReader(t *testing.T) { 9 | b := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} 10 | r := bytes.NewBuffer(b) 11 | 12 | mr := MinReader(r, 10) 13 | 14 | toRead := make([]byte, 5) 15 | n, err := mr.Read(toRead) 16 | if err != nil { 17 | t.Error(err) 18 | } 19 | if n != 5 { 20 | t.Error("Expected n to be 5, but was ", n) 21 | } 22 | if string(toRead) != string([]byte{1, 2, 3, 4, 5}) { 23 | t.Error("expected 5 specific bytes to be read") 24 | } 25 | err = mr.Close() 26 | if err != nil { 27 | t.Error(err) 28 | } 29 | n, err = r.Read(toRead) // read from the outer stream 30 | if err != nil { 31 | t.Error(err) 32 | } 33 | if n != 5 { 34 | t.Error("Expected n to be 5, but was ", n) 35 | } 36 | if string(toRead) != string([]byte{11, 12, 13, 14, 15}) { 37 | t.Error("expected the last 5 bytes to be read") 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /internal/goplugin/plugin.go: -------------------------------------------------------------------------------- 1 | // +build goplugin 2 | 3 | package goplugin 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | "path" 9 | "path/filepath" 10 | "plugin" 11 | "strings" 12 | ) 13 | 14 | // loadExternalPlugins loads external plugins from shared libraries (.so, .dll, etc.) 15 | // in the specified directory. 16 | func LoadExternalPlugins(rootDir string) error { 17 | return filepath.Walk(rootDir, func(pth string, info os.FileInfo, err error) error { 18 | // Stop if there was an error. 19 | if err != nil { 20 | return err 21 | } 22 | 23 | // Ignore directories. 24 | if info.IsDir() { 25 | return nil 26 | } 27 | 28 | // Ignore files that aren't shared libraries. 29 | ext := strings.ToLower(path.Ext(pth)) 30 | if ext != ".so" && ext != ".dll" { 31 | return nil 32 | } 33 | 34 | // Load plugin. 35 | _, err = plugin.Open(pth) 36 | if err != nil { 37 | return fmt.Errorf("error loading %s: %s", pth, err) 38 | } 39 | 40 | return nil 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /plugins/inputs/temp/temp_test.go: -------------------------------------------------------------------------------- 1 | package temp 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/shirou/gopsutil/host" 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/influxdata/telegraf/plugins/inputs/system" 10 | "github.com/influxdata/telegraf/testutil" 11 | ) 12 | 13 | func TestTemperature(t *testing.T) { 14 | var mps system.MockPS 15 | var err error 16 | defer mps.AssertExpectations(t) 17 | var acc testutil.Accumulator 18 | 19 | ts := host.TemperatureStat{ 20 | SensorKey: "coretemp_sensor1_crit", 21 | Temperature: 60.5, 22 | } 23 | 24 | mps.On("Temperature").Return([]host.TemperatureStat{ts}, nil) 25 | 26 | err = (&Temperature{ps: &mps}).Gather(&acc) 27 | require.NoError(t, err) 28 | 29 | expectedFields := map[string]interface{}{ 30 | "temp": float64(60.5), 31 | } 32 | 33 | expectedTags := map[string]string{ 34 | "sensor": "coretemp_sensor1_crit", 35 | } 36 | acc.AssertContainsTaggedFields(t, "temp", expectedFields, expectedTags) 37 | } 38 | -------------------------------------------------------------------------------- /plugins/parsers/logfmt/README.md: -------------------------------------------------------------------------------- 1 | # Logfmt 2 | 3 | The `logfmt` data format parses data in [logfmt] format. 4 | 5 | [logfmt]: https://brandur.org/logfmt 6 | 7 | ### Configuration 8 | 9 | ```toml 10 | [[inputs.file]] 11 | files = ["example"] 12 | 13 | ## Data format to consume. 14 | ## Each data format has its own unique set of configuration options, read 15 | ## more about them here: 16 | ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md 17 | data_format = "logfmt" 18 | ``` 19 | 20 | ### Metrics 21 | 22 | Each key/value pair in the line is added to a new metric as a field. The type 23 | of the field is automatically determined based on the contents of the value. 24 | 25 | ### Examples 26 | 27 | ``` 28 | - method=GET host=example.org ts=2018-07-24T19:43:40.275Z connect=4ms service=8ms status=200 bytes=1653 29 | + logfmt method="GET",host="example.org",ts="2018-07-24T19:43:40.275Z",connect="4ms",service="8ms",status=200i,bytes=1653i 30 | ``` 31 | -------------------------------------------------------------------------------- /testutil/pki/cakey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANPJLHJd7JBCMI60 3 | 1D/twq1c33WyngHWTvCE8oE7rJcQUVGthrDvrFjkJNM9MloA8En5qYc908Z+Yarr 4 | JfXS2MBpZBBhXboDGeB+m2LoXXhyLT9f+xNrLyKL/gO7kNGv1/2sdWKY8BJHV+SA 5 | r4gWFec42fVH6k1sdiYZLg5U3Kg/AgMBAAECgYA2PCtssk7Vdo3WzcoZAPs8yC7V 6 | hkNedxJKF9G+dJizKtOYVhbLEuWQ8gPYMLDHSbw/RXc7kgK8rzq1uXhEJpWo4THD 7 | CUUlxGRu3gt94202hbnEnV93Kix4hP98qpv1jPErlx2KywsRPTegMnUAZ2xeI564 8 | yYwDITqXALa/PqRqSQJBAPPZQeRDtBSfEjZFJS3IgUkmN3RJn4rJz+6D0ahgXPga 9 | YAYVe8SJyj2epLJP2aOBzrqBSUVkVGg8qOG5w+ibebsCQQDeVuUzYOffthO5f1Hl 10 | LvdEmfaHjXI0Q+grOnDjNRcvQaCDYYkC9JewBQmnpFrd85rN/Leo0gQ5Yyxp/ja5 11 | gPFNAkAFwn/38FF0mz1G4uM57Z6AJ9LvgD2wfYvXym1NWNlZUuYpvqApyEdqpTCm 12 | tZQidJJ5fUxJw1DrFWO30Td7axC5AkEAjSbRX6rXyhiHsS35SexlInI0Jp5PsIqj 13 | 7D2vyS69R0z8oCvdlbi+TAsGtB0Navbqgnc8Cbs630vsuGWhTGdlyQJBAKqQ2gYw 14 | +WeXH77FP8yDQOjpFw80tSyXVykT0Am75RF3sQ1OIn0o0DLhE+he0crb2n8g3FJh 15 | WyxmGkbTDelSG20= 16 | -----END PRIVATE KEY----- 17 | -------------------------------------------------------------------------------- /plugins/inputs/swap/README.md: -------------------------------------------------------------------------------- 1 | # Swap Input Plugin 2 | 3 | The swap plugin collects system swap metrics. 4 | 5 | For more information on what swap memory is, read [All about Linux swap space](https://www.linux.com/news/all-about-linux-swap-space). 6 | 7 | ### Configuration: 8 | 9 | ```toml 10 | # Read metrics about swap memory usage 11 | [[inputs.swap]] 12 | # no configuration 13 | ``` 14 | 15 | ### Metrics: 16 | 17 | - swap 18 | - fields: 19 | - free (int, bytes): free swap memory 20 | - total (int, bytes): total swap memory 21 | - used (int, bytes): used swap memory 22 | - used_percent (float, percent): percentage of swap memory used 23 | - in (int, bytes): data swapped in since last boot calculated from page number 24 | - out (int, bytes): data swapped out since last boot calculated from page number 25 | 26 | ### Example Output: 27 | 28 | ``` 29 | swap total=20855394304i,used_percent=45.43883523785713,used=9476448256i,free=1715331072i 1511894782000000000 30 | ``` 31 | -------------------------------------------------------------------------------- /plugins/outputs/loki/README.md: -------------------------------------------------------------------------------- 1 | # Loki Output Plugin 2 | 3 | This plugin sends logs to Loki, using tags as labels, 4 | log line will content all fields in `key="value"` format which is easily parsable with `logfmt` parser in Loki. 5 | 6 | ### Configuration: 7 | 8 | ```toml 9 | # A plugin that can transmit logs to Loki 10 | [[outputs.loki]] 11 | ## The domain of Loki 12 | domain = "https://loki.domain.tld" 13 | 14 | ## Endpoint to write api 15 | # endpoint = "/loki/api/v1/push" 16 | 17 | ## Connection timeout, defaults to "5s" if not set. 18 | # timeout = "5s" 19 | 20 | ## Basic auth credential 21 | # username = "loki" 22 | # password = "pass" 23 | 24 | ## Additional HTTP headers 25 | # http_headers = {"X-Scope-OrgID" = "1"} 26 | 27 | ## If the request must be gzip encoded 28 | # gzip_request = false 29 | 30 | ## Optional TLS Config 31 | # tls_ca = "/etc/telegraf/ca.pem" 32 | # tls_cert = "/etc/telegraf/cert.pem" 33 | # tls_key = "/etc/telegraf/key.pem" 34 | ``` 35 | -------------------------------------------------------------------------------- /scripts/deb/pre-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if ! grep "^telegraf:" /etc/group &>/dev/null; then 4 | groupadd -r telegraf 5 | fi 6 | 7 | if ! id telegraf &>/dev/null; then 8 | useradd -r -M telegraf -s /bin/false -d /etc/telegraf -g telegraf 9 | fi 10 | 11 | if [[ -d /etc/opt/telegraf ]]; then 12 | # Legacy configuration found 13 | if [[ ! -d /etc/telegraf ]]; then 14 | # New configuration does not exist, move legacy configuration to new location 15 | echo -e "Please note, Telegraf's configuration is now located at '/etc/telegraf' (previously '/etc/opt/telegraf')." 16 | mv -vn /etc/opt/telegraf /etc/telegraf 17 | 18 | if [[ -f /etc/telegraf/telegraf.conf ]]; then 19 | backup_name="telegraf.conf.$(date +%s).backup" 20 | echo "A backup of your current configuration can be found at: /etc/telegraf/${backup_name}" 21 | cp -a "/etc/telegraf/telegraf.conf" "/etc/telegraf/${backup_name}" 22 | fi 23 | fi 24 | fi 25 | -------------------------------------------------------------------------------- /scripts/rpm/pre-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if ! grep "^telegraf:" /etc/group &>/dev/null; then 4 | groupadd -r telegraf 5 | fi 6 | 7 | if ! id telegraf &>/dev/null; then 8 | useradd -r -M telegraf -s /bin/false -d /etc/telegraf -g telegraf 9 | fi 10 | 11 | if [[ -d /etc/opt/telegraf ]]; then 12 | # Legacy configuration found 13 | if [[ ! -d /etc/telegraf ]]; then 14 | # New configuration does not exist, move legacy configuration to new location 15 | echo -e "Please note, Telegraf's configuration is now located at '/etc/telegraf' (previously '/etc/opt/telegraf')." 16 | mv -vn /etc/opt/telegraf /etc/telegraf 17 | 18 | if [[ -f /etc/telegraf/telegraf.conf ]]; then 19 | backup_name="telegraf.conf.$(date +%s).backup" 20 | echo "A backup of your current configuration can be found at: /etc/telegraf/${backup_name}" 21 | cp -a "/etc/telegraf/telegraf.conf" "/etc/telegraf/${backup_name}" 22 | fi 23 | fi 24 | fi 25 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Required for all PRs: 2 | 3 | 5 | 6 | - [ ] Updated associated README.md. 7 | - [ ] Wrote appropriate unit tests. 8 | 9 | 16 | 17 | resolves # 18 | 19 | 26 | -------------------------------------------------------------------------------- /internal/syslog/framing_test.go: -------------------------------------------------------------------------------- 1 | package syslog 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "testing" 6 | ) 7 | 8 | func TestFraming(t *testing.T) { 9 | var f1 Framing 10 | f1.UnmarshalTOML([]byte(`"non-transparent"`)) 11 | assert.Equal(t, NonTransparent, f1) 12 | 13 | var f2 Framing 14 | f2.UnmarshalTOML([]byte(`non-transparent`)) 15 | assert.Equal(t, NonTransparent, f2) 16 | 17 | var f3 Framing 18 | f3.UnmarshalTOML([]byte(`'non-transparent'`)) 19 | assert.Equal(t, NonTransparent, f3) 20 | 21 | var f4 Framing 22 | f4.UnmarshalTOML([]byte(`"octet-counting"`)) 23 | assert.Equal(t, OctetCounting, f4) 24 | 25 | var f5 Framing 26 | f5.UnmarshalTOML([]byte(`octet-counting`)) 27 | assert.Equal(t, OctetCounting, f5) 28 | 29 | var f6 Framing 30 | f6.UnmarshalTOML([]byte(`'octet-counting'`)) 31 | assert.Equal(t, OctetCounting, f6) 32 | 33 | var f7 Framing 34 | err := f7.UnmarshalTOML([]byte(`nope`)) 35 | assert.Equal(t, Framing(-1), f7) 36 | assert.Error(t, err) 37 | } 38 | -------------------------------------------------------------------------------- /plugins/processors/starlark/testdata/time_timestamp.star: -------------------------------------------------------------------------------- 1 | # Example of filtering metrics based on the timestamp in seconds. 2 | # 3 | # Example Input: 4 | # time result="KO" 1616020365100400201 5 | # time result="OK" 1616150517100400201 6 | # 7 | # Example Output: 8 | # time result="OK" 1616150517100400201 9 | 10 | load('time.star', 'time') 11 | # loads time.parse_duration(), time.is_valid_timezone(), time.now(), time.time(), 12 | # time.parse_time() and time.from_timestamp() 13 | 14 | def apply(metric): 15 | # 1616198400 sec = Saturday, March 20, 2021 0:00:00 GMT 16 | refDate = time.from_timestamp(1616198400) 17 | # 1616020365 sec = Wednesday, March 17, 2021 22:32:45 GMT 18 | # 1616150517 sec = Friday, March 19, 2021 10:41:57 GMT 19 | metric_date = time.from_timestamp(int(metric.time / 1e9)) 20 | # Only keep metrics with a timestamp that is not more than 24 hours before the reference date 21 | if refDate - time.parse_duration("24h") < metric_date: 22 | return metric 23 | -------------------------------------------------------------------------------- /.github/workflows/golangci-lint.yml: -------------------------------------------------------------------------------- 1 | name: golangci-lint 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | schedule: 10 | # Trigger every day at 16:00 UTC 11 | - cron: '0 16 * * *' 12 | jobs: 13 | golangci-pr: 14 | if: github.ref != 'refs/heads/master' 15 | name: lint-pr-changes 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: golangci-lint 20 | uses: golangci/golangci-lint-action@v2 21 | with: 22 | version: v1.38 23 | only-new-issues: true 24 | golangci-master: 25 | if: github.ref == 'refs/heads/master' 26 | name: lint-master-all 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v2 30 | - name: golangci-lint 31 | uses: golangci/golangci-lint-action@v2 32 | with: 33 | version: v1.38 34 | only-new-issues: true 35 | args: --issues-exit-code=0 36 | -------------------------------------------------------------------------------- /plugins/common/kafka/scram_client.go: -------------------------------------------------------------------------------- 1 | package kafka 2 | 3 | import ( 4 | "crypto/sha256" 5 | "crypto/sha512" 6 | "hash" 7 | 8 | "github.com/xdg/scram" 9 | ) 10 | 11 | var SHA256 scram.HashGeneratorFcn = func() hash.Hash { return sha256.New() } 12 | var SHA512 scram.HashGeneratorFcn = func() hash.Hash { return sha512.New() } 13 | 14 | type XDGSCRAMClient struct { 15 | *scram.Client 16 | *scram.ClientConversation 17 | scram.HashGeneratorFcn 18 | } 19 | 20 | func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error) { 21 | x.Client, err = x.HashGeneratorFcn.NewClient(userName, password, authzID) 22 | if err != nil { 23 | return err 24 | } 25 | x.ClientConversation = x.Client.NewConversation() 26 | return nil 27 | } 28 | 29 | func (x *XDGSCRAMClient) Step(challenge string) (response string, err error) { 30 | response, err = x.ClientConversation.Step(challenge) 31 | return 32 | } 33 | 34 | func (x *XDGSCRAMClient) Done() bool { 35 | return x.ClientConversation.Done() 36 | } 37 | -------------------------------------------------------------------------------- /plugins/processors/tag_limit/README.md: -------------------------------------------------------------------------------- 1 | # Tag Limit Processor Plugin 2 | 3 | Use the `tag_limit` processor to ensure that only a certain number of tags are 4 | preserved for any given metric, and to choose the tags to preserve when the 5 | number of tags appended by the data source is over the limit. 6 | 7 | This can be useful when dealing with output systems (e.g. Stackdriver) that 8 | impose hard limits on the number of tags/labels per metric or where high 9 | levels of cardinality are computationally and/or financially expensive. 10 | 11 | ### Configuration 12 | 13 | ```toml 14 | [[processors.tag_limit]] 15 | ## Maximum number of tags to preserve 16 | limit = 3 17 | 18 | ## List of tags to preferentially preserve 19 | keep = ["environment", "region"] 20 | ``` 21 | 22 | ### Example 23 | 24 | ```diff 25 | + throughput month=Jun,environment=qa,region=us-east1,lower=10i,upper=1000i,mean=500i 1560540094000000000 26 | + throughput environment=qa,region=us-east1,lower=10i 1560540094000000000 27 | ``` 28 | -------------------------------------------------------------------------------- /plugins/common/tls/utils.go: -------------------------------------------------------------------------------- 1 | package tls 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // ParseCiphers returns a `[]uint16` by received `[]string` key that represents ciphers from crypto/tls. 8 | // If some of ciphers in received list doesn't exists ParseCiphers returns nil with error 9 | func ParseCiphers(ciphers []string) ([]uint16, error) { 10 | suites := []uint16{} 11 | 12 | for _, cipher := range ciphers { 13 | if v, ok := tlsCipherMap[cipher]; ok { 14 | suites = append(suites, v) 15 | } else { 16 | return nil, fmt.Errorf("unsupported cipher %q", cipher) 17 | } 18 | } 19 | 20 | return suites, nil 21 | } 22 | 23 | // ParseTLSVersion returns a `uint16` by received version string key that represents tls version from crypto/tls. 24 | // If version isn't supported ParseTLSVersion returns 0 with error 25 | func ParseTLSVersion(version string) (uint16, error) { 26 | if v, ok := tlsVersionMap[version]; ok { 27 | return v, nil 28 | } 29 | return 0, fmt.Errorf("unsupported version %q", version) 30 | } 31 | -------------------------------------------------------------------------------- /plugins/inputs/intel_powerstat/dto.go: -------------------------------------------------------------------------------- 1 | package intel_powerstat 2 | 3 | type msrData struct { 4 | mperf uint64 5 | aperf uint64 6 | timeStampCounter uint64 7 | c3 uint64 8 | c6 uint64 9 | c7 uint64 10 | throttleTemp uint64 11 | temp uint64 12 | mperfDelta uint64 13 | aperfDelta uint64 14 | timeStampCounterDelta uint64 15 | c3Delta uint64 16 | c6Delta uint64 17 | c7Delta uint64 18 | readDate int64 19 | } 20 | 21 | type raplData struct { 22 | dramCurrentEnergy float64 23 | socketCurrentEnergy float64 24 | socketEnergy float64 25 | dramEnergy float64 26 | readDate int64 27 | } 28 | 29 | type cpuInfo struct { 30 | physicalID string 31 | coreID string 32 | cpuID string 33 | vendorID string 34 | cpuFamily string 35 | model string 36 | flags string 37 | } 38 | -------------------------------------------------------------------------------- /plugins/processors/rename/README.md: -------------------------------------------------------------------------------- 1 | # Rename Processor Plugin 2 | 3 | The `rename` processor renames measurements, fields, and tags. 4 | 5 | ### Configuration: 6 | 7 | ```toml 8 | [[processors.rename]] 9 | ## Specify one sub-table per rename operation. 10 | [[processors.rename.replace]] 11 | measurement = "network_interface_throughput" 12 | dest = "throughput" 13 | 14 | [[processors.rename.replace]] 15 | tag = "hostname" 16 | dest = "host" 17 | 18 | [[processors.rename.replace]] 19 | field = "lower" 20 | dest = "min" 21 | 22 | [[processors.rename.replace]] 23 | field = "upper" 24 | dest = "max" 25 | ``` 26 | 27 | ### Tags: 28 | 29 | No tags are applied by this processor, though it can alter them by renaming. 30 | 31 | ### Example processing: 32 | 33 | ```diff 34 | - network_interface_throughput,hostname=backend.example.com lower=10i,upper=1000i,mean=500i 1502489900000000000 35 | + throughput,host=backend.example.com min=10i,max=1000i,mean=500i 1502489900000000000 36 | ``` 37 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/complex_nesting/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "metadata": { 4 | "generated": 1626285886000, 5 | "url": "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_week.geojson", 6 | "title": "USGS Significant Earthquakes, Past Week", 7 | "status": 200, 8 | "api": "1.10.3", 9 | "count": 1 10 | }, 11 | "features": [ 12 | { 13 | "type": "Feature", 14 | "properties": { 15 | "mag": 6, 16 | "place": "Antelope Valley, CA", 17 | "time": 1625784588110, 18 | "updated": 1626277167263 19 | }, 20 | "geometry": { 21 | "type": "Point", 22 | "coordinates": [ 23 | -119.4998333, 24 | 38.5075, 25 | 7.45 26 | ] 27 | }, 28 | "id": "nc73584926" 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /internal/choice/choice.go: -------------------------------------------------------------------------------- 1 | // Package choice provides basic functions for working with 2 | // plugin options that must be one of several values. 3 | package choice 4 | 5 | import "fmt" 6 | 7 | // Contains return true if the choice in the list of choices. 8 | func Contains(choice string, choices []string) bool { 9 | for _, item := range choices { 10 | if item == choice { 11 | return true 12 | } 13 | } 14 | return false 15 | } 16 | 17 | // CheckSContains returns an error if a choice is not one of 18 | // the available choices. 19 | func Check(choice string, available []string) error { 20 | if !Contains(choice, available) { 21 | return fmt.Errorf("unknown choice %s", choice) 22 | } 23 | return nil 24 | } 25 | 26 | // CheckSliceContains returns an error if the choices is not a subset of 27 | // available. 28 | func CheckSlice(choices, available []string) error { 29 | for _, choice := range choices { 30 | err := Check(choice, available) 31 | if err != nil { 32 | return err 33 | } 34 | } 35 | return nil 36 | } 37 | -------------------------------------------------------------------------------- /plugins/processors/execd/examples/multiplier_line_protocol/multiplier_line_protocol.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | loop do 4 | # example input: "counter_ruby count=0 1586302128978187000" 5 | line = STDIN.readline.chomp 6 | # parse out influx line protocol sections with a really simple hand-rolled parser that doesn't support escaping. 7 | # for a full line parser in ruby, check out something like the influxdb-lineprotocol-parser gem. 8 | parts = line.split(" ") 9 | case parts.size 10 | when 3 11 | measurement, fields, timestamp = parts 12 | when 4 13 | measurement, tags, fields, timestamp = parts 14 | else 15 | STDERR.puts "Unable to parse line protocol" 16 | exit 1 17 | end 18 | fields = fields.split(",").map{|t| 19 | k,v = t.split("=") 20 | if k == "count" 21 | v = v.to_i * 2 # multiple count metric by two 22 | end 23 | "#{k}=#{v}" 24 | }.join(",") 25 | puts [measurement, tags, fields, timestamp].select{|s| s && s.size != 0 }.join(" ") 26 | STDOUT.flush 27 | end 28 | -------------------------------------------------------------------------------- /plugins/inputs/file/README.md: -------------------------------------------------------------------------------- 1 | # File Input Plugin 2 | 3 | The file plugin parses the **complete** contents of a file **every interval** using 4 | the selected [input data format][]. 5 | 6 | **Note:** If you wish to parse only newly appended lines use the [tail][] input 7 | plugin instead. 8 | 9 | ### Configuration: 10 | 11 | ```toml 12 | [[inputs.file]] 13 | ## Files to parse each interval. Accept standard unix glob matching rules, 14 | ## as well as ** to match recursive files and directories. 15 | files = ["/tmp/metrics.out"] 16 | 17 | ## Data format to consume. 18 | ## Each data format has its own unique set of configuration options, read 19 | ## more about them here: 20 | ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md 21 | data_format = "influx" 22 | 23 | ## Name a tag containing the name of the file the data was parsed from. Leave empty 24 | ## to disable. 25 | # file_tag = "" 26 | ``` 27 | 28 | [input data format]: /docs/DATA_FORMATS_INPUT.md 29 | [tail]: /plugins/inputs/tail 30 | -------------------------------------------------------------------------------- /plugins/outputs/application_insights/mocks/diagnostics_message_subscriber.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | package mocks 3 | 4 | import appinsights "github.com/microsoft/ApplicationInsights-Go/appinsights" 5 | 6 | import mock "github.com/stretchr/testify/mock" 7 | 8 | // DiagnosticsMessageSubscriber is an autogenerated mock type for the DiagnosticsMessageSubscriber type 9 | type DiagnosticsMessageSubscriber struct { 10 | mock.Mock 11 | } 12 | 13 | // Subscribe provides a mock function with given fields: _a0 14 | func (_m *DiagnosticsMessageSubscriber) Subscribe(_a0 appinsights.DiagnosticsMessageHandler) appinsights.DiagnosticsMessageListener { 15 | ret := _m.Called(_a0) 16 | 17 | var r0 appinsights.DiagnosticsMessageListener 18 | if rf, ok := ret.Get(0).(func(appinsights.DiagnosticsMessageHandler) appinsights.DiagnosticsMessageListener); ok { 19 | r0 = rf(_a0) 20 | } else { 21 | if ret.Get(0) != nil { 22 | r0 = ret.Get(0).(appinsights.DiagnosticsMessageListener) 23 | } 24 | } 25 | 26 | return r0 27 | } 28 | -------------------------------------------------------------------------------- /docs/METRICS.md: -------------------------------------------------------------------------------- 1 | # Metrics 2 | 3 | Telegraf metrics are the internal representation used to model data during 4 | processing. Metrics are closely based on InfluxDB's data model and contain 5 | four main components: 6 | 7 | - **Measurement Name**: Description and namespace for the metric. 8 | - **Tags**: Key/Value string pairs and usually used to identify the 9 | metric. 10 | - **Fields**: Key/Value pairs that are typed and usually contain the 11 | metric data. 12 | - **Timestamp**: Date and time associated with the fields. 13 | 14 | This metric type exists only in memory and must be converted to a concrete 15 | representation in order to be transmitted or viewed. To achieve this we 16 | provide several [output data formats][] sometimes referred to as 17 | *serializers*. Our default serializer converts to [InfluxDB Line 18 | Protocol][line protocol] which provides a high performance and one-to-one 19 | direct mapping from Telegraf metrics. 20 | 21 | [output data formats]: /docs/DATA_FORMATS_OUTPUT.md 22 | [line protocol]: /plugins/serializers/influx 23 | -------------------------------------------------------------------------------- /plugins/inputs/swap/swap_test.go: -------------------------------------------------------------------------------- 1 | package swap 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/influxdata/telegraf/plugins/inputs/system" 7 | "github.com/influxdata/telegraf/testutil" 8 | "github.com/shirou/gopsutil/mem" 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestSwapStats(t *testing.T) { 13 | var mps system.MockPS 14 | var err error 15 | defer mps.AssertExpectations(t) 16 | var acc testutil.Accumulator 17 | 18 | sms := &mem.SwapMemoryStat{ 19 | Total: 8123, 20 | Used: 1232, 21 | Free: 6412, 22 | UsedPercent: 12.2, 23 | Sin: 7, 24 | Sout: 830, 25 | } 26 | 27 | mps.On("SwapStat").Return(sms, nil) 28 | 29 | err = (&SwapStats{&mps}).Gather(&acc) 30 | require.NoError(t, err) 31 | 32 | swapfields := map[string]interface{}{ 33 | "total": uint64(8123), 34 | "used": uint64(1232), 35 | "used_percent": float64(12.2), 36 | "free": uint64(6412), 37 | } 38 | acc.AssertContainsTaggedFields(t, "swap", swapfields, make(map[string]string)) 39 | } 40 | -------------------------------------------------------------------------------- /plugins/inputs/temp/README.md: -------------------------------------------------------------------------------- 1 | # Temperature Input Plugin 2 | 3 | The temp input plugin gather metrics on system temperature. This plugin is 4 | meant to be multi platform and uses platform specific collection methods. 5 | 6 | Currently supports Linux and Windows. 7 | 8 | ### Configuration 9 | 10 | ```toml 11 | [[inputs.temp]] 12 | # no configuration 13 | ``` 14 | 15 | ### Metrics 16 | 17 | - temp 18 | - tags: 19 | - sensor 20 | - fields: 21 | - temp (float, celcius) 22 | 23 | 24 | ### Troubleshooting 25 | 26 | On **Windows**, the plugin uses a WMI call that is can be replicated with the 27 | following command: 28 | ``` 29 | wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature 30 | ``` 31 | 32 | ### Example Output 33 | 34 | ``` 35 | temp,sensor=coretemp_physicalid0_crit temp=100 1531298763000000000 36 | temp,sensor=coretemp_physicalid0_critalarm temp=0 1531298763000000000 37 | temp,sensor=coretemp_physicalid0_input temp=100 1531298763000000000 38 | temp,sensor=coretemp_physicalid0_max temp=100 1531298763000000000 39 | ``` 40 | -------------------------------------------------------------------------------- /plugins/inputs/csgo/README.md: -------------------------------------------------------------------------------- 1 | # Counter-Strike: Global Offensive (CSGO) Input Plugin 2 | 3 | The `csgo` plugin gather metrics from Counter-Strike: Global Offensive servers. 4 | 5 | #### Configuration 6 | ```toml 7 | # Fetch metrics from a CSGO SRCDS 8 | [[inputs.csgo]] 9 | ## Specify servers using the following format: 10 | ## servers = [ 11 | ## ["ip1:port1", "rcon_password1"], 12 | ## ["ip2:port2", "rcon_password2"], 13 | ## ] 14 | # 15 | ## If no servers are specified, no data will be collected 16 | servers = [] 17 | ``` 18 | 19 | ### Metrics 20 | 21 | The plugin retrieves the output of the `stats` command that is executed via rcon. 22 | 23 | If no servers are specified, no data will be collected 24 | 25 | - csgo 26 | - tags: 27 | - host 28 | - fields: 29 | - cpu (float) 30 | - net_in (float) 31 | - net_out (float) 32 | - uptime_minutes (float) 33 | - maps (float) 34 | - fps (float) 35 | - players (float) 36 | - sv_ms (float) 37 | - variance_ms (float) 38 | - tick_ms (float) 39 | -------------------------------------------------------------------------------- /plugins/parsers/json_v2/testdata/nested_and_nonnested_tags/expected.out: -------------------------------------------------------------------------------- 1 | file,hostname=testhost1,outputname=1A-CC01-PC01 systemVoltage=-54.1,systemCurrent=-3.8 2 | file,hostname=testhost1,outputname=2A-CC01-KA01 systemVoltage=-54.1,systemCurrent=-3.8 3 | file,hostname=testhost1,outputname=3A-CC01-CC02 systemVoltage=-54.1,systemCurrent=-3.8 4 | file,hostname=testhost1,outputname=4A systemVoltage=-54.1,systemCurrent=-3.8 5 | file,hostname=testhost1,outputname=5A systemVoltage=-54.1,systemCurrent=-3.8 6 | file,hostname=testhost1,outputname=6A-CC01-88-INV01-A systemVoltage=-54.1,systemCurrent=-3.8 7 | file,hostname=testhost2,outputname=1A systemVoltage=27.5,systemCurrent=9.5 8 | file,hostname=testhost2,outputname=2A systemVoltage=27.5,systemCurrent=9.5 9 | file,hostname=testhost2,outputname=3A systemVoltage=27.5,systemCurrent=9.5 10 | file,hostname=testhost2,outputname=4A systemVoltage=27.5,systemCurrent=9.5 11 | file,hostname=testhost2,outputname=5A systemVoltage=27.5,systemCurrent=9.5 12 | file,hostname=testhost2,outputname=6A systemVoltage=27.5,systemCurrent=9.5 13 | --------------------------------------------------------------------------------