FXMAR 发表于 2019-1-20 09:33:49

zabbix2.2安装grafana

  1、操作环境
CentOS release 6.4 (Final)
Kernel \r on an \m
# uname -r
2.6.32-358.el6.x86_64
# uname -m
x86_64  

  

  2、下载grafana以及安装
# wget https://grafanarel.s3.amazonaws.com/builds/grafana-2.1.1-1.x86_64.rpm
# yum install grafana-2.1.1-1.x86_64.rpm -y  

  

  3、下载zabbix的grafana插件,以及配置相关文件
# git clone https://github.com/linglong0820/grafana-zabbix
# cp -r grafana-zabbix/zabbix/ /usr/share/grafana/public/app/plugins/datasource  4、启动grafana
# /etc/init.d/grafana-server start
Starting Grafana Server: .... OK  

  5、修改zabbix的api文件api_jsonrpc.php
# pwd
/usr/share/zabbix
# vim api_jsonrpc.php网上找的内容如下:
修改Zabbix的API文件,由于Zabbix2.2不支持跨域的问题,故添加以下配置:
#sudo vim /usr/share/zabbix/
api_jsonrpc.php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Max-Age: 1000');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    return;
}
#在此之前添加
require_once dirname(__FILE__).'/include/func.inc.php';
require_once dirname(__FILE__).'/include/classes/class.chttp_request.php';
注意:如果是2.4以上版本,请忽略此配置(无需更改api_jsonrpc.php文件)  






  6、注意这里是Zabbix的WEB API用户和密码(不一定非得是Admin,普通用户即可,具有可读权限),假如你不能确定用户名密码是否对,用如下shell命令测试:
# pwd
/usr/share/grafana/public/app/plugins/datasource/zabbix
# cat plugin.json
{
"pluginType": "datasource",
"name": "Zabbix",
"type": "zabbix",
"serviceName": "ZabbixAPIDatasource",
"module": "plugins/datasource/zabbix/datasource",
"partials": {
    "config": "app/plugins/datasource/zabbix/partials/config.html",
    "query": "app/plugins/datasource/zabbix/partials/query.editor.html",
    "annotations": "app/plugins/datasource/zabbix/partials/annotations.editor.html"
},
"username": "test",
"password": "test",
"trends": false,
"trendsFrom": "7d",
"limitmetrics": 100,
"metrics": true,
"annotations": true
}  

  shell命令测试
# curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc": "2.0","method":"user.authenticate","params":{"user":"test","password":"test"},"auth": null,"id":0}' http://127.0.0.1/zabbix/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Tue, 26 Apr 2016 01:44:08 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 68
Connection: close
Content-Type: application/json
{"jsonrpc":"2.0","result":"8375dc88a89f08229b0feb1b50d4d843","id":0}  注:成功后就可以配置grafana了
  7、配置grafana
  默认的登录用户和密码是admin
http://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://s5.运维网.com/wyfs02/M01/7F/7D/wKioL1cgmiPhQUWfAAL5RA_MIRw156.png
http://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://s1.运维网.com/wyfs02/M02/7F/7D/wKioL1cgmlfTrUIxAAIW-FMsgko121.png
http://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://s4.运维网.com/wyfs02/M01/7F/7D/wKioL1cgmoCARkYUAAJjyZcmyzE106.png
  8、添加grafana的图形
http://s4.运维网.com/wyfs02/M01/7F/7E/wKioL1cgmzrwVo9GAAFxvu8Ng5c672.pnghttp://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://s5.运维网.com/wyfs02/M02/7F/80/wKiom1cgmrmRgdbmAACdpK_Ny4o947.png
http://s3.运维网.com/wyfs02/M00/7F/7E/wKioL1cgm5SwfyA1AAKJZJULWkA756.png
http://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://s2.运维网.com/wyfs02/M00/7F/80/wKiom1cgmtjxMSxiAAP6GKKHEJw928.pnghttp://s2.运维网.com/wyfs02/M01/7F/7E/wKioL1cgm-_BEubhAAP6GKKHEJw506.pnghttp://s2.运维网.com/wyfs02/M02/7F/80/wKiom1cgm0LR83p8AAKJpdqC5Ro440.pnghttp://s5.运维网.com/wyfs02/M02/7F/7E/wKioL1cgnB6AU1DoAAQkkRSmm58620.pnghttp://s2.运维网.com/wyfs02/M00/7F/80/wKiom1cgm3Czi_EkAAHMVhFuopE089.png
  

  以上就是grafana的配置图形,收工。
  




页: [1]
查看完整版本: zabbix2.2安装grafana