Grafana 安裝與配置

百聯達發表於2017-10-26
一: 簡介

Grafana 是一個開源儀表盤工具,它可用於GraphiteInfluxDB與 OpenTSDB 一起使用。最新的版本還可以用於其他的資料來源,比如Elasticsearch。

從本質上說,它是一個功能豐富的Graphite-web 替代品,能幫助使用者更簡單地建立和編輯儀表盤。它包含一個獨一無二的Graphite目標解析器,從而可以簡化度量和函式的編輯

二: 安裝與配置

1.安裝
yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.5.2-1.x86_64.rpm

2.開機啟動配置
 systemctl daemon-reload
 systemctl start grafana-server
 systemctl status grafana-server

3.相關檔案目錄
Installs binary to /usr/sbin/grafana-server
Copies init.d script to /etc/init.d/grafana-server
Installs default file (environment vars) to /etc/sysconfig/grafana-server
Copies configuration file to /etc/grafana/grafana.ini
Installs systemd service (if systemd is available) name grafana-server.service
The default configuration uses a log file at /var/log/grafana/grafana.log
The default configuration specifies an sqlite3 database at /var/lib/grafana/grafana.db

4.應用頁面  http://ip:3000  使用者名稱/密碼:admin/admin


三:配置

1.通過rpm安裝,配置資訊在/etc/grafana/grafana.ini檔案中,通過安裝包安裝配置檔案在/usr/share/grafana/conf/目錄下。



通過啟動日誌可以看到,會讀取defaults.ini和grafana.ini的配置資訊, 因此如果要修改訪問埠(如3000改成3001)需要修改defaults.ini

配置檔案中的資訊,感覺有點奇怪。

2.dashboards配置

編輯配置檔案/etc/grafana/grafana.ini,修改dashboards.json段落下兩個引數的值:
[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards
一定要去掉開頭的分號(“;”)否則配置不起作用

安裝儀表盤(Percona提供),重新啟動應用
$ git clone https://github.com/percona/grafana-dashboards.git
$ cp -r grafana-dashboards/dashboards /var/lib/grafana/
systemctl restart grafana-server



四:同prometheus一起監控Mysql

1.Prometheus安裝   請參考上一篇博文

2.配置檔案


點選(此處)摺疊或開啟

  1. global:
  2.   scrape_interval: 15s
  3.   evaluation_interval: 15s

  4. scrape_configs:
  5.   - job_name: prometheus
  6.     static_configs:
  7.       - targets: ['localhost:9090']
  8.         labels:
  9.           instance: prometheus

  10.   - job_name: linux
  11.     static_configs:
  12.       - targets: ['10.10.0.186:9100']
  13.         labels:
  14.           instance: db1

  15.   - job_name: mysql
  16.     static_configs:
  17.       - targets: ['10.10.0.186:9104']
  18.         labels:
  19.           instance: db1
3.部署node_exporters和mysqld_exporters


點選(此處)摺疊或開啟

  1. $ wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.0.linux-amd64.tar.gz -O node_exporter-0.14.0.linux-amd64.tar.gz
  2. $ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz -O mysqld_exporter-0.10.0.linux-amd64.tar.gz
  3. $ mkdir /usr/local/services/prometheus_exporters
  4. $ tar zxf node_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local/services/prometheus_exporters --strip-components=1
  5. $ tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /usr/local/services/prometheus_exporters --strip-components=1

  6. $ cd /usr/local/services/prometheus_exporters
  7. $ ./node_exporter

  8. $ cd /usr/local/services/prometheus_exporters
  9. $ cat << EOF > .my.cnf
  10. [client]
  11. user=prom
  12. password=abc123
  13. EOF
  14. $ ./mysqld_exporter -config.my-cnf=".my.cnf"
檢視Prometheus  http://ip:9090



4.Grafana中建立Prometheus資料來源



5.伺服器監控結果畫面

6.Mysql資料庫監控結果畫面

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28624388/viewspace-2146458/,如需轉載,請註明出處,否則將追究法律責任。

相關文章