Grafana數據可視化

1.1 Grafana簡介

1.1.1 Grafana是什麼?

一個相似Kibana的東西,也是對後端的數據進行實時展現,那麼GrafanaKibana有什麼區別?在我看來區別不大,不過在你們的平常使用中Kibana是跟着LogstashElasticSearch等組件一塊兒使用作日誌展現、索引、分析的,形成了一種假象就是Kibana就只有這種用法了,Kibana也能夠接入其餘數據源的,不過你們最長用的仍是展現日誌。html

那麼Grafana究竟是什麼呢?Grafana其實就是一個可視化面板(Dashboard),有着很是漂亮的圖表和佈局展現,功能齊全的度量儀表盤和圖形編輯器,支持GraphitezabbixInfluxDBPrometheusOpenTSDB做爲數據源。隨着版本的迭代,支持接入的數據源將會更多。git

下面看看官方是怎麼解釋Grafana的:github

 grafana是用於可視化大型測量數據的開源程序,他提供了強大和優雅的方式去建立、共享、瀏覽數據。dashboard中顯示了你不一樣metric數據源中的數據。web

 grafana最經常使用於因特網基礎設施和應用分析,但在其餘領域也有機會用到,好比:工業傳感器、家庭自動化、過程控制等等。 redis

 grafana有熱插拔控制面板和可擴展的數據源,目前已經支持Graphite、InfluxDB、OpenTSDB、Elasticsearch。json

Grafana官方網站:https://grafana.com/                                        後端

1.1.2 如何獲取Grafana

訪問Grafana下載頁面https://grafana.com/grafana/download在這裏可獲取該軟件的全版本。api

能夠按照使用需求,進行下載相應版本。瀏覽器

 

1.2 安裝Grafana

1.2.1 系統環境說明

[root@monitor.clsn.io /root]
#cat  /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 

[root@monitor.clsn.io /root]
#uname -r 
3.10.0-862.el7.x86_64

[root@monitor.clsn.io /root]
#systemctl  status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

[root@monitor.clsn.io /root]
#sestatus 
SELinux status:                 disabled

1.2.2 安裝Grafana

在此次安裝中,咱們使用的是grafana-5.2.4版本。不一樣版本之間功能存在着必定的差距。服務器

[root@monitor.clsn.io /root]
#wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.4-1.x86_64.rpm

[root@monitor.clsn.io /root]
#ls
grafana-5.2.4-1.x86_64.rpm

[root@monitor.clsn.io /root]
#sudo yum localinstall grafana-5.2.4-1.x86_64.rpm

1.2.3 啓動Grafana

[root@monitor.clsn.io /root]
#systemctl  start grafana-server.service

[root@monitor.clsn.io /root]
#systemctl enable grafana-server.service

1.2.4 檢查監聽端口

Grafana默認監聽端口爲3000,能夠經過修改配置文件(/etc/grafana/grafana.ini)對其作定製化配置。

[root@monitor.clsn.io /root]
#netstat  -lntup |grep grafana
tcp6       0      0 :::3000                 :::*                    LISTEN      1333/grafana-server

1.3 Grafana的使用

1.3.1 訪問界面

經過流量器訪問 http://ip:3000 便可訪問grafana頁面,初始用戶名與密碼均爲admin,可在登錄是修改默認密碼。

登錄成功以後能夠先進行建立第一個數據源,以及第一個展現面板。

  

1.3.2 Grafana For Zabbix

使用Zabbix收集數據,Grafana展現圖形,許多的公司都是這麼作的。Grafana默認沒有zabbix做爲數據源,咱們須要手動給zabbix安裝一個插件,而後再添加進Grafana便可。

關於zabbix的安裝能夠參照如下文章進行配置。

慘綠少年博客:http://www.javashuo.com/article/p-tsgzrpxb-nb.html

zabbix官方文檔:https://www.zabbix.com/documentation/3.4/zh/manual

注:本次使用zabbix版本爲3.4.14

[root@monitor.clsn.io /root]
#zabbix_server -V
zabbix_server (Zabbix) 3.4.14
Revision 84877 14 September 2018, compilation time: Sep 14 2018 08:09:35

