监控系统搭建 influxdb+ telegraf + stat
环境: ubuntu 18+
1 安装 influxdb
install influxdb文档
influxdb 是一个开源的时间序列数据库,高性能读写
增加源
wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
apt get and start influxdb
udo apt-get update && sudo apt-get install influxdb
sudo systemctl unmask influxdb.service
sudo systemctl start influxdb
influxdb 绑定的端口
TCP port 8086 is available for client-server communication using the InfluxDB HTTP API.
TCP port 8088 is available for the RPC service to perform back up and restore operations.
查看版本
influx -version
默认配置文件/etc/influxdb/influxdb.conf
简单命令
打开 influxdb shell influx
show databases;
use <DB NAME>
show measurements # 类似 mysql show tables
select * from <MEASUREMENT NAME>
install telegraf
增加 influxdb repo
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
install by apt and start
sudo apt-get update && sudo apt-get install telegraf
sudo systemctl start telegraf
查看版本
telegraf -version
配置文件 /etc/telegraf/telegraf.conf
配置 influxdb 作为输出源,默认数据库名字是 telegraf
[[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"]
重启 telegraf sudo systemctl restart telegraf
打开 influx, 执行 show databases
应该能看到 telegraf 数据库
3. 将 statsd 作为输入源
StatsD
Plugin ID: statsd
The StatsD input plugin is a special type of plugin which runs a backgrounded statsd
listener service while Telegraf is running. StatsD messages are formatted as described in the original etsy statsdimplementation.
配置按照 github的 example
改完 config ,restart telegraf
install grafana
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install grafana
sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-server
配置
配置文件 /etc/grafana/grafana.ini
简单使用
启动服务后访问http://localhost:3000,默认端口为3000,可在配置文件修改。默认用户名和密码为admin/admin。登录后按照提示配置数据源:
nginx 配置
location /grafana/ {
include proxy_params;
proxy_pass http://localhost:3000/;
proxy_buffering off;
}
grafana.ini 文件里 改 root_url,如下
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana
重启 grafana 服务
登录, 配置 data source