Serverless では Lambda 関数が多く、ブラウザで Screenboard を作成するのは辛いと思うのでスクリプトを書いてみました。 Widget は 全て Graph で作成しています。
import boto3
from datadog import initialize, api
options = {
'api_key': 'xxxxxxxxxxxxxxxxxxxxxx',
'app_key': 'xxxxxxxxxxxxxxxxxxxxxx'
}
widget_width = 37
widget_height = 13
widget_mergin = 1
lambda_metrics_group = {
'duration': [
'aws.lambda.duration',
'aws.lambda.duration.maximum',
'aws.lambda.duration.minimum',
'aws.lambda.duration.sum'
],
'errors': [
'aws.lambda.errors'
],
'invocation': [
'aws.lambda.invocation'
],
'throttles': [
'aws.lambda.throttles'
]
}
def get_functions():
list = []
client = boto3.client('lambda')
lambda_functions = client.list_functions()
for function in lambda_functions['Functions']:
list.append(function['FunctionName'])
return list
def gen_widget(group, metrics, query, x, y):
template = {
'title_size': 16,
'title': True,
'title_align': 'left',
'title_text': '[' + group + ']' + query,
'height': widget_height,
'tile_def': {
'viz': 'timeseries',
'requests': [],
'autoscale': True
},
'width': widget_width,
'timeframe': '1h',
'y': y,
'x': x,
'legend_size': '0',
'type': 'timeseries',
'legend': False,
'isShared': False
}
for m in metrics:
req = {
'q': 'avg:' + m + '{' + query + '}',
'style': {
'width': 'normal',
'palette': 'dog_classic',
'type': 'solid'
},
'type': 'line'
}
template['tile_def']['requests'].append(req)
return template
x = widget_mergin
y = widget_mergin
widgets = []
for function in get_functions():
query = 'functionname:' + function
for group in lambda_metrics_group:
widgets.append(gen_widget(group, lambda_metrics_group[group], query, x, y))
x = x + widget_width + widget_mergin
x = widget_mergin
y = y + widget_height + widget_mergin + 2
initialize(**options)
api.Screenboard.create(board_title = 'Lambda Screen Board ',
description = 'An informative screenboard.',
widgets = widgets)
高橋克幸
新卒3年目で脱新人を目指してます。
フロントに興味を持ち始めた今日このごろ。
趣味は 麻雀 プログラミング 音楽。
運動不足を感じているため、ダンスを始めようかと思っています。