telegraf输出MySQL_Grafana+influxdb+telegraf初探-快速监控主机与mysql
一、安裝
1.1、配置influxdb yum源
[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
1.2、安裝Grafana+influxdb+telegraf
安裝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
1.3、軟件版本
InfluxDB version: 1.7.4
Telegraf version: 1.10.2
Grafana version: 6.1.3
1.4、啟動服務(wù),添加開機啟動
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
1.5、查看grafana界面
grafana默認(rèn)監(jiān)聽在3000端口,默認(rèn)用戶名admin,密碼admin
二、數(shù)據(jù)采集之telegraf
Telegraf是用Go寫的代理程序,可以用于收集系統(tǒng)和服務(wù)的統(tǒng)計數(shù)據(jù),是TICK技術(shù)棧的一部分。它具備輸入插件,可以直接從系統(tǒng)獲取指標(biāo)數(shù)據(jù),從第三方API獲取指標(biāo)數(shù)據(jù),甚至可以通過statsd和Kafka獲取指標(biāo)數(shù)據(jù)。它還具備輸出插件,可以將采集的指標(biāo)發(fā)送到各種數(shù)據(jù)存儲,服務(wù)和消息隊列。比如InfluxDB,Graphite,OpenTSDB,Datadog,Librato,Kafka,MQTT,NSQ等等,目前Telegraf尚不支持Oracle數(shù)據(jù)庫統(tǒng)計數(shù)據(jù)的實時監(jiān)控。
三、數(shù)據(jù)存儲之InfluxDB
InfluxDB是一個時間序列數(shù)據(jù)庫,旨在處理高寫入和查詢負載,主要用于存儲系統(tǒng)的監(jiān)控數(shù)據(jù)
InfluxDB有三大特性:
? Time Series (時間序列):可以使用與時間有關(guān)的相關(guān)函數(shù)(如最大,最小,求和等)
? Metrics(度量):你可以實時對大量數(shù)據(jù)進行計算
? Eevents(事件):它支持任意的事件數(shù)據(jù)
特點
? Schemaless(無結(jié)構(gòu)),可以是任意數(shù)量的列
? Scalable(可擴展):min, max, sum, count, mean, median 一系列函數(shù),方便統(tǒng)計
? Native HTTP API, 內(nèi)置http支持,使用http讀寫
? Powerful Query Language 類似sql
? 自帶壓力測試工具等,功能強大
四、數(shù)據(jù)展示之Grafana
Grafana是一個開源指標(biāo)分析和可視化套件,常用于可視化基礎(chǔ)設(shè)施的性能數(shù)據(jù)和應(yīng)用程序分析的時間序列數(shù)據(jù)。也可以應(yīng)用于其他領(lǐng)域,包括工業(yè)傳感器,家庭自動化,天氣和過程控制。但請注意,我們使用Grafana最關(guān)心的是如何把數(shù)據(jù)進行聚合后進行展示。
Grafana支持多種不同的時序數(shù)據(jù)庫數(shù)據(jù)源,Grafana對每種數(shù)據(jù)源提供不同的查詢方法,而且能很好的支持每種數(shù)據(jù)源的特性。它支持下面幾種數(shù)據(jù)源:Graphite、Elasticsearch、CloudWatch、InfluxDB、OpenTSDB、Prometheus、MySQL、Postgres、Microsoft SQL Server (MSSQL)。每種數(shù)據(jù)源都有相應(yīng)的文檔,可以將多個數(shù)據(jù)源的數(shù)據(jù)合并到一個單獨的儀表板上。
五、配置監(jiān)控主機狀態(tài)及mysql運行狀態(tài)
5.1、創(chuàng)建數(shù)據(jù)庫
[root@node ~]# influx
> create user "mysql-server"with password '123456'
> create database myserverDB
5.2、配置本機的influxdb數(shù)據(jù)庫為期望的輸出源-output
[root@node ~]# vim /etc/telegraf/telegraf.conf
[[outputs.influxdb]]
urls = ["http://127.0.0.1:8086"]
database = "myserverDB"
5.3、配置監(jiān)控項-input
配置基本監(jiān)控項
[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監(jiān)控項
[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"
5.4、配置grafana界面
選擇Data Sources,添加需要的數(shù)據(jù)源
創(chuàng)建主機儀表盤
可以通過訪問https://grafana.com/dashboards 來查看已經(jīng)由其他用戶共享的儀表盤,選取合適的使用,縮短上手時間
將合適的模版import導(dǎo)入,我這里用的是https://grafana.com/dashboards/1443, 注意模版與telegraf input配置一致。
可以看到如下界面
六、通過自定義腳本采集監(jiān)控數(shù)據(jù)
6.1、在influxdb數(shù)據(jù)庫創(chuàng)建mysql_run_status庫
create user "admin" with password '123456'
create database mysql_run_status
6.2、在被監(jiān)控主機上創(chuàng)建監(jiān)控腳本,并開啟mysql
通過influxDB數(shù)據(jù)庫http接口上傳數(shù)據(jù),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"
6.3、執(zhí)行監(jiān)控腳本,查看入庫情況
./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
6.4、grafana展示
連接數(shù)據(jù)源
創(chuàng)建儀表盤
總結(jié)
以上是生活随笔為你收集整理的telegraf输出MySQL_Grafana+influxdb+telegraf初探-快速监控主机与mysql的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jsp标签 判断 余数_程序员的数学基础
- 下一篇: sha256校验工具_使用AIDE工具做