此工程主要为了能够方便的将telegraf嵌入其它golang工程之中,主要改造了telegraf的启动入口,以及配置文件加载方式
调用示例
package monitor
import (
"fmt"
"gitee.com/zhimiao/qiansi-telegraf/cmd/telegraf"
)
// 获取服务器远程配置(其实就是telegraf的配置文件内容)
func telegrafRemoteData() (result []byte, err error) {
return
}
// 启动
func Start() error {
// 获取服务器远程配置
data, err := telegrafRemoteData()
if err != nil {
return err
}
telegraf.Start(data)
return nil
}
// 重启
func Restart() error {
// 获取服务器远程配置
data, err := telegrafRemoteData()
if err != nil {
return err
}
telegraf.Restart(data)
return nil
}
自定义插件注入方法
// 采集&输出插件重点在于init方法中的添加操作,因此无论放在哪里,只要能通过`outputs.Add` 或者 `inputs.Add` 在运行前添加到插件列表中就可以了
package monitor
import (
"fmt"
"gitee.com/zhimiao/qiansi-client/common"
"gitee.com/zhimiao/qiansi-client/request"
"gitee.com/zhimiao/qiansi-telegraf"
"gitee.com/zhimiao/qiansi-telegraf/plugins/outputs"
"gitee.com/zhimiao/qiansi-telegraf/plugins/serializers"
"time"
)
type Qiansi struct {
Ok bool `toml:"ok"`
}
func (s *Qiansi) Description() string {
return "qiansi client output"
}
func (s *Qiansi) SampleConfig() string {
return `
ok = true
`
}
func (s *Qiansi) Init() error {
return nil
}
func (s *Qiansi) Connect() error {
// Make a connection to the URL here
return nil
}
func (s *Qiansi) Close() error {
// Close connection to the URL here
return nil
}
func (s *Qiansi) Write(metrics []telegraf.Metric) error {
ser, _ := serializers.NewJsonSerializer(time.Second)
r, _ := ser.SerializeBatch(metrics)
fmt.Println(string(r))
if common.Config.ENV() == "dev" {
fmt.Println(string(r))
}
// 推送到千丝服务端
request.MetricPush(r)
return nil
}
func init() {
outputs.Add("qiansi", func() telegraf.Output { return &Qiansi{} })
}
Telegraf is an agent for collecting, processing, aggregating, and writing metrics.
Design goals are to have a minimal memory footprint with a plugin system so that developers in the community can easily add support for collecting metrics.
Telegraf is plugin-driven and has the concept of 4 distinct plugin types:
- Input Plugins collect metrics from the system, services, or 3rd party APIs
- Processor Plugins transform, decorate, and/or filter metrics
- Aggregator Plugins create aggregate metrics (e.g. mean, min, max, quantiles, etc.)
- Output Plugins write metrics to various destinations
New plugins are designed to be easy to contribute, pull requests are welcomed and we work to incorporate as many pull requests as possible.
You can try Telegraf right in your browser in the Telegraf playground.
There are many ways to contribute:
- Fix and report bugs
- Improve documentation
- Review code and feature proposals
- Answer questions and discuss here on github and on the Community Site
- Contribute plugins
- Contribute external plugins (experimental)
Telegraf shares the same minimum requirements as Go:
- Linux kernel version 2.6.23 or later
- Windows 7 or later
- FreeBSD 11.2 or later
- MacOS 10.11 El Capitan or later
You can download the binaries directly from the downloads page or from the releases section.
Ansible role: https://github.com/rossmcdonald/telegraf
Telegraf requires Go version 1.12 or newer, the Makefile requires GNU make.
- Install Go >=1.12 (1.13 recommended)
- Clone the Telegraf repository:
cd ~/src git clone https://github.com/influxdata/telegraf.git
- Run
make
from the source directorycd ~/src/telegraf make
View the changelog for the latest updates and changes by version.
These builds are generated from the master branch:
- telegraf-nightly_darwin_amd64.tar.gz
- telegraf_nightly_amd64.deb
- telegraf_nightly_arm64.deb
- telegraf-nightly.arm64.rpm
- telegraf_nightly_armel.deb
- telegraf-nightly.armel.rpm
- telegraf_nightly_armhf.deb
- telegraf-nightly.armv6hl.rpm
- telegraf-nightly_freebsd_amd64.tar.gz
- telegraf-nightly_freebsd_i386.tar.gz
- telegraf_nightly_i386.deb
- telegraf-nightly.i386.rpm
- telegraf-nightly_linux_amd64.tar.gz
- telegraf-nightly_linux_arm64.tar.gz
- telegraf-nightly_linux_armel.tar.gz
- telegraf-nightly_linux_armhf.tar.gz
- telegraf-nightly_linux_i386.tar.gz
- telegraf-nightly_linux_s390x.tar.gz
- telegraf_nightly_s390x.deb
- telegraf-nightly.s390x.rpm
- telegraf-nightly_windows_amd64.zip
- telegraf-nightly_windows_i386.zip
- telegraf-nightly.x86_64.rpm
- telegraf-static-nightly_linux_amd64.tar.gz
See usage with:
telegraf --help
telegraf config > telegraf.conf
telegraf --section-filter agent:inputs:outputs --input-filter cpu --output-filter influxdb config
telegraf --config telegraf.conf --test
telegraf --config telegraf.conf
telegraf --config telegraf.conf --input-filter cpu:mem --output-filter influxdb
For documentation on the latest development code see the documentation index.
- activemq
- aerospike
- amqp_consumer (rabbitmq)
- apache
- apcupsd
- aurora
- aws cloudwatch (Amazon Cloudwatch)
- azure_storage_queue
- bcache
- beanstalkd
- bind
- bond
- burrow
- cassandra (deprecated, use jolokia2)
- ceph
- cgroup
- chrony
- cisco_telemetry_gnmi
- cisco_telemetry_mdt
- clickhouse
- cloud_pubsub Google Cloud Pub/Sub
- cloud_pubsub_push Google Cloud Pub/Sub push endpoint
- conntrack
- consul
- couchbase
- couchdb
- cpu
- DC/OS
- diskio
- disk
- disque
- dmcache
- dns query time
- docker
- docker_log
- dovecot
- aws ecs (Amazon Elastic Container Service, Fargate)
- elasticsearch
- ethtool
- eventhub_consumer (Azure Event Hubs & Azure IoT Hub)
- exec (generic executable plugin, support JSON, influx, graphite and nagios)
- execd
- fail2ban
- fibaro
- file
- filestat
- filecount
- fireboard
- fluentd
- github
- graylog
- haproxy
- hddtemp
- httpjson (generic JSON-emitting http service plugin)
- http_listener (deprecated, renamed to influxdb_listener)
- http_listener_v2
- http (generic HTTP plugin, supports using input data formats)
- http_response
- icinga2
- infiniband
- influxdb
- influxdb_listener
- internal
- interrupts
- ipmi_sensor
- ipset
- iptables
- ipvs
- jenkins
- jolokia2 (java, cassandra, kafka)
- jolokia (deprecated, use jolokia2)
- jti_openconfig_telemetry
- kafka_consumer
- kapacitor
- aws kinesis (Amazon Kinesis)
- kernel
- kernel_vmstat
- kibana
- kubernetes
- kube_inventory
- lanz
- leofs
- linux_sysctl_fs
- logparser (deprecated, use tail)
- logstash
- lustre2
- mailchimp
- marklogic
- mcrouter
- memcached
- mem
- mesos
- minecraft
- modbus
- mongodb
- monit
- mqtt_consumer
- multifile
- mysql
- nats_consumer
- nats
- neptune_apex
- net
- net_response
- netstat
- nginx
- nginx_plus_api
- nginx_plus
- nginx_upstream_check
- nginx_vts
- nsq_consumer
- nsq
- nstat
- ntpq
- nvidia_smi
- openldap
- openntpd
- opensmtpd
- openweathermap
- pf
- pgbouncer
- phpfpm
- phusion passenger
- ping
- postfix
- postgresql_extensible
- postgresql
- powerdns
- powerdns_recursor
- processes
- procstat
- prometheus (can be used for Caddy server)
- puppetagent
- rabbitmq
- raindrops
- redis
- rethinkdb
- riak
- salesforce
- sensors
- sflow
- smart
- snmp_legacy
- snmp
- snmp_trap
- socket_listener
- solr
- sql server (microsoft)
- stackdriver (Google Cloud Monitoring)
- statsd
- suricata
- swap
- synproxy
- syslog
- sysstat
- systemd_units
- system
- tail
- temp
- tcp_listener
- teamspeak
- tengine
- tomcat
- twemproxy
- udp_listener
- unbound
- uwsgi
- varnish
- vsphere VMware vSphere
- webhooks
- win_perf_counters (windows performance counters)
- win_services
- wireguard
- wireless
- x509_cert
- zfs
- zipkin
- zookeeper
- InfluxDB Line Protocol
- Collectd
- CSV
- Dropwizard
- FormUrlencoded
- Graphite
- Grok
- JSON
- Logfmt
- Nagios
- Value, ie: 45 or "booyah"
- Wavefront
- clone
- converter
- date
- dedup
- defaults
- enum
- filepath
- override
- parser
- pivot
- printer
- regex
- rename
- s2geo
- strings
- tag_limit
- template
- topk
- unpivot
- influxdb (InfluxDB 1.x)
- influxdb_v2 (InfluxDB 2.x)
- amon
- amqp (rabbitmq)
- application_insights
- aws kinesis
- aws cloudwatch
- azure_monitor
- cloud_pubsub Google Cloud Pub/Sub
- cratedb
- datadog
- discard
- elasticsearch
- exec
- file
- graphite
- graylog
- health
- http
- instrumental
- kafka
- librato
- mqtt
- nats
- nsq
- opentsdb
- prometheus
- riemann
- riemann_legacy
- socket_writer
- stackdriver (Google Cloud Monitoring)
- syslog
- tcp
- udp
- warp10
- wavefront