[root@node ~]# cat /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
安装influxdb
yum install influxdb
安装telegraf
yum install telegraf
安装grafana
wget https://dl.grafana.com/oss/release/grafana-6.1.3-1.x86_64.rpm
yum localinstall grafana-6.1.3-1.x86_64.rpm
InfluxDB version: 1.7.4
Telegraf version: 1.10.2
Grafana version: 6.1.3
systemctl start influxdb.service
systemctl start telegraf.service
systemctl start grafana-server.service
systemctl enable influxdb.service
systemctl enable telegraf.service
systemctl enable grafana-server.service
grafana默认监听在3000端口,默认用户名admin,密码admin
Telegraf是用Go写的代理程序,可以用于收集系统和服务的统计数据,是TICK技术栈的一部分。它具备输入插件,可以直接从系统获取指标数据,从第三方API获取指标数据,甚至可以通过statsd和Kafka获取指标数据。它还具备输出插件,可以将采集的指标发送到各种数据存储,服务和消息队列。比如InfluxDB,Graphite,OpenTSDB,Datadog,Librato,Kafka,MQTT,NSQ等等,目前Telegraf尚不支持Oracle数据库统计数据的实时监控。
来自于官网:https://www.influxdata.com/time-series-platform/telegraf/
InfluxDB是一个时间序列数据库,旨在处理高写入和查询负载,主要用于存储系统的监控数据
InfluxDB有三大特性:
• Time Series (时间序列):可以使用与时间有关的相关函数(如最大,最小,求和等)
• Metrics(度量):你可以实时对大量数据进行计算
• Eevents(事件):它支持任意的事件数据
特点
• Schemaless(无结构),可以是任意数量的列
• Scalable(可扩展):min, max, sum, count, mean, median 一系列函数,方便统计
• Native HTTP API, 内置http支持,使用http读写
• Powerful Query Language 类似sql
• 自带压力测试工具等,功能强大
Grafana是一个开源指标分析和可视化套件,常用于可视化基础设施的性能数据和应用程序分析的时间序列数据。也可以应用于其他领域,包括工业传感器,家庭自动化,天气和过程控制。但请注意,我们使用Grafana最关心的是如何把数据进行聚合后进行展示。
Grafana支持多种不同的时序数据库数据源,Grafana对每种数据源提供不同的查询方法,而且能很好的支持每种数据源的特性。它支持下面几种数据源:Graphite、Elasticsearch、CloudWatch、InfluxDB、OpenTSDB、Prometheus、MySQL、Postgres、Microsoft SQL Server (MSSQL)。每种数据源都有相应的文档,可以将多个数据源的数据合并到一个单独的仪表板上。
[root@node ~]# influx
> create user "mysql-server"with password '123456'
> create database myserverDB
[root@node ~]# vim /etc/telegraf/telegraf.conf
[[outputs.influxdb]]
urls = ["http://127.0.0.1:8086"]
database = "myserverDB"
配置基本监控项
[root@node ~]# cat /etc/telegraf/telegraf.d/telegraf.conf
[[inputs.net]]
interfaces = ["eth0,eth1,lo"]
[[inputs.cpu]]
##Whether to report per-cpu stats or not
percpu = true
##Whether to report total system cpu stats or not
totalcpu = true
## Iftrue, collect raw CPU time metrics.
collect_cpu_time = false
# Read metrics about disk usage by mountpoint
[[inputs.disk]]
## Bydefault, 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]]
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.processes]]
[[inputs.swap]]
[[inputs.system]]
[[inputs.netstat]]
配置mysql监控项
[root@node ~]# cat /etc/telegraf/telegraf.d/telegraf_mysql.conf
[[inputs.mysql]]
interval = "5m"
servers = ["tcp(127.0.0.1:3306)/"]
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"
选择Data Sources,添加需要的数据源
创建主机仪表盘
可以通过访问https://grafana.com/dashboards 来查看已经由其他用户共享的仪表盘,选取合适的使用,缩短上手时间
将合适的模版import导入,我这里用的是https://grafana.com/dashboards/1443, 注意模版与telegraf input配置一致。
可以看到如下界面
创建mysql仪表盘
import https://grafana.com/dashboards/1177
create user "admin" with password '123456'
create database mysql_run_status
通过influxDB数据库http接口上传数据,0为up,1为down
[root@node2 local]# systemctl start mariadb
[root@node2 local]# cat mysql_status.sh
#!/bin/bash
systemctl status mariadb.service |grep running &>/dev/null
if [ $? -eq 0 ];then
echo "mysql_status=0" > temp_mysql_run
else
echo "mysql_status=1" > temp_mysql_run
fi
IP=192.168.143.131
test=`cat temp_mysql_run`
curl -i -XPOST 'http://192.168.143.130:8086/write?db=mysql_run_status' --data-binary "mysql_run_status,ip=$IP,$test count=1"
./mysql_status.sh &> /dev/null
> select * from mysql_run_status
name: mysql_run_status
time count ip mysql_status
---- ----- -- ------------
1556267694277201332 1 192.168.143.131 0
连接数据源
创建仪表盘
参考文章
https://www.influxdata.com/time-series-platform/telegraf/
https://docs.influxdata.com/telegraf/v1.10/
https://docs.influxdata.com/influxdb/v1.7/
https://grafana.com/grafana
https://juejin.im/post/5b4568c851882519790c72f3
转载于:https://blog.51cto.com/jiayimeng/2378086