Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/v2/blackbox_exporter/blackbox_exporter.go
5414 views
1
package blackbox_exporter_v2
2
3
import (
4
"github.com/go-kit/log"
5
"github.com/grafana/agent/pkg/integrations/blackbox_exporter"
6
integrations_v2 "github.com/grafana/agent/pkg/integrations/v2"
7
"github.com/grafana/agent/pkg/integrations/v2/common"
8
blackbox_config "github.com/prometheus/blackbox_exporter/config"
9
)
10
11
// DefaultConfig holds the default settings for the blackbox_exporter integration.
12
var DefaultConfig = Config{
13
// Default value taken from https://github.com/prometheus/blackbox_exporter/blob/master/main.go#L61
14
ProbeTimeoutOffset: 0.5,
15
}
16
17
// Config configures the Blackbox integration.
18
type Config struct {
19
BlackboxConfigFile string `yaml:"config_file,omitempty"`
20
BlackboxTargets []blackbox_exporter.BlackboxTarget `yaml:"blackbox_targets"`
21
BlackboxConfig blackbox_config.Config `yaml:"blackbox_config,omitempty"`
22
ProbeTimeoutOffset float64 `yaml:"probe_timeout_offset,omitempty"`
23
24
Common common.MetricsConfig `yaml:",inline"`
25
globals integrations_v2.Globals
26
}
27
28
// UnmarshalYAML implements yaml.Unmarshaler for Config.
29
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
30
*c = DefaultConfig
31
32
type plain Config
33
return unmarshal((*plain)(c))
34
}
35
36
// Name returns the name of the integration.
37
func (c *Config) Name() string {
38
return "blackbox"
39
}
40
41
// ApplyDefaults applies the integration's default configuration.
42
func (c *Config) ApplyDefaults(globals integrations_v2.Globals) error {
43
c.Common.ApplyDefaults(globals.SubsystemOpts.Metrics.Autoscrape)
44
return nil
45
}
46
47
// Identifier returns a string that identifies the integration.
48
func (c *Config) Identifier(globals integrations_v2.Globals) (string, error) {
49
if c.Common.InstanceKey != nil {
50
return *c.Common.InstanceKey, nil
51
}
52
return c.Name(), nil
53
}
54
55
func init() {
56
integrations_v2.Register(&Config{}, integrations_v2.TypeSingleton)
57
}
58
59
// NewIntegration creates a new blackbox integration.
60
func (c *Config) NewIntegration(log log.Logger, globals integrations_v2.Globals) (integrations_v2.Integration, error) {
61
modules, err := blackbox_exporter.LoadBlackboxConfig(log, c.BlackboxConfigFile, c.BlackboxTargets, &c.BlackboxConfig)
62
if err != nil {
63
return nil, err
64
}
65
66
c.globals = globals
67
bbh := &blackboxHandler{
68
cfg: c,
69
modules: modules,
70
log: log,
71
}
72
return bbh, nil
73
}
74
75