Telegraf是TICK堆栈中的度量收集代理。
在安装之前先安装InfluxDB和Chronograf 。
1.下载Telegraf镜像
docker pull telegraf
2.创建数据目录
/root/runenv/opt/docker/telegraf
/root/runenv/opt/docker/telegraf/run
3.导出默认配置文件
docker run --rm telegraf telegraf config > telegraf.conf
4.修改配置文件
主要修改 urls、database、username、password、timeout等配置项
[[outputs.influxdb]]
## The full HTTP or UDP URL for your InfluxDB instance.
##
## Multiple URLs can be specified for a single cluster, only ONE of the
## urls will be written to each interval.
# urls = ["unix:///var/run/influxdb.sock"]
# urls = ["udp://127.0.0.1:8089"]
# urls = ["http://127.0.0.1:8086"]
urls = ["http://ip:8086"]
## The target database for metrics; will be created as needed.
## For UDP url endpoint database needs to be configured on server side.
database = "telegraf"
## The value of this tag will be used to determine the database. If this
## tag is not set the 'database' option is used as the default.
# database_tag = ""
## If true, no CREATE DATABASE queries will be sent. Set to true when using
## Telegraf with a user without permissions to create databases or when the
## database already exists.
# skip_database_creation = false
## Name of existing retention policy to write to. Empty string writes to
## the default retention policy. Only takes effect when using HTTP.
#retention_policy = "1h"
## Write consistency (clusters only), can be: "any", "one", "quorum", "all".
## Only takes effect when using HTTP.
# write_consistency = "any"
## Timeout for HTTP messages.
timeout = "5s"
## HTTP Basic Auth
username = "用户"
password = "密码"
## HTTP User-Agent
# user_agent = "telegraf"
## UDP payload size is the maximum packet size to send.
# udp_payload = "512B"
## Optional TLS Config for use on HTTP connections.
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
## HTTP Proxy override, if unset values the standard proxy environment
## variables are consulted to determine which proxy, if any, should be used.
# http_proxy = "http://corporate.proxy:3128"
## Additional HTTP headers
# http_headers = {"X-Special-Header" = "Special-Value"}
## HTTP Content-Encoding for write request body, can be set to "gzip" to
## compress body or "identity" to apply no encoding.
# content_encoding = "identity"
## When true, Telegraf will output unsigned integers as unsigned values,
## i.e.: "42u". You will need a version of InfluxDB supporting unsigned
## integer values. Enabling this option will result in field type errors if
## existing data has been written.
# influx_uint_support = false
5.配置数据库
在InfluxDB中创建数据库同配置文件中的 database 参数
创建用户同配置文件中的 username 和 password 参数
6.启动服务
docker run -d --name=telegraf -v /root/runenv/opt/docker/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro -v /root/runenv/opt/docker/telegraf/run:/var/run telegraf
7.配置Chronograf
Telegraf Database Name 填写上面配置文件中配置的 database
Username 和 Password 填写上面配置文件中配置的 username 和 password
Kapacitor 没有配置,这里选 Skip
8.配置 Dashboard 的查询
选择刚才设置的 Influxdb 连接
选择 DB.RetentionPolicy,这里选testdb.autogen,选择 Measurements 及 Tags 作为 From 和 Where,选择 Fields 作为 Select,生成查询条件后可手动进行修改,点击 Group By XXX 将该条件加到 GROUP BY 中。
可以输入图的名称或其他一些设置后,点击右上角的对勾按钮进行保存
9.在 Dashboard 中查看,可以修改此 Dashboard 的名称。
至此设置完成,更多功能请大家自己尝试。