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