标签(空格分隔): Graphite Carbon Whisper 监控前端
注:该系列文章绝对是学习 Graphite 的好文章,是我见过的将的最全面,最清晰,最简单明了的系列文章。我会把该系列的全部文章所有翻译完成,可是仍是推荐各位读读原文。python
在 Graphite 系列博客中,我将提供一个指南,以帮助使用 Graphite 技术栈完成搭建一个监控和报警系统的全部步骤。声明:我不是一个专家,我仅仅是经过提供更详细的文档帮助 Graphite 社区发展。若是出现一些错误,请在文章下面评论或者是给我发送一封邮件到 feangulo@yaipan.com。git
Graphite 是由多个后端和前端组件组合而成。后端组件被用于存储数值的时间序列数据。前端组件被用于检索度量数据和可选的图像渲染。在这篇博客文章中,我将重点介绍后端组件:Carbon 和 Whisper。github
度量指标能够被发布到一个负载均衡器或者是直接到一个 Carbon 进程。Carbon 进程与 Whisper 数据库包交互来存储时间序列数据到文件系统。web
Carbon 是一个 daemon,其使用一个名为 Twisted 的事件驱动网络引擎来监听时间序列数据。Twisted 框架支持 Carbon 进程以较低的开销处理大量的客户端和处理大量的流量。数据库
为了安装 Carbon,运行如下命令(假设是 RHEL 操做系统):后端
# sudo yum groupinstall "Development Tools" # sudo yum install python-devel # sudo yum install git # sudo easy_install pip # sudo pip install twisted # cd /tmp # git clone https://github.com/graphite-project/carbon.git # cd /tmp/carbon # sudo python setup.py install
/opt/graphite
如今应该有 carbon 的 lib 包和配置文件:网络
# ls -l /opt/graphite total 16 drwxr-xr-x. 2 root root 4096 May 18 23:56 bin drwxr-xr-x. 2 root root 4096 May 18 23:56 conf drwxr-xr-x. 4 root root 4096 May 18 23:56 lib drwxr-xr-x. 6 root root 4096 May 18 23:56 storage
Whisper 是一个用于存储时间序列数据的数据库包,它被应用经过使用 create, update, 和 fetch 操做来检索以及操做。app
为了安装 Whisper,运行如下命令:负载均衡
# cd /tmp # git clone https://github.com/graphite-project/whisper.git # cd /tmp/whisper # sudo python setup.py install
Whisper 脚本如今应该在应有的位置上:
# ls -l /usr/bin/whisper* -rwxr-xr-x. 1 root root 1711 May 19 00:00 /usr/bin/whisper-create.py -rwxr-xr-x. 1 root root 2902 May 19 00:00 /usr/bin/whisper-dump.py -rwxr-xr-x. 1 root root 1779 May 19 00:00 /usr/bin/whisper-fetch.py -rwxr-xr-x. 1 root root 1121 May 19 00:00 /usr/bin/whisper-info.py -rwxr-xr-x. 1 root root 674 May 19 00:00 /usr/bin/whisper-merge.py -rwxr-xr-x. 1 root root 5982 May 19 00:00 /usr/bin/whisper-resize.py -rwxr-xr-x. 1 root root 1060 May 19 00:00 /usr/bin/whisper-set-aggregation-method.py -rwxr-xr-x. 1 root root 969 May 19 00:00 /usr/bin/whisper-update.py
Carbon 安装自带了默认的端口和不少其余的配置文件。拷贝已经存在的示例文件。
# cd /opt/graphite/conf # cp aggregation-rules.conf.example aggregation-rules.conf # cp blacklist.conf.example blacklist.conf # cp carbon.conf.example carbon.conf # cp carbon.amqp.conf.example carbon.amqp.conf # cp relay-rules.conf.example relay-rules.conf # cp rewrite-rules.conf.example rewrite-rules.conf # cp storage-schemas.conf.example storage-schemas.conf # cp storage-aggregation.conf.example storage-aggregation.conf # cp whitelist.conf.example whitelist.conf # vi carbon.conf
在 cache 段下面,line receiver port 已经被指定:
[cache] LINE_RECEIVER_INTERFACE = 0.0.0.0 LINE_RECEIVER_PORT = 2003
经过运行如下命令启动一个 carbon-cache 进程:
# cd /opt/graphite/bin # ./carbon-cache.py start Starting carbon-cache (instance a)
该进程如今应该监听在 2003 端口上:
# ps -efla | grep carbon-cache 1 S root 2674 1 0 80 0 - 75916 ep_pol 00:18 ? 00:00:03 /usr/bin/python ./carbon-cache.py start # netstat -nap | grep 2003 tcp 0 0 0.0.0.0:2003 0.0.0.0:* LISTEN 2674/python
一个度量值是任何能够随时间变化的可测量的值:
一个数据点是一个元组包含:
客户端应用经过发送数据点到一个 Carbon 进程来发布度量值。这个应用在 Carbon 进程的端口上创建一个 TCP 链接并以一个简单的纯文本格式发送数据点。在咱们的例子中,端口是 2003。TCP 链接或许依旧是打开并根据须要重复屡次使用。Carbon 进程监听进入的数据可是不给客户端发送任何响应。
数据点格式被定义成:
好比,这里有一些有效的数据点:
客户端应用有多个方式来发布度量值:
为了简单起见,在这个教程中我将经过 netcat 命令使用纯文本协议。为了发布以上列出的示例数据点,运行如下命令:
sudo yum install nc echo "carbon.agents.graphite-tutorial.metricsReceived 28198 `date +%s`" | nc localhost 2003 echo "carbon.agents.graphite-tutorial.creates 8 `date +%s`" | nc localhost 2003 echo "PRODUCTION.host.graphite-tutorial.responseTime.p95 0.10 `date +%s`" | nc localhost 2003
carbon-cache 日志文件将包含关于新的被接收到的度量值的信息,信息被存储在:
# tail -f /opt/graphite/storage/log/carbon-cache/carbon-cache-a/creates.log 19/05/2014 10:42:44 :: creating database file /opt/graphite/storage/whisper/carbon/agents/graphite-tutorial/metricsReceived.wsp (archive=[(60, 129600)] xff=0.5 agg=average) 19/05/2014 10:42:53 :: creating database file /opt/graphite/storage/whisper/carbon/agents/graphite-tutorial/creates.wsp (archive=[(60, 129600)] xff=0.5 agg=average) 19/05/2014 10:42:57 :: creating database file /opt/graphite/storage/whisper/PRODUCTION/host/graphite-tutorial/responseTime/p95.wsp (archive=[(60, 1440)] xff=0.5 agg=average)
Carbon 与 Whisper 交互来存储时间序列数据到文件系统。操做文件系统来确保数据文件已经被建立:
# ls -l /opt/graphite/storage/whisper/carbon/agents/graphite-tutorial/ total 3040 -rw-r--r--. 1 root root 1555228 May 19 10:42 creates.wsp -rw-r--r--. 1 root root 1555228 May 19 10:42 metricsReceived.wsp # ls -l /opt/graphite/storage/whisper/PRODUCTION/host/graphite-tutorial/responseTime/ total 20 -rw-r--r--. 1 root root 17308 May 19 10:42 p95.wsp
最后,你能够检索关于 Whisper 文件的元数据信息,使用 whisper-info 脚本:
# whisper-info.py /opt/graphite/storage/whisper/PRODUCTION/host/graphite-tutorial/responseTime/p95.wsp maxRetention: 86400 xFilesFactor: 0.5 aggregationMethod: average fileSize: 17308 Archive 0 retention: 86400 secondsPerPoint: 60 points: 1440 size: 17280 offset: 28
whisper-dump 脚本是一个更完整的脚本,其能够输出全部存储保留时期的原始数据以及关于 Whisper 文件的元数据信息:
# whisper-dump.py /opt/graphite/storage/whisper/PRODUCTION/host/graphite-tutorial/responseTime/p95.wsp Meta data: aggregation method: average max retention: 86400 xFilesFactor: 0.5 Archive 0 info: offset: 28 seconds per point: 60 points: 1440 retention: 86400 size: 17280 Archive 0 data: 0: 1400609220, 0.1000000000000000055511151231257827 1: 0, 0 2: 0, 0 3: 0, 0 4: 0, 0 5: 0, 0 ... 1437: 0, 0 1438: 0, 0 1439: 0, 0
弄明白 Aggregation 方法,最大的保留期, xFilesFactor 和 Whisper 文件的全部其余属性是很是重要的。不要担忧,就算你在这点上没有学习到,我将会在接下来的博客文章会更详细地讲诉这些。
Graphite 系列 :
本文的做者是 franklinangulo,本文的原文是 GRAPHITE SERIES #2: CARBON & WHISPER