-
Notifications
You must be signed in to change notification settings - Fork 478
/
memcached_exporter.go
66 lines (53 loc) · 1.88 KB
/
memcached_exporter.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
// Package memcached_exporter embeds https://github.com/google/memcached_exporter
package memcached_exporter //nolint:golint
import (
"time"
"github.com/go-kit/kit/log"
"github.com/grafana/agent/pkg/integrations"
"github.com/grafana/agent/pkg/integrations/config"
"github.com/prometheus/memcached_exporter/pkg/exporter"
)
// DefaultConfig is the default config for memcached_exporter.
var DefaultConfig Config = Config{
MemcachedAddress: "localhost:11211",
Timeout: time.Second,
}
// Config controls the memcached_exporter integration.
type Config struct {
Common config.Common `yaml:",inline"`
// MemcachedAddress is the address of the memcached server (host:port).
MemcachedAddress string `yaml:"memcached_address,omitempty"`
// Timeout is the connection timeout for memcached.
Timeout time.Duration `yaml:"timeout,omitempty"`
}
// UnmarshalYAML implements yaml.Unmarshaler for Config.
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultConfig
type plain Config
return unmarshal((*plain)(c))
}
// Name returns the name of the integration that this config represents.
func (c *Config) Name() string {
return "memcached_exporter"
}
// CommonConfig returns the common settings shared across all integratons.
func (c *Config) CommonConfig() config.Common {
return c.Common
}
// NewIntegration converts this config into an instance of an integration.
func (c *Config) NewIntegration(l log.Logger) (integrations.Integration, error) {
return New(l, c)
}
func init() {
integrations.RegisterIntegration(&Config{})
}
// New creates a new memcached_exporter integration. The integration scrapes metrics
// from a memcached server.
func New(log log.Logger, c *Config) (integrations.Integration, error) {
return integrations.NewCollectorIntegration(
c.Name(),
integrations.WithCollectors(
exporter.New(c.MemcachedAddress, c.Timeout, log),
),
), nil
}