1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
| import boto3
import json
cloudwatch = boto3.client('cloudwatch')
def create_dashboard(project_name, queue_name, function_name):
"""
建立 CloudWatch 監控儀表板
"""
dashboard_body = {
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 12,
"height": 6,
"properties": {
"title": "SQS Queue Metrics",
"metrics": [
["AWS/SQS", "ApproximateNumberOfMessagesVisible",
"QueueName", queue_name],
[".", "ApproximateNumberOfMessagesNotVisible", ".", "."],
[".", "NumberOfMessagesSent", ".", "."],
[".", "NumberOfMessagesReceived", ".", "."]
],
"period": 60,
"stat": "Sum",
"region": "ap-northeast-1"
}
},
{
"type": "metric",
"x": 12,
"y": 0,
"width": 12,
"height": 6,
"properties": {
"title": "Lambda Invocations & Errors",
"metrics": [
["AWS/Lambda", "Invocations",
"FunctionName", function_name],
[".", "Errors", ".", "."],
[".", "Throttles", ".", "."]
],
"period": 60,
"stat": "Sum",
"region": "ap-northeast-1"
}
},
{
"type": "metric",
"x": 0,
"y": 6,
"width": 12,
"height": 6,
"properties": {
"title": "Lambda Duration",
"metrics": [
["AWS/Lambda", "Duration",
"FunctionName", function_name,
{"stat": "Average"}],
["...", {"stat": "p99"}],
["...", {"stat": "Maximum"}]
],
"period": 60,
"region": "ap-northeast-1"
}
},
{
"type": "metric",
"x": 12,
"y": 6,
"width": 12,
"height": 6,
"properties": {
"title": "Lambda Concurrent Executions",
"metrics": [
["AWS/Lambda", "ConcurrentExecutions",
"FunctionName", function_name]
],
"period": 60,
"stat": "Maximum",
"region": "ap-northeast-1"
}
}
]
}
cloudwatch.put_dashboard(
DashboardName=f"{project_name}-monitoring",
DashboardBody=json.dumps(dashboard_body)
)
|