使用graphite/Grafana记录mongodb实例中所有集合的大小。我写了一个简单的(WIP)python脚本来做到这一点:石墨衍生物不显示数据
#!/usr/bin/python
from pymongo import MongoClient
import socket
import time
statsd_ip = '127.0.0.1'
statsd_port = 8125
# create a udp socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client = MongoClient(host='12.34.56.78', port=12345)
db = client.my_DB
# get collection list each runtime
collections = db.collection_names()
sizes = {}
# main
while (1):
# get collection size per name
for collection in collections:
sizes[collection] = db.command('collstats', collection)['size']
# write to statsd
for size in sizes:
MESSAGE = "collection_%s:%d|c" % (size, sizes[size])
sock.sendto(MESSAGE, (statsd_ip, statsd_port))
time.sleep(60)
这正确显示了我在grafana中的所有收藏大小。不过,我想改变这些尺寸的速度,所以我建立以下的石墨查询在grafana:
derivative(statsd.myHost.collection_myCollection)
和图形显示了完全空白。有任何想法吗?
后续操作:当选择大于24h的时间范围时,所有数据同样从图中消失。不能为我的生活找出那一个。
我需要查看显示它的数据或图形,以更好地理解为什么'derivative()'函数可能会失败。另外,请发布你的'storage-schemas.conf'。 – obfuscurity
下面是一些数据截图:[imgur专辑](http://imgur.com/a/NRWJr)。 无论出于何种原因,图像的顺序都搞砸了,但信息就在那里。 –
更新:我认为这个问题起源于石墨。使用石墨网格界面进行图形绘制可得到与Grafana中相同的结果 - 衍生图形显示空白图形,并且包括大于过去24小时的范围显示空图形。我在irc.freenode.net上咨询过#graphite,他们似乎认为这可能是一个聚合问题。我的storage-aggregation.conf是一个空文件。 –