forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
check.go
74 lines (60 loc) · 2.05 KB
/
check.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package generic
import (
yaml "gopkg.in/yaml.v2"
"github.com/StackVista/stackstate-agent/pkg/aggregator"
"github.com/StackVista/stackstate-agent/pkg/autodiscovery/integration"
"github.com/StackVista/stackstate-agent/pkg/collector/check"
core "github.com/StackVista/stackstate-agent/pkg/collector/corechecks"
"github.com/StackVista/stackstate-agent/pkg/util/containers"
"github.com/StackVista/stackstate-agent/pkg/util/containers/v2/metrics"
)
const (
genericContainerCheckName = "container"
)
// ContainerConfig holds the check configuration
type ContainerConfig struct{}
// Parse parses the container check config and set default values
func (c *ContainerConfig) Parse(data []byte) error {
return yaml.Unmarshal(data, c)
}
// ContainerCheck generates metrics for all containers
type ContainerCheck struct {
core.CheckBase
instance *ContainerConfig
processor Processor
}
func init() {
core.RegisterCheck("container", ContainerCheckFactory)
}
// ContainerCheckFactory is exported for integration testing
func ContainerCheckFactory() check.Check {
return &ContainerCheck{
CheckBase: core.NewCheckBase(genericContainerCheckName),
instance: &ContainerConfig{},
}
}
// Configure parses the check configuration and init the check
func (c *ContainerCheck) Configure(config, initConfig integration.Data, source string) error {
err := c.CommonConfigure(config, source)
if err != nil {
return err
}
filter, err := containers.GetSharedMetricFilter()
if err != nil {
return err
}
c.processor = NewProcessor(metrics.GetProvider(), MetadataContainerLister{}, GenericMetricsAdapter{}, filter)
return c.instance.Parse(config)
}
// Run executes the check
func (c *ContainerCheck) Run() error {
sender, err := aggregator.GetSender(c.ID())
if err != nil {
return err
}
return c.processor.Run(sender, c.Interval()/2)
}