diff --git a/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/grafana-6.3.0-1.x86_64.rpm b/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/grafana-6.3.0-1.x86_64.rpm new file mode 100644 index 0000000..e04af29 Binary files /dev/null and b/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/grafana-6.3.0-1.x86_64.rpm differ diff --git a/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/influxdb-1.7.7.x86_64.rpm b/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/influxdb-1.7.7.x86_64.rpm new file mode 100644 index 0000000..4df5dfc Binary files /dev/null and b/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/influxdb-1.7.7.x86_64.rpm differ diff --git a/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/telegraf-1.11.4-1.x86_64.rpm b/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/telegraf-1.11.4-1.x86_64.rpm new file mode 100644 index 0000000..21d3483 Binary files /dev/null and b/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/telegraf-1.11.4-1.x86_64.rpm differ diff --git a/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/安装文档.md b/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/安装文档.md new file mode 100644 index 0000000..a596326 --- /dev/null +++ b/基于Telegraf+InfluxDB+Grafana展示FieldStat的数据/安装文档.md @@ -0,0 +1,206 @@ +# 基于 Telegraf + InfluxDB + Grafana 展示 FieldStat 数据的安装文档 # + +## 交互图 + +``` + 采集数据 ++------------+ +| FieldStat2 | ++------------+ + | + | udp + | 192.168.10.152:8125 + \|/ ++----------+ http +----------+ http +----------+ +| Telegraf | -----------------> | InfluxDB | -----------------> | Grafana | ++----------+ 127.0.0.1:8086 +----------+ 127.0.0.1:8086 +----------+ + 聚合数据 存储数据 展示数据 +``` + +## 更新系统时间 + +在所有机器上执行下列命令,更新系统时间,避免时间偏差。 + +```sh +ntpdate us.pool.ntp.org +``` + +## influxdb + +**安装** + +> 最新的 InfluxDB 1.x 是稳定版本,推荐用于生产;InfluxDB 2.0 处于 alpha 阶段,不建议用于生产。 + +``` sh +wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.7.x86_64.rpm +yum localinstall influxdb-1.7.7.x86_64.rpm +``` + +* influxdb 为服务端 +* influx 为客户端工具 + +**配置** + +采用默认配置即可,配置文件路径 `/etc/influxdb/influxdb.conf` + +``` sh +influxdb config 查看配置 +``` + +**启动** + +``` sh +systemctl start/stop/status/restart influxdb +``` + +**开机自启动** + +``` sh +systemctl enable influxdb.service 设置 +systemctl list-unit-files | grep influxdb.service 查看 +``` + +**创建数据库** + +1.启动 influx 客户端 + +`-precision rfc3339` 表示以 `rfc3339` 格式显示时间,方便阅读。 + +``` sql +influx 或 influx -precision rfc3339 +``` + +2.创建名为 telegraf 的数据库 + +``` sql +create database telegraf +``` + +3.切换到 telegraf 数据库 + +``` sql +use telegraf +``` + +4.创建用户名为 telegraf 密码为 telegraf 的用户,注意用户名用双引号,密码用单引号 + +``` sql +create user "telegraf" with password 'telegraf' +``` + +5.设置数据保留策略,如果不设置则采用默认策略(autogen),数据永久保存 + +``` sql +CREATE RETENTION POLICY "1_year" ON telegraf DURATION 365d REPLICATION 1 +ALTER RETENTION POLICY "1_year" ON telegraf DURATION 365d REPLICATION 1 default +``` + +6.显示当前数据库中的所有表 + +``` sql +show measurements +``` + +7.插入数据 + +若未提供时间戳,influxdb 则分配当前的时间戳 +格式:",key1=val1,key2=val2",其中的 就是通常说的表名,例如: + +``` sql +INSERT cpu,host=serverA,region=us_west value=0.64 +``` + +8.查询数据 + +`tz('Asia/Shanghai')` 表示按照上海的 +8 时区显示时间。 +`tz('Asia/Bishkek')` 表示按照哈萨克斯坦的 +6 时区显示时间。 + +``` sh +SELECT "host", "region", "value" FROM "cpu" tz('Asia/Shanghai') +SELECT * FROM /.*/ 使用正则,表示查询所有的表 +``` +## telegraf + +**安装** + +``` sh +wget https://dl.influxdata.com/telegraf/releases/telegraf-1.11.4-1.x86_64.rpm +yum localinstall telegraf-1.11.4-1.x86_64.rpm +``` + +**配置** + +配置文件路径:`/etc/telegraf/telegraf.conf` + +``` +[agent] + hostname = "192.168.10.38" +# 当 telegraf 与数据源 fieldstat 布置到同一台机器上时设置 hostname 才有意义。 +# 用于 influxdb 的 host 列用于区分数据来源于哪台机器。 + +[[outputs.influxdb]] + urls = ["http://127.0.0.1:8086"] + database = "telegraf" + username = "telegraf" + password = "telegraf" + +[[inputs.statsd]] + protocol = "udp4" + service_address = ":8125" 设置聚合器接收数据的端口 + percentiles = [50,80,90,95] 建议与 fieldstat 的配置一致 + percentile_limit = 100000000 +``` + +**启动** + +``` sh +systemctl start/stop/status/restart telegraf +``` +**开机自启动** + +``` sh +systemctl enable telegraf.service 设置 +systemctl list-unit-files | grep telegraf.service 查看 +``` +## grafana + +**安装** + +``` sh +wget https://dl.grafana.com/oss/release/grafana-6.3.0-1.x86_64.rpm +yum localinstall grafana-6.3.0-1.x86_64.rpm +``` + +**配置** + +配置文件路径:/etc/grafana/grafana.ini +更改配置后需要重启服务。 + +**启动** + +``` sh +systemctl start/stop/status/restart grafana-server +``` + +**开机自启动** + +``` sh +systemctl enable grafana-server.service 设置 +systemctl list-unit-files | grep grafana-server.service 查看 +``` + +**管理** + +``` +端口:3000 +账号:admin +密码:admin +``` + +**配置** + +* tfe 中使用的都是 FS_CALC_CURRENT +* FS_STYLE_FIELD : 建议只统计该类型的数据 +* FS_STYLE_STATUS : 类型的数据入 fluxdb 有插入 + +> SELECT sum("value") / 60 FROM "[tfe3a]http_sess" WHERE $timeFilter GROUP BY time(1m) fill(0)