Graphite 系列 #2:Carbon 和 Whisper

标签(空格分隔): Graphite Carbon Whisper 监控


注:该系列文章绝对是学习 Graphite 的好文章,是我见过的将的最全面,最清晰,最简单明了的系列文章。我会把该系列的所有文章全部翻译完成,但是还是推荐各位读读原文。

在 Graphite 系列博客中,我将提供一个指南,以帮助使用 Graphite 技术栈完成搭建一个监控和报警系统的所有步骤。声明:我不是一个专家,我仅仅是通过提供更详细的文档帮助 Graphite 社区发展。如果出现一些错误,请在文章下面评论或者是给我发送一封邮件到 feangulo@yaipan.com。


Graphite 后端

Graphite 是由多个后端和前端组件组合而成。后端组件被用于存储数值的时间序列数据。前端组件被用于检索度量数据和可选的图像渲染。在这篇博客文章中,我将重点介绍后端组件:Carbon 和 Whisper。

此处输入图片的描述

度量指标可以被发布到一个负载均衡器或者是直接到一个 Carbon 进程。Carbon 进程与 Whisper 数据库包交互来存储时间序列数据到文件系统。

安装 Carbon

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

Whisper 是一个用于存储时间序列数据的数据库包,它被应用通过使用 create, update, 和 fetch 操作来检索以及操作。

为了安装 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 进程

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 

发布度量指标

一个度量值是任何可以随时间变化的可测量的值:

  • 每秒的请求数
  • 进程请求时间
  • CPU 利用率

一个数据点是一个元组包含:

  • 一个度量值的名字
  • 一个可度量的值
  • 在一个指定时间点(通常是一个 timestamp)

客户端应用通过发送数据点到一个 Carbon 进程来发布度量值。这个应用在 Carbon 进程的端口上建立一个 TCP 连接并以一个简单的纯文本格式发送数据点。在我们的例子中,端口是 2003。TCP 连接或许依旧是打开并根据需要重复多次使用。Carbon 进程监听进入的数据但是不给客户端发送任何响应。

数据点格式被定义成:

  • 每个数据点是一个单行文本
  • 在位置 0 是一个带点的度量名称
  • 在位置 1 是一个值
  • 在位置 2 是一个 Unix Epoch 的 timestamp
  • 以空格作为位置的分隔符

比如,这里有一些有效的数据点:

  • carbon.agents.graphite-tutorial.metricsReceived 28198 1400509108
  • carbon.agents.graphite-tutorial.creates 8 1400509110
  • PRODUCTION.host.graphite-tutorial.responseTime.p95 0.10 1400509112

客户端应用有多个方式来发布度量值:

  • 使用一个纯文本协议工具比如 netcat (nc) 命令
  • 使用 pickle 协议
  • 使用高级消息队列协议(AMQP)
  • 使用 lib 包比如 Coda Hale metrics library

为了简单起见,在这个教程中我将通过 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 系列

  1. Provision Hardware
  2. Carbon & Whisper
  3. Whisper Storage Schemas & Aggregations
  4. Graphite Webapp
  5. Stress Testing Carbon Caches
  6. Carbon Aggregators

本文的作者是 franklinangulo,本文的原文是 GRAPHITE SERIES #2: CARBON & WHISPER

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值