Mackerelへカスタムメトリックを投稿するスクロプト例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import json | |
import os | |
import time | |
import sys | |
from random import randint | |
from collections import defaultdict | |
def multi_dimension_dict(dimension, callable_obj=int): | |
""" | |
pythonで多次元配列を使う関数 | |
参照元: http://materia.jp/blog/20121119.html | |
""" | |
nodes = defaultdict(callable_obj) | |
for i in range(dimension-1): | |
p = nodes.copy() | |
nodes = defaultdict(lambda : defaultdict(p.default_factory)) | |
return nodes | |
if(os.environ.get('MACKEREL_AGENT_PLUGIN_META') == '1'): | |
meta = multi_dimension_dict(2) | |
metrics = [{'name':'d6','label':'Die(d6)'},{'name':'d20','label':'Die(20)'}] | |
meta['graphs']['super.dice'] = {'label': 'My Dice', 'unit': 'integer', 'metrics': metrics} | |
print(json.dumps(meta)) | |
sys.exit(0) | |
print('\t'.join(['super.dice.d6', str(randint(1,6)), str(time.time())])) | |
print('\t'.join(['super.dice.d20', str(randint(1,20)), str(time.time())])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment