/
aws_elb_latency
executable file
·57 lines (48 loc) · 1.5 KB
/
aws_elb_latency
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
#!/usr/bin/env python
import datetime
import os
import sys
import boto
from boto.ec2.cloudwatch import CloudWatchConnection
from munin import MuninPlugin
class AWSCloudWatchELBLatencyPlugin(MuninPlugin):
category = "AWS"
args = "-l 0 --base 1000"
vlabel = "Seconds"
info = "Show latency for requests"
@property
def title(self):
return "Seconds of latency for ELBs"
@property
def fields(self):
return [
("maximum", dict(
label = "Maximum latency",
type = "GAUGE",
)),
("minimum", dict(
label = "Minimum latency",
type = "GAUGE",
)),
("average", dict(
label = "Average latency",
type = "GAUGE",
)),
]
def __init__(self):
self.api_key = os.environ['AWS_KEY']
self.secret_key = os.environ['AWS_SECRET']
def execute(self):
minutes = 5
end_date = datetime.datetime.utcnow()
start_date = end_date - datetime.timedelta(minutes=minutes)
cw = CloudWatchConnection(self.api_key, self.secret_key)
metrics = cw.get_metric_statistics(5*60, start_date, end_date, "Latency", "AWS/ELB", ["Average", "Minimum", "Maximum"])
m = metrics[0]
return dict(
maximum = m['Maximum'],
minimum = m['Minimum'],
average = m['Average'],
)
if __name__ == "__main__":
AWSCloudWatchELBLatencyPlugin().run()