forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
75 lines (67 loc) · 1.58 KB
/
types.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
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
package ecs
import (
"encoding/json"
"io"
"strings"
"time"
"github.com/docker/docker/api/types"
)
// Task is the ECS task representation
type Task struct {
Cluster string
TaskARN string
Family string
Revision string
DesiredStatus string
KnownStatus string
Containers []Container
Limits map[string]float64
PullStartedAt time.Time
PullStoppedAt time.Time
}
// Container is the ECS metadata container representation
type Container struct {
ID string `json:"DockerId"`
Name string
DockerName string
Image string
ImageID string
Labels map[string]string
DesiredStatus string
KnownStatus string
Limits map[string]float64
CreatedAt time.Time
StartedAt time.Time
Stats types.StatsJSON
Type string
Networks []Network
}
// Network is a docker network configuration
type Network struct {
NetworkMode string
IPv4Addresses []string
}
func unmarshalTask(r io.Reader) (*Task, error) {
task := &Task{}
err := json.NewDecoder(r).Decode(task)
return task, err
}
// docker parsers
func unmarshalStats(r io.Reader) (map[string]types.StatsJSON, error) {
var statsMap map[string]types.StatsJSON
err := json.NewDecoder(r).Decode(&statsMap)
return statsMap, err
}
// interleaves Stats in to the Container objects in the Task
func mergeTaskStats(task *Task, stats map[string]types.StatsJSON) {
for i, c := range task.Containers {
if strings.Trim(c.ID, " ") == "" {
continue
}
stat, ok := stats[c.ID]
if !ok {
continue
}
task.Containers[i].Stats = stat
}
}