Yume 練功地

偷偷練

telegraf

文件

產生 config file

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

Start Telegraf Server

X Homebrew
1
telegraf -config telegraf.conf
debian and RPM packages
1
sudo service telegraf start
1
systemctl start telegraf

Config

Output Plugin List

Input Plugin List

[agent]

interval: 預設搜集所有輸入的時間間隔 Default data collection interval for all inputs
round_interval: Rounds collection interval to ‘interval’ ie, if interval=”10s” then always collect on :00, :10, :20, etc.
metric_buffer_limit: Telegraf will cache metric_buffer_limit metrics for each output, and will flush this buffer on a successful write.
collection_jitter: Collection jitter is used to jitter the collection by a random amount. Each plugin will sleep for a random time within jitter before collecting. This can be used to avoid many plugins querying things like sysfs at the same time, which can have a measurable effect on the system.
flush_interval: Default data flushing interval for all outputs. You should not set this below interval. Maximum flush_interval will be flush_interval + flush_jitter
flush_jitter: Jitter the flush interval by a random amount. This is primarily to avoid large write spikes for users running a large number of telegraf instances. ie, a jitter of 5s and flush_interval 10s means flushes will happen every 10-15s.
debug: Run telegraf in debug mode.
quiet: Run telegraf in quiet mode.
hostname: Override default hostname, if empty use os.Hostname().

[inputs.xxx]

name_override: Override the base name of the measurement. (Default is the name of the input).
name_prefix: Specifies a prefix to attach to the measurement name.
name_suffix: Specifies a suffix to attach to the measurement name.
tags: A map of tags to apply to a specific inputs measurements.
interval: How often to gather this metric. Normal plugins use a single global interval, but if one particular input should be run less or more often, you can configure that here.

Input filter

pass: An array of strings that is used to filter metrics generated by the current input. Each string in the array is tested as a glob match against field names and if it matches, the field is emitted.
drop: The inverse of pass, if a field name matches, it is not emitted.
tagpass: tag names and arrays of strings that are used to filter measurements by the current input. Each string in the array is tested as a glob match against the tag name, and if it matches the measurement is emitted.
tagdrop: The inverse of tagpass. If a tag matches, the measurement is not emitted. This is tested on measurements that have passed the tagpass test.

tagdrop
1
2
3
4
5
6
7
8
# 不搜集 cpu6 cpu7 的 cpu 資料
[[inputs.cpu]]
percpu = true
totalcpu = false
drop = ["cpu_time"]
# Don't collect CPU data for cpu6 & cpu7
[inputs.cpu.tagdrop]
cpu = [ "cpu6", "cpu7" ]
tagpass

tagpass conditions are OR, not AND.

1
2
3
4
5
6
7
8
9
# 如果 filesystem 是 ext4 或 xfs 或者路徑為 /opt 或 /home 可以通過
[[inputs.disk]]
[inputs.disk.tagpass]
# tagpass conditions are OR, not AND.
# If the (filesystem is ext4 or xfs) OR (the path is /opt or /home)
# then the metric passes
fstype = [ "ext4", "xfs" ]
# Globs can also be used on the tag values
path = [ "/opt", "/home*" ]
drop
1
2
3
4
5
6
7
8
9
10
#過濾掉開頭為 time_ 的欄位(fields)
[[inputs.cpu]]
# filter all fields beginning with 'time_'
drop = ["time_*"]

# Drop all metrics for guest & steal CPU usage
[[inputs.cpu]]
percpu = false
totalcpu = true
drop = ["usage_guest", "usage_steal"]
pass
1
2
3
4
# 只有 inode 相關能通過
# Only store inode related metrics for disks
[[inputs.disk]]
pass = ["inodes*"]
prefix, suffix
1
2
3
4
5
# cpu_total
[[inputs.cpu]]
name_suffix = "_total"
percpu = false
totalcpu = true
override
1
2
3
4
5
# foobar
[[inputs.cpu]]
name_override = "foobar"
percpu = false
totalcpu = true
tags
1
2
3
4
5
6
7
# 多兩個 tag,分別是 tag1=foo 跟 tag2=bar
[[inputs.cpu]]
percpu = false
totalcpu = true
[inputs.cpu.tags]
tag1 = "foo"
tag2 = "bar"
Multiple inputs of the same type
1
2
3
4
5
6
7
8
9
10
# 建議搭配使用 name_override, name_prefix, or name_suffix
[[inputs.cpu]]
percpu = false
totalcpu = true

[[inputs.cpu]]
percpu = true
totalcpu = false
name_override = "percpu_usage"
drop = ["cpu_time*"]