Path: blob/main/component/prometheus/exporter/redis/redis.go
4095 views
package redis12import (3"fmt"4"strings"5"time"67"github.com/grafana/agent/component"8"github.com/grafana/agent/component/prometheus/exporter"9"github.com/grafana/agent/pkg/integrations"10"github.com/grafana/agent/pkg/integrations/redis_exporter"11"github.com/grafana/agent/pkg/river/rivertypes"12config_util "github.com/prometheus/common/config"13)1415func init() {16component.Register(component.Registration{17Name: "prometheus.exporter.redis",18Args: Arguments{},19Exports: exporter.Exports{},20Build: exporter.New(createExporter, "redis"),21})22}2324func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, error) {25a := args.(Arguments)26return a.Convert().NewIntegration(opts.Logger)27}2829// DefaultArguments holds non-zero default options for Arguments when it is30// unmarshaled from river.31var DefaultArguments = Arguments{32IncludeExporterMetrics: false,33Namespace: "redis",34ConfigCommand: "CONFIG",35ConnectionTimeout: 15 * time.Second,36SetClientName: true,37CheckKeyGroupsBatchSize: 10000,38MaxDistinctKeyGroups: 100,39}4041type Arguments struct {42IncludeExporterMetrics bool `river:"include_exporter_metrics,attr,optional"`4344// exporter-specific config.45//46// The exporter binary config differs to this, but these47// are the only fields that are relevant to the exporter struct.48RedisAddr string `river:"redis_addr,attr"`49RedisUser string `river:"redis_user,attr,optional"`50RedisPassword rivertypes.Secret `river:"redis_password,attr,optional"`51RedisPasswordFile string `river:"redis_password_file,attr,optional"`52RedisPasswordMapFile string `river:"redis_password_map_file,attr,optional"`53Namespace string `river:"namespace,attr,optional"`54ConfigCommand string `river:"config_command,attr,optional"`55CheckKeys []string `river:"check_keys,attr,optional"`56CheckKeyGroups []string `river:"check_key_groups,attr,optional"`57CheckKeyGroupsBatchSize int64 `river:"check_key_groups_batch_size,attr,optional"`58MaxDistinctKeyGroups int64 `river:"max_distinct_key_groups,attr,optional"`59CheckSingleKeys []string `river:"check_single_keys,attr,optional"`60CheckStreams []string `river:"check_streams,attr,optional"`61CheckSingleStreams []string `river:"check_single_streams,attr,optional"`62CountKeys []string `river:"count_keys,attr,optional"`63ScriptPath string `river:"script_path,attr,optional"`64ScriptPaths []string `river:"script_paths,attr,optional"`65ConnectionTimeout time.Duration `river:"connection_timeout,attr,optional"`66TLSClientKeyFile string `river:"tls_client_key_file,attr,optional"`67TLSClientCertFile string `river:"tls_client_cert_file,attr,optional"`68TLSCaCertFile string `river:"tls_ca_cert_file,attr,optional"`69SetClientName bool `river:"set_client_name,attr,optional"`70IsTile38 bool `river:"is_tile38,attr,optional"`71IsCluster bool `river:"is_cluster,attr,optional"`72ExportClientList bool `river:"export_client_list,attr,optional"`73ExportClientPort bool `river:"export_client_port,attr,optional"`74RedisMetricsOnly bool `river:"redis_metrics_only,attr,optional"`75PingOnConnect bool `river:"ping_on_connect,attr,optional"`76InclSystemMetrics bool `river:"incl_system_metrics,attr,optional"`77SkipTLSVerification bool `river:"skip_tls_verification,attr,optional"`78}7980// UnmarshalRiver implements River unmarshalling for Config.81func (a *Arguments) UnmarshalRiver(f func(interface{}) error) error {82*a = DefaultArguments8384type args Arguments85if err := f((*args)(a)); err != nil {86return err87}88return a.Validate()89}9091func (a *Arguments) Validate() error {92if a.ScriptPath != "" && len(a.ScriptPaths) > 0 {93return fmt.Errorf("only one of script_path and script_paths should be specified")94}95return nil96}9798func (a *Arguments) Convert() *redis_exporter.Config {99var scriptPath string100if a.ScriptPath != "" {101scriptPath = a.ScriptPath102} else if len(a.ScriptPaths) > 0 {103scriptPath = strings.Join(a.ScriptPaths, ",")104}105106return &redis_exporter.Config{107IncludeExporterMetrics: a.IncludeExporterMetrics,108RedisAddr: a.RedisAddr,109RedisUser: a.RedisUser,110RedisPassword: config_util.Secret(a.RedisPassword),111RedisPasswordFile: a.RedisPasswordFile,112RedisPasswordMapFile: a.RedisPasswordMapFile,113Namespace: a.Namespace,114ConfigCommand: a.ConfigCommand,115CheckKeys: strings.Join(a.CheckKeys, ","),116CheckKeyGroups: strings.Join(a.CheckKeyGroups, ","),117CheckKeyGroupsBatchSize: a.CheckKeyGroupsBatchSize,118MaxDistinctKeyGroups: a.MaxDistinctKeyGroups,119CheckSingleKeys: strings.Join(a.CheckSingleKeys, ","),120CheckStreams: strings.Join(a.CheckStreams, ","),121CheckSingleStreams: strings.Join(a.CheckSingleStreams, ","),122CountKeys: strings.Join(a.CountKeys, ","),123ScriptPath: scriptPath,124ConnectionTimeout: a.ConnectionTimeout,125TLSClientKeyFile: a.TLSClientKeyFile,126TLSClientCertFile: a.TLSClientCertFile,127TLSCaCertFile: a.TLSCaCertFile,128SetClientName: a.SetClientName,129IsTile38: a.IsTile38,130IsCluster: a.IsCluster,131ExportClientList: a.ExportClientList,132ExportClientPort: a.ExportClientPort,133RedisMetricsOnly: a.RedisMetricsOnly,134PingOnConnect: a.PingOnConnect,135InclSystemMetrics: a.InclSystemMetrics,136SkipTLSVerification: a.SkipTLSVerification,137}138}139140141