Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/dnsmasq_exporter/dnsmasq_exporter.go
5456 views
1
// Package dnsmasq_exporter embeds https://github.com/google/dnsmasq_exporter
2
package dnsmasq_exporter //nolint:golint
3
4
import (
5
"github.com/go-kit/log"
6
"github.com/google/dnsmasq_exporter/collector"
7
"github.com/grafana/agent/pkg/integrations"
8
integrations_v2 "github.com/grafana/agent/pkg/integrations/v2"
9
"github.com/grafana/agent/pkg/integrations/v2/metricsutils"
10
"github.com/miekg/dns"
11
)
12
13
// DefaultConfig is the default config for dnsmasq_exporter.
14
var DefaultConfig = Config{
15
DnsmasqAddress: "localhost:53",
16
LeasesPath: "/var/lib/misc/dnsmasq.leases",
17
}
18
19
// Config controls the dnsmasq_exporter integration.
20
type Config struct {
21
// DnsmasqAddress is the address of the dnsmasq server (host:port).
22
DnsmasqAddress string `yaml:"dnsmasq_address,omitempty"`
23
24
// Path to the dnsmasq leases file.
25
LeasesPath string `yaml:"leases_path,omitempty"`
26
}
27
28
// Name returns the name of the integration that this config is for.
29
func (c *Config) Name() string {
30
return "dnsmasq_exporter"
31
}
32
33
// InstanceKey returns the address of the dnsmasq server.
34
func (c *Config) InstanceKey(agentKey string) (string, error) {
35
return c.DnsmasqAddress, nil
36
}
37
38
// NewIntegration converts this config into an instance of an integration.
39
func (c *Config) NewIntegration(l log.Logger) (integrations.Integration, error) {
40
return New(l, c)
41
}
42
43
// UnmarshalYAML implements yaml.Unmarshaler for Config.
44
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
45
*c = DefaultConfig
46
47
type plain Config
48
return unmarshal((*plain)(c))
49
}
50
51
func init() {
52
integrations.RegisterIntegration(&Config{})
53
integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeMultiplex, metricsutils.NewNamedShim("dnsmasq"))
54
}
55
56
// New creates a new dnsmasq_exporter integration. The integration scrapes metrics
57
// from a dnsmasq server.
58
func New(log log.Logger, c *Config) (integrations.Integration, error) {
59
exporter := collector.New(log, &dns.Client{
60
SingleInflight: true,
61
}, c.DnsmasqAddress, c.LeasesPath)
62
63
return integrations.NewCollectorIntegration(c.Name(), integrations.WithCollectors(exporter)), nil
64
}
65
66