Copyright (C) 2018 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

1.3.3 獲取grafana for zabbix 插件

經過grafana-cli plugins list-remote命令 能夠獲取到grafana的插件列表。

[root@monitor.clsn.io /root]
#grafana-cli plugins list-remote  |grep  zabbix
id: alexanderzobnin-zabbix-app version: 3.9.1

   從上能夠查詢到插件版本爲3.9.1

安裝插件

[root@monitor.clsn.io /root]
#grafana-cli plugins install alexanderzobnin-zabbix-app
installing alexanderzobnin-zabbix-app @ 3.9.1
from url: https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/3.9.1/download
into: /var/lib/grafana/plugins

✔ Installed alexanderzobnin-zabbix-app successfully 
Restart grafana after installing plugins . <service grafana-server restart>

   出現√即爲安裝成功。在安裝完成後無比重啓grafana使其生效。

[root@monitor.clsn.io /root]
#systemctl  restart grafana-server.service

1.3.4 配置zabbix

登錄grafana頁面,開啓zabbix插件。

 

   點擊enable開啓插件。

 

   添加zabbix數據源

 

相關配置項目說明:

配置項目

說明

Name

給數據源起一個名字。

Default

選擇默認,意味着數據源將預先選定爲新的面板。

Type

選擇數據源的類型。

Url

這裏的Urlhttp協議,地址和端口是zabbix-web提供的接口。或爲zabbixapi地址。

Access

訪問代理,這裏選擇了proxy表示Grfana經過後端訪問,還有direct值表示從瀏覽器直接訪問目錄。

Username

輸入zabbix的用戶名,須要進行認證,通常使用管理員。

Password

輸入zabbix用戶的密碼。

代理(proxy)訪問意味着的Grafana後端將從瀏覽器代理全部請求,並將它們發送到數據源。這樣是有用的,由於它能夠消除CORS(交叉來源站點資源)的問題,如消除須要傳播到數據源到瀏覽器的身份驗證詳細信息。但還支持直接(direct)訪問,由於在某些狀況下可能用來訪問直接根據用例和拓撲結構的Grafana 用戶和數據源的數據源。

以上信息都填寫完成以後點擊Save & Test,通常只要看見Success就表示成功了,下面就能夠去利用zabbix中數據添加圖形了。

下面先引入zabbix自帶的dashboard,點擊import

 

1.3.5 查看zabbix dashboard頁面

 

   使用grafana的好處是對圖形的自定義更加簡便,經過變動不一樣的json文件,便可在數據源中查找到想要的結果,而後繪製出圖。

 

1.4 附錄

1.4.1 grafana-cli命令

安裝插件最簡單的方法是使用與grafana捆綁在一塊兒的CLI工具grafana-cli。在修改插件以後發生任何修改以前,grafana服務器須要從新啓動。

Grafana插件安裝目錄

Linux系統上,grafana-cli會假定grafana插件目錄是/var/lib/grafana/plugins。經過指定-pluginsDir標誌能夠覆蓋grafana-cli將要運行的目錄。在Windows系統中,必須爲每一個呼叫指定此參數

Grafana-cli命令說明

列出可用的插件
#grafana-cli plugins list-remote

安裝最新版本的插件
#grafana-cli plugins install <plugin-id>

安裝特定版本的插件
#grafana-cli plugins install <plugin-id> <version>

列出安裝的插件
#grafana-cli plugins ls

更新全部安裝的插件
#grafana-cli plugins update-all

更新一個插件
#grafana-cli plugins update <plugin-id>

刪除一個插件
#grafana-cli plugins remove <plugin-id>

1.5 參考文獻

 [1]  http://www.javashuo.com/article/p-tsgzrpxb-nb.html

 [2]  http://www.ywnds.com/?cat=122

 [3]  https://github.com/grafana/grafana/

 [4]  https://grafana.com/grafana/download

 [5]  http://www.javashuo.com/article/p-slzbcysq-co.html

 [6]  http://www.javashuo.com/article/p-uhwymrth-p.html

相關文章
相關標籤/搜索