Skip to content

Instantly share code, notes, and snippets.

@sky-joker
Created April 23, 2017 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sky-joker/a6d8b67451345d2c86c9b406f527d2f4 to your computer and use it in GitHub Desktop.
Save sky-joker/a6d8b67451345d2c86c9b406f527d2f4 to your computer and use it in GitHub Desktop.
Mackerelへカスタムメトリックを投稿するスクロプト例
#!/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