Path: blob/main/pkg/integrations/dnsmasq_exporter/dnsmasq_exporter.go
5456 views
// Package dnsmasq_exporter embeds https://github.com/google/dnsmasq_exporter1package dnsmasq_exporter //nolint:golint23import (4"github.com/go-kit/log"5"github.com/google/dnsmasq_exporter/collector"6"github.com/grafana/agent/pkg/integrations"7integrations_v2 "github.com/grafana/agent/pkg/integrations/v2"8"github.com/grafana/agent/pkg/integrations/v2/metricsutils"9"github.com/miekg/dns"10)1112// DefaultConfig is the default config for dnsmasq_exporter.13var DefaultConfig = Config{14DnsmasqAddress: "localhost:53",15LeasesPath: "/var/lib/misc/dnsmasq.leases",16}1718// Config controls the dnsmasq_exporter integration.19type Config struct {20// DnsmasqAddress is the address of the dnsmasq server (host:port).21DnsmasqAddress string `yaml:"dnsmasq_address,omitempty"`2223// Path to the dnsmasq leases file.24LeasesPath string `yaml:"leases_path,omitempty"`25}2627// Name returns the name of the integration that this config is for.28func (c *Config) Name() string {29return "dnsmasq_exporter"30}3132// InstanceKey returns the address of the dnsmasq server.33func (c *Config) InstanceKey(agentKey string) (string, error) {34return c.DnsmasqAddress, nil35}3637// NewIntegration converts this config into an instance of an integration.38func (c *Config) NewIntegration(l log.Logger) (integrations.Integration, error) {39return New(l, c)40}4142// UnmarshalYAML implements yaml.Unmarshaler for Config.43func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {44*c = DefaultConfig4546type plain Config47return unmarshal((*plain)(c))48}4950func init() {51integrations.RegisterIntegration(&Config{})52integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeMultiplex, metricsutils.NewNamedShim("dnsmasq"))53}5455// New creates a new dnsmasq_exporter integration. The integration scrapes metrics56// from a dnsmasq server.57func New(log log.Logger, c *Config) (integrations.Integration, error) {58exporter := collector.New(log, &dns.Client{59SingleInflight: true,60}, c.DnsmasqAddress, c.LeasesPath)6162return integrations.NewCollectorIntegration(c.Name(), integrations.WithCollectors(exporter)), nil63}646566