
工具介绍前端

1. Statsd 是一个使用Node开发网络守护进程,它的特色是经过UDP(性能好,及时挂了也不影响主服务)或者TCP来监听各类数据信息,而后发送聚合数据到后端服务进行处理。常见支持的「Graphite」,「ElasticaSearch」,「InfluxDB」 等等 ,它集成了各类语言的客户端API,这里咱们使用了jsocol/pystatsd: A Python client for statsd进行数据收集。nginx
2. Graphite 是一套Python写的开源编程接口,主要是用来收集服务器的及时状态,在这里主要做为statsd的数据后端。分为了三个子项目git
- carbon 守护进程,接收StatsD发送过来的原始统计数据。github
- whisper 用来存储统计数据的时间序列数据库。web
- graphite webapp 用来图形化展现统计数据的web项目数据库
3. Grafana 使用Go开发,能够在界面上设计调整本身的统计图表,支持多重报警,可定制化。apache
安装编程
在这里我使用了[synthesize(https://github.com/obfuscurity/synthesize)进行快速安装Graphite和Statsd包,这里面须要注意安装数据在 **/opt/graphite ** 目录下面。这里面咱们安装启动了后端
service carbon-cache start # statsd数据处理后会进入中转
service memcached start # 缓存
service collectd start # 收集服务负载可选
service apache2 start # 这能够经过使用nginx替换
service statsite start # statsd的后端服务
这里面须要单独启动graphite-web应用,端口启动:0.0.0.0:8080,后面配置数据源须要使用。缓存
cd /opt/graphite/
sudo ./run-graphite-devel-server.py /opt/graphite/
Grafana数据包能够经过手动下载安装也能够经过apt-get 安装
- sudo apt-get install grafana
启动以后访问3000端口就能看到这样一个页面,默认的帐号密码:admin,admin能够经过配置github或者google登陆。

login
数据收集
Python端咱们使用statsd进行数据统一打点到到监控服务器收集
>>> import statsd
>>> c = statsd.StatsClient('localhost', 8125)
>>> c.incr('foo') # Increment the 'foo' counter.
>>> c.timing('stats.timed', 320) # Record a 320ms 'stats.timed'.
这里面咱们经过Python把数据收集到statsite,经过Graphite Web服务来进行展现。
配置Graphite
进入Grafana后台,进行配置点击 「Data Sources」进行配置Graphite的数据(来自前端statsd收集)

data_source
接下来配置对应的数据展现:

add-graph
到此基本的数据配置就完了,恭喜你拥有了一个完整的监控系统。
为了方便理解这里我补充一下,数据从应用内,添加agent,把应用的时间性能数据经过statsd收集发送到服务端,经过carbon统计,whisper存储最后展现在graphite,其中这里面咱们用grafana来替代了graphite原生的UI展现,也就是咱们题图的效果。