grafana+graphit安装笔记

OS:MAC 10.11
查看测试线运行demo请访问http://10.103.13.101:3000/dashboard/db/graphite-carbon-metrics?editorTab=Options 

1 grafana

1)安装文档:
    http://docs.grafana.org/installation/mac/
    https://segmentfault.com/a/1190000000693520

2)运行service:brew service start grafana-server

3)查看配置: vim /usr/local/etc/grafana/grafana.ini
    a. http_port:3000
    b. localhost
    c. admin-amin(密码可以在页面的profile里修改)
    d. database

4)http or https
5)运行:在浏览器中输入localhost:3000,此时可以看到监控页面,用admin账户登入即可
6)比较智能,有多重角色控制,这块儿待开发


2 graphite

1)安装
sudo pip install whisper carbon graphite-web
默认安装目录: /opt/graphite

2)配置
https://segmentfault.com/a/1190000000693520
http://graphite.wikidot.com/installation
*http://blog.liulantao.com/blog/2014/2014-01-26-graphite-setup-notes.html
https://github.com/graphite-project/graphite-web
http://graphite.readthedocs.io/en/latest/
*http://blog.163.com/guaiguai_family/blog/static/20078414520140710515276/*
 
3)修改local_setting.py
务必重新设计SECRET_KEY,根据需要调整TIME_ZONE和其他参数,解注debug=true
根据提示创建需要的.log文件
跑数据,创建一个mysql库这个库只用作存储用户表和数据表结构,不用正式数据
python manage.py syncdb

4)run一下这个app吧!
python carbon-cache start
cd /opt/graphite
bin/run-graphite-devel-server.py  /opt/graphite
在浏览器中访问http://0.0.0.0:8080/ 嗯,此时看到一个看起来比较正常的管理页面

没有图,图片碎成了一个小点,心伤。 好吧,页面提示没有cairocffi模块,没有就安装呗,查了一下这个模块是Python绑定的一个2D标量图形库的面相对象api的集合,为多种图片类型提供了后台支持。嗯,不求甚解,了解一下就OK了。

pip install cairocffi

报错c/_cffi_backend.c:15:10: fatal error: 'ffi.h' file not found 
brew install pig-config libffi

再次充满了希望!

cannot import name constants

又失败了。。。

sudo pip install constants

dlopen() failed to load a library: cairo / cairo-2

这个问题比较诡异,这个github页有几个人很专注的讨论了这个问题https://github.com/SimonSapin/cairocffi/issues/29
安装方法sudo brew install cairo

酱,再次运行看起来就正常了

最后在页面测试的时候,还可能报一些文件不存在或者权限deny的错误,直接touch或者sudo就可以了

3 grafana+graphite

1)将二者结合到一起

https://segmentfault.com/a/1190000000693520 

找到config.js,修改datasources
/usr/local/Cellar/grafana/3.1.1/share/grafana/public/app/core/config.js

2)将二者结合到一起-2

    grafana的主菜单中有一个“Data Sources”菜单,点击进入,可以看到一个Data Sources列表,右上方有绿色的添加按钮“Add data source”,顾名思义可以添加数据源。

3)页面配置就慢慢探索吧,点点就会了,也可以参考grafana的官方文档

4 nginx
1)本机已经装了nginx,这块儿不表
2)配置nginx.conf
3)单独写了一个local.grafana.nginx 然后在nginx.conf里将这个配置include进来
    本机上配置的是8088端口,访问127.0.0.1:8088 可以看到配置成功,不过话说感觉这里配置个nginx也没有什么鸟用吧!
4)接下来,应该专心考虑数据集成和拟合了

5 数据集成拟合

1)后台数据处理这块进度略慢,一方面其他事情中断、另一方面更主要的是不熟悉。

2)上午熟悉了nc命令,测试了一下,正式log的导出应该不成问题了,在目的服务器上开一个nc监听端口nc -l 1234 > reseiveData.txt&,在源服务器上发送数据nc server_name server_port

3)metric

4)http://graphite.readthedocs.io/en/latest/           

做到之前的那一步就可以直接操作grafana配置了,真是强大啊,不用自己写代码,直接配置就能展示漂亮的页面和强大的聚合功能。接下来就是写写脚本啦~
写了一个小demo:
sync_data.sh 
#!/bin/bash
 
PORT=2003
SERVER=10.103.13.101

now_1mago=`date -d "1  minutes ago" +%y%m%d%H%M%S`
now=`date +%y%m%d%H%M%S`
now_1magotm=`date -d "1 minute ago" +%s`

# 项目名称
project=$1

sleep 30

logfile="/opt/logs/tornado/test1/*.log"
tmplogfile="/opt/log_collect/$num.log"
profile="/opt/log_collect/profile"
for i in `cat $profile`
do
    cat $logfile|grep '[0-9]\{6\}'|grep "$i"|tr -d ":"|awk '{a='"$now_1mago"';b='"$now"';c=$2 $3}(c>=a&&c<b){print $0}'|awk 'BEGIN{sum_error=0}{sum_error+=1} END {print "test.'"$project"'.'"$i"'",sum_error,"'$now_1magotm'"}' | nc ${SERVER} ${PORT} &
done
 

http://graphite-api.readthedocs.io/en/latest/api.html#format
 graphite给出的测试用例对于写脚本还是挺有用的,无非就是把数据整合成graphite能接受的格式,然后从2003端口发出去。

接上文,已经放弃mac中的脚本写作了,直接在linux上部署,grafana和graphite已经能访问了,转到测试服务器,centos5.5,接下来的工作要在centos5.5上开展,linux上的安装和配置稍有不同,但是大体步骤都是一样的,参考同一份文档即可!
 
粗糙整理,未完待续
 

posted @ 2016-09-20 16:47  bierxiaobia  阅读(977)  评论(1编辑  收藏  举报