作者:lee某某 | 来源:互联网 | 2023-09-06 16:21
夜莺从5.1版本开始,拥抱开源社区,支持OpenTSDB的协议格式,支持Telegraf、Prometheus生态的exporter(也就是说,他们自己不做agent了)。具体落地实践时,建议优先选用Telegraf(all-in-one的架构,运维简单)
一、使用TELEGRAF采集监控数据(https://n9e.gitee.io/quickstart/telegraf/)
1.telegraf下载地址:https://github.com/influxdata/telegraf/releases
2.在centos8.2中安装telegraf(/opt/telegraf/telegraf.conf的内容是个删减版,只是为了让大家快速跑起来,如果要采集更多监控对象,比如mysql、redis、tomcat等,请往下看)
#!/bin/sh
version=1.20.4
tarball=telegraf-${version}_linux_amd64.tar.gz
wget https://dl.influxdata.com/telegraf/releases/$tarball
tar xzvf $tarball
mkdir -p /opt/telegraf
cp -far telegraf-${version}/usr/bin/telegraf /opt/telegraf
cat < /etc/telegraf/telegraf.conf
[global_tags]
[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
hostname = ""
omit_hostname = false
logfile = "/var/log/telegraf.log"
[[outputs.opentsdb]]
host = "http://127.0.0.1"
port = 19000
http_batch_size = 50
http_path = "/opentsdb/put"
debug = false
separator = "_"
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = true
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
[[inputs.diskio]]
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.processes]]
[[inputs.system]]
fielddrop = ["uptime_format"]
[[inputs.net]]
ignore_protocol_stats = true
EOF
cat < /etc/systemd/system/telegraf.service
[Unit]
Description="telegraf"
After=network.target
[Service]
Type=simple
ExecStart=/opt/telegraf/telegraf --config-directory /etc/telegraf/
WorkingDirectory=/opt/telegraf
Restart=on-failure
SuccessExitStatus=0
LimitNOFILE=65536
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=telegraf
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable telegraf
systemctl restart telegraf
systemctl status telegraf
3.使用telegraf采集mysql、redis、tomcat
cat < /etc/telegraf/mysql.conf
[[inputs.mysql]]
interval = "5m"
servers = ["root:root@tcp(127.0.0.1:3306)/?tls=false"]
perf_events_statements_digest_text_limit = 120
perf_events_statements_limit = 250
perf_events_statements_time_limit = 86400
table_schema_databases = [""]
gather_table_schema = false
gather_process_list = true
gather_info_schema_auto_inc = true
gather_slave_status = true
gather_binary_logs = false
gather_table_io_waits = false
gather_table_lock_waits = false
gather_index_io_waits = false
gather_event_waits = false
gather_file_events_stats = false
interval_slow = "30m"
[[inputs.tcp_listener]]
service_address = ":8094"
allowed_pending_messages = 10000
max_tcp_connections = 250
data_format = "influx"
[[inputs.exec]]
commands = ["/tmp/test.sh"]
timeout = "5m"
data_format = "influx"
name_suffix = "_mycollector"
[[inputs.redis]]
## specify servers via a url matching:
## [protocol://][:password]@address[:port]
## e.g.
servers = ['tcp://127.0.0.1:6379']
EOF
4.其中inputs.exec是可以写脚本(shell或者python都可以)获取自己需要的监控数据,简单示例如下(注意标签中如果不包含数据会导致写入失败)
cat < /tmp/test.sh
#!/bin/sh
echo "sinoc estab=27,closed=40"
EOF