forked from imjerrybao/apex
/
metrics.go
46 lines (37 loc) · 938 Bytes
/
metrics.go
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
// Package metrics fetches CloudWatch metrics for a function.
package metrics
import (
"time"
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
)
// Config is used to configure Metrics.
type Config struct {
MetricNames []string
Service cloudwatchiface.CloudWatchAPI
StartDate time.Time
EndDate time.Time
}
// AggregatedMetrics represents aggregated metrics.
type AggregatedMetrics struct {
Duration int
Errors int
Invocations int
Throttles int
}
// Metrics collects CloudWatch metrics for multiple functions
type Metrics struct {
Config
FunctionNames []string
}
// Collect and aggregate metrics for multiple functions.
func (m *Metrics) Collect() (a map[string]AggregatedMetrics) {
a = make(map[string]AggregatedMetrics)
for _, fnName := range m.FunctionNames {
metric := Metric{
Config: m.Config,
FunctionName: fnName,
}
a[fnName] = metric.Collect()
}
return
}