[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.3node
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
mysql
Telegraf是用Go寫的代理程序,能夠用於收集系統和服務的統計數據,是TICK技術棧的一部分。它具有輸入插件,能夠直接從系統獲取指標數據,從第三方API獲取指標數據,甚至能夠經過statsd和Kafka獲取指標數據。它還具有輸出插件,能夠將採集的指標發送到各類數據存儲,服務和消息隊列。好比InfluxDB,Graphite,OpenTSDB,Datadog,Librato,Kafka,MQTT,NSQ等等,目前Telegraf尚不支持Oracle數據庫統計數據的實時監控。
sql
來自於官網: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
• 自帶壓力測試工具等,功能強大vim
Grafana是一個開源指標分析和可視化套件,經常使用於可視化基礎設施的性能數據和應用程序分析的時間序列數據。也能夠應用於其餘領域,包括工業傳感器,家庭自動化,天氣和過程控制。但請注意,咱們使用Grafana最關心的是如何把數據進行聚合後進行展現。
Grafana支持多種不一樣的時序數據庫數據源,Grafana對每種數據源提供不一樣的查詢方法,並且能很好的支持每種數據源的特性。它支持下面幾種數據源:Graphite、Elasticsearch、CloudWatch、InfluxDB、OpenTSDB、Prometheus、MySQL、Postgres、Microsoft SQL Server (MSSQL)。每種數據源都有相應的文檔,能夠將多個數據源的數據合併到一個單獨的儀表板上。bash
[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"
配置基本監控項less
[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監控項curl
[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,添加須要的數據源
tcp
建立主機儀表盤
ide
能夠經過訪問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
http://www.javashuo.com/article/p-mqeowmxv-hp.html