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