一 使用说明
以下是喂数据的方式,但是在实际使用中我们使用statsd来喂数据,请参考我的第四篇文章:statsd指南
喂数据有三种方式:
There are three main methods for sending data to Graphite: Plaintext, Pickle, and AMQP.
Choosing the right transfer method for you is dependent on how you want to build your application or script to send data:
For a singular script, or for test data, the plaintext protocol is the most straightforward method.For sending large amounts of data, you’ll want to batch this data up and send it to Carbon’s pickle receiver.Finally, Carbon can listen to a message bus, via AMQP.
The plaintext protocol
The plaintext protocol is the most straightforward protocol supported by Carbon.
The data sent must be in the following format:
Carbon will then help translate this line of text into a metric that the web interface and Whisper understand.
On Unix, the nc program can be used to create a socket and send data to Carbon (by default, ‘plaintext’ runs on port 2003):
PORT=2003
SERVER=graphite.your.org
echo "local.random.diceroll 4 `date +%s`" | nc ${SERVER} ${PORT};
The pickle protocol
The pickle protocol is a much more efficient take on the plaintext protocol, and supports sending batches of metrics to Carbon in one go.
The general idea is that the pickled data forms a list of multi-level tuples:
[(path, (timestamp, value)), ...]
Once you’ve formed a list of sufficient size (don’t go too big!), send the data over a socket to Carbon’s pickle receiver (by default, port 2004). You’ll need to pack your pickled data into a packet containing a simple header:
payload = pickle.dumps(listOfMetricTuples)
header = struct.pack("!L", len(payload))
message = header + payload
You would then send the message object through a network socket.
Using AMQP
高级消息队列协议(AMQP)是一个异步消息传递所使用的应用层协议规范。作为线路层协议,而不是API(例如JMS),AMQP 客户端能够无视消息的来源任意发送和接受信息。
这个应该不容易使用
问题:
1 y轴的单位和发送的不匹配
二使用方法
总结来说,偶尔观察的话,直接打开整个graphite(server:8080)看就行;如果是长期使用,用dashboard比较方便。
但是在我电脑上通配符不能使的情况,使用url api的方式可以得到通配符;dashboard的话,这能把所有的拉到一张图上
参考:http://www.jsxubar.info/graphite-dashboard.html
进入虚拟主机的方式是server:8080
变量使用说明:变量名字以树的结构展开,比如carbon.agents.alg-1-a.cpuUsage表示在cpuUsage这个变量在carbon.agents.alg-1-a.这个路径下。
1 dashboard
顾名思义,以面板的方式显示。
这种方式可以选定项目,画出图形,最后保存为一个网页的形式。再查看时可以直接打开网页。
server:8080/dashboard 打开面板
选择数据源的时候可以使用“*”这个通配符,这就相当方便。比如我要比较多个主机的空闲内容,那可以使用*.meminfo.free来进行筛选找到数据源的最底层信息,然后点击,出现加粗,说明数据源已选上,下面就会出现该数据的图形
选择数据,产生图形,保存为一个dashboard,如将CPU的图形信息保存为cpu,关闭这个浏览器窗口,下次查看时就可以使用server:8080/dashboard/#cpu 进行查看。
下次打开面板时,我不记得以前建立的面板,这时可以通过“Finder”,选择面板列表
自己在做的时候,发现通配符不管用,有种反应很慢的感觉。??????????????????
2 cli
命令行操作
参考上面提到的jsxubar博客或者官网http://graphite.wikidot.com/cli-reference
3 Url Api
使用网址的方式直接获取所需的图形。
例如,http://127.0.0.1:8080/render?target=*.test&target=*.bigboy&from=-60min
参考上面提到的jsxubar博客或者官网http://graphite.wikidot.com/url-api-reference
一些小点
设置yStep
Default: Calculated automatically
Manually set the value step between Y-axis labels and grid lines
主要参考:
graphite文档 :https://graphite.readthedocs.org 基本可以查到所有东西
原文地址:https://www.cnblogs.com/catkins/archive/2012/12/27/5270669.html
文章链接
发表评论