Path: blob/main/pkg/integrations/v2/blackbox_exporter/blackbox_exporter.go
5414 views
package blackbox_exporter_v212import (3"github.com/go-kit/log"4"github.com/grafana/agent/pkg/integrations/blackbox_exporter"5integrations_v2 "github.com/grafana/agent/pkg/integrations/v2"6"github.com/grafana/agent/pkg/integrations/v2/common"7blackbox_config "github.com/prometheus/blackbox_exporter/config"8)910// DefaultConfig holds the default settings for the blackbox_exporter integration.11var DefaultConfig = Config{12// Default value taken from https://github.com/prometheus/blackbox_exporter/blob/master/main.go#L6113ProbeTimeoutOffset: 0.5,14}1516// Config configures the Blackbox integration.17type Config struct {18BlackboxConfigFile string `yaml:"config_file,omitempty"`19BlackboxTargets []blackbox_exporter.BlackboxTarget `yaml:"blackbox_targets"`20BlackboxConfig blackbox_config.Config `yaml:"blackbox_config,omitempty"`21ProbeTimeoutOffset float64 `yaml:"probe_timeout_offset,omitempty"`2223Common common.MetricsConfig `yaml:",inline"`24globals integrations_v2.Globals25}2627// UnmarshalYAML implements yaml.Unmarshaler for Config.28func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {29*c = DefaultConfig3031type plain Config32return unmarshal((*plain)(c))33}3435// Name returns the name of the integration.36func (c *Config) Name() string {37return "blackbox"38}3940// ApplyDefaults applies the integration's default configuration.41func (c *Config) ApplyDefaults(globals integrations_v2.Globals) error {42c.Common.ApplyDefaults(globals.SubsystemOpts.Metrics.Autoscrape)43return nil44}4546// Identifier returns a string that identifies the integration.47func (c *Config) Identifier(globals integrations_v2.Globals) (string, error) {48if c.Common.InstanceKey != nil {49return *c.Common.InstanceKey, nil50}51return c.Name(), nil52}5354func init() {55integrations_v2.Register(&Config{}, integrations_v2.TypeSingleton)56}5758// NewIntegration creates a new blackbox integration.59func (c *Config) NewIntegration(log log.Logger, globals integrations_v2.Globals) (integrations_v2.Integration, error) {60modules, err := blackbox_exporter.LoadBlackboxConfig(log, c.BlackboxConfigFile, c.BlackboxTargets, &c.BlackboxConfig)61if err != nil {62return nil, err63}6465c.globals = globals66bbh := &blackboxHandler{67cfg: c,68modules: modules,69log: log,70}71return bbh, nil72}737475