资讯专栏INFORMATION COLUMN

Graphite 系列 #2:Carbon 和 Whisper

MASAILA / 698人阅读

摘要:为了发布以上列出的示例数据点,运行以下命令日志文件将包含关于新的被接收到的度量值的信息,信息被存储在与交互来存储时间序列数据到文件系统。

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


  

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

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


Graphite 后端

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

  

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

安装 Carbon

Carbon 是一个 daemon,其使用一个名为 Twisted 的事件驱动网络引擎来监听时间序列数据。Twisted 框架支持 Carbon 进程以较低的开销处理大量的客户端和处理大量的流量。

Carbon Github 项目:点击这里

为了安装 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 Github 项目:点击这里

为了安装 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 系列

Provision Hardware

Carbon & Whisper

Whisper Storage Schemas & Aggregations

Graphite Webapp

Stress Testing Carbon Caches

Carbon Aggregators

  

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

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/37505.html

相关文章

  • 在 CentOS 5.8 上安装 Graphite

    摘要:在上安装标签空格分隔监控首先说一句,在上安装真的很坑爹。。。或如果上面这个方法无法安装那就用源码安装的方法。安装开始好几次就死在安装这个上面,版本的通过命令安装的不行,对应版本的包的名字叫做。 在 CentOS 5.8 上安装 Graphite 标签(空格分隔): 监控 monitor CentOS 5.8 Graphite 首先说一句,在 CentOS 5.8 上安装真的很坑爹...

    banana_pi 评论0 收藏0
  • 如何深入理解 StatsD 与 Graphite

    摘要:众所周知,负责收集并聚合测量值。每个都有一个,该值的解释方式依赖于。计时器的一大好处在于,你可以得到平均值总值计数值和上下限值。给传一个数字,它会不经处理地将该数字传到后端。由三部分组成监听时间序列的数据的后台程序。 众所周知,StatsD 负责收集并聚合测量值。之后,它会将数据传给 Graphite,后者以时间序列为依据存储数据,并绘制图表。但是,我们不知道,基于 http 访问的图...

    dreamans 评论0 收藏0
  • [afterCode] docker 速成班 7: 实战 构建基于graphtie/grafana监

    摘要:由于公司没有运维又需要监控服务器的一些数据信息想尽快的启动一个数值监控系统技术评估了下打算的方式来建设是一个时间数列数据库并且自带一些简单图形展示功能虽然展示方面不是很完美但是在收集时间数据上非常的方便和简单根据官网的例子只需要一个连接就能 由于公司没有运维, 又需要监控服务器的一些数据信息, 想尽快的启动一个数值监控系统. 技术评估了下打算 graphite + grafana 的...

    jhhfft 评论0 收藏0
  • FastD 最佳实践四: 构建系统可视化监控

    摘要:的展示非常炫酷,绝对是运维提升逼格的一大利器。另外的可视化功能比强得多,而且以上版本将集成报警功能。它由写成,着力于高性能地查询与存储时序型数据。被广泛应用于存储系统的监控数据,行业的实时数据等场景。 原有监控系统 showImg(https://segmentfault.com/img/remote/1460000011082384); 整个系统以 Graphite (carbon ...

    khlbat 评论0 收藏0
  • 宜信开源|一个实例解析PaaS平台LAIN的9大杀手级功能

    摘要:正式上线已经大约两年,基本已经成熟,为宜信大数据创新中心各个团队提供了统一的测试和生产环境,简化了服务的部署与上线流程,也降低了运维人员对系统管理的复杂度。地址白皮书原文发布于高可用架构作者宜信大数据创新中心团队王超一 一、基于Docker的PaaS平台LAIN 在金融的场景下,LAIN 是为解放各个团队和业务线的生产力而设计的一个云平台。LAIN 正式上线已经大约两年,基本已经成熟,...

    Apollo 评论0 收藏0

发表评论

0条评论

MASAILA

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<