Path: blob/main/pkg/integrations/memcached_exporter/memcached_exporter.go
5393 views
// Package memcached_exporter embeds https://github.com/google/memcached_exporter1package memcached_exporter //nolint:golint23import (4"time"56"github.com/go-kit/log"7"github.com/grafana/agent/pkg/integrations"8integrations_v2 "github.com/grafana/agent/pkg/integrations/v2"9"github.com/grafana/agent/pkg/integrations/v2/metricsutils"10"github.com/prometheus/memcached_exporter/pkg/exporter"11)1213// DefaultConfig is the default config for memcached_exporter.14var DefaultConfig = Config{15MemcachedAddress: "localhost:11211",16Timeout: time.Second,17}1819// Config controls the memcached_exporter integration.20type Config struct {21// MemcachedAddress is the address of the memcached server (host:port).22MemcachedAddress string `yaml:"memcached_address,omitempty"`2324// Timeout is the connection timeout for memcached.25Timeout time.Duration `yaml:"timeout,omitempty"`26}2728// UnmarshalYAML implements yaml.Unmarshaler for Config.29func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {30*c = DefaultConfig3132type plain Config33return unmarshal((*plain)(c))34}3536// Name returns the name of the integration that this config represents.37func (c *Config) Name() string {38return "memcached_exporter"39}4041// InstanceKey returns the address:port of the memcached server.42func (c *Config) InstanceKey(agentKey string) (string, error) {43return c.MemcachedAddress, nil44}4546// NewIntegration converts this config into an instance of an integration.47func (c *Config) NewIntegration(l log.Logger) (integrations.Integration, error) {48return New(l, c)49}5051func init() {52integrations.RegisterIntegration(&Config{})53integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeMultiplex, metricsutils.NewNamedShim("memcached"))54}5556// New creates a new memcached_exporter integration. The integration scrapes metrics57// from a memcached server.58func New(log log.Logger, c *Config) (integrations.Integration, error) {59return integrations.NewCollectorIntegration(60c.Name(),61integrations.WithCollectors(62exporter.New(c.MemcachedAddress, c.Timeout, log),63),64), nil65}666768