1.1 Grafana簡介
1.1.1 Grafana是什么?
一個類似Kibana的東西,也是對后端的數據進行實時展示,那么Grafana和Kibana有什么區別?在我看來區別不大,不過在大家的日常使用中Kibana是跟着Logstash、ElasticSearch等組件一起使用做日志展示、索引、分析的,造成了一種假象就是Kibana就只有這種用法了,Kibana也可以接入其他數據源的,不過大家最長用的還是展示日志。
那么Grafana到底是什么呢?Grafana其實就是一個可視化面板(Dashboard),有着非常漂亮的圖表和布局展示,功能齊全的度量儀表盤和圖形編輯器,支持Graphite、zabbix、InfluxDB、Prometheus和OpenTSDB作為數據源。隨着版本的迭代,支持接入的數據源將會更多。
下面看看官方是怎么解釋Grafana的:
grafana是用於可視化大型測量數據的開源程序,他提供了強大和優雅的方式去創建、共享、瀏覽數據。dashboard中顯示了你不同metric數據源中的數據。
grafana最常用於因特網基礎設施和應用分析,但在其他領域也有機會用到,比如:工業傳感器、家庭自動化、過程控制等等。
grafana有熱插拔控制面板和可擴展的數據源,目前已經支持Graphite、InfluxDB、OpenTSDB、Elasticsearch。
Grafana官方網站:https://grafana.com/
1.1.2 如何獲取Grafana
訪問Grafana下載頁面https://grafana.com/grafana/download在這里可獲取該軟件的全版本。
可以按照使用需求,進行下載相應版本。
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的安裝可以參照以下文章進行配置。
慘綠少年博客:https://www.cnblogs.com/clsn/p/7885990.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 |
這里的Url是http協議,地址和端口是zabbix-web提供的接口。或為zabbix的api地址。 |
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] https://www.cnblogs.com/clsn/p/7885990.html
[2] http://www.ywnds.com/?cat=122
[3] https://github.com/grafana/grafana/
[4] https://grafana.com/grafana/download
[5] https://blog.csdn.net/m0_37814112/article/details/80476364