1、操作环境
CentOS release 6.4 (Final) Kernel \r on an \m [[email protected] ~]# uname -r 2.6.32-358.el6.x86_64 [[email protected] ~]# uname -m x86_64
2、下载grafana以及安装
[[email protected] ~]# wget https://grafanarel.s3.amazonaws.com/builds/grafana-2.1.1-1.x86_64.rpm [[email protected] ~]# yum install grafana-2.1.1-1.x86_64.rpm -y
3、下载zabbix的grafana插件,以及配置相关文件
[[email protected] ~]# git clone https://github.com/linglong0820/grafana-zabbix [[email protected] datasource]# cp -r grafana-zabbix/zabbix/ /usr/share/grafana/public/app/plugins/datasource
4、启动grafana
[[email protected] ~]# /etc/init.d/grafana-server start Starting Grafana Server: .... OK
5、修改zabbix的api文件api_jsonrpc.php
[[email protected] zabbix]# pwd /usr/share/zabbix [[email protected] 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命令测试:
[[email protected] zabbix]# pwd /usr/share/grafana/public/app/plugins/datasource/zabbix [[email protected] 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命令测试
[[email protected] zabbix]# 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
8、添加grafana的图形
以上就是grafana的配置图形,收工。
时间: 2024-12-08 10:06:10