使用telegraf,influxdb,grafana打造颜值爆表的监控系统(三)-telegraf安装

简介

Telegraf是一个用于收集和报告指标的插件驱动的服务器代理,是TICK堆栈的第一部分。Telegraf具有插件,可直接从运行的系统获取各种指标,从第三方API提取指标,甚至通过statsd和Kafka消费者服务监听指标。它还具有输出插件,用于向各种其他数据存储,服务和消息队列发送指标,包括InfluxDB,Graphite,OpenTSDB,Datadog,Librato,Kafka,MQTT,NSQ等。

安装

1
2
wget https://dl.influxdata.com/telegraf/releases/telegraf-1.2.1.x86_64.rpm
sudo yum localinstall telegraf-1.2.1.x86_64.rpm

配置

默认配置文件在这里

1
/etc/telegraf/telegraf.conf

在下面的示例中,我们创建一个名为telegraf.conf的配置文件,其中包含两个输入:一个用于读取有关系统cpu使用率(cpu)的度量标准,另一个用于读取有关系统内存使用率(mem)的度量标准。我们将InfluxDB指定为所需的输出。

1
telegraf -sample-config -input-filter cpu:mem -output-filter influxdb > /etc/telegraf/telegraf.conf

这里分享一个我目前用的telegraf的部分配置文件,主要是对主机的监控

telegraf input插件配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[[inputs.net]]
# ## By default, telegraf gathers stats from any up interface (excluding loopback)
# ## Setting interfaces will tell it to gather these explicit interfaces,
# ## regardless of status.
# ##
interfaces = ["eth0"]
[[inputs.cpu]]
## Whether to report per-cpu stats or not
percpu = true
## Whether to report total system cpu stats or not
totalcpu = true
## If true, collect raw CPU time metrics.
collect_cpu_time = false
# Read metrics about disk usage by mount point
[[inputs.disk]]
## By default, telegraf gather stats for all mountpoints.
## Setting mountpoints will restrict the stats to the specified mountpoints.
# mount_points = ["/"]

## Ignore some mountpoints by filesystem type. For example (dev)tmpfs (usually
## present on /run, /var/run, /dev/shm or /dev).
ignore_fs = ["tmpfs", "devtmpfs"]
# Read metrics about disk IO by device
[[inputs.diskio]]
## By default, telegraf will gather stats for all devices including
## disk partitions.
## Setting devices will restrict the stats to the specified devices.
# devices = ["sda", "sdb"]
## Uncomment the following line if you need disk serial numbers.
# skip_serial_number = false


# Get kernel statistics from /proc/stat
[[inputs.kernel]]
# no configuration


# Read metrics about memory usage
[[inputs.mem]]
# no configuration


# Get the number of processes and group them by status
[[inputs.processes]]
# no configuration


# Read metrics about swap memory usage
[[inputs.swap]]
[[inputs.system]]
[[inputs.netstat]]

telegraf output插件配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[[outputs.influxdb]]
## The full HTTP or UDP endpoint URL for your InfluxDB instance.
## Multiple urls can be specified as part of the same cluster,
## this means that only ONE of the urls will be written to each interval.
# urls = ["udp://localhost:8089"] # UDP endpoint example
urls = ["http://localhost:8086"] # required
## The target database for metrics (telegraf will create it if not exists).
database = "telegraf" # required

## Retention policy to write to. Empty string writes to the default rp.
retention_policy = ""
## Write consistency (clusters only), can be: "any", "one", "quorum", "all"
write_consistency = "any"

## Write timeout (for the InfluxDB client), formatted as a string.
## If not provided, will default to 5s. 0s means no timeout (not recommended).
timeout = "5s"
# username = "telegraf"
# password = "metricsmetricsmetricsmetrics"
## Set the user agent for HTTP POSTs (can be useful for log differentiation)
# user_agent = "telegraf"
## Set UDP payload size, defaults to InfluxDB UDP Client default (512 bytes)
# udp_payload = 512

## Optional SSL Config
# ssl_ca = "/etc/telegraf/ca.pem"
# ssl_cert = "/etc/telegraf/cert.pem"
# ssl_key = "/etc/telegraf/key.pem"
## Use SSL but skip chain & host verification
# insecure_skip_verify = false

启动

1
sudo service telegraf start

日志

默认的日志文件在/var/log/telegraf/telegfrad.log

更多的数据收集请参考官档的插件介绍

参考

https://docs.influxdata.com/telegraf/v1.2/

坚持原创技术分享,您的支持将鼓励我继续创作!