-
Notifications
You must be signed in to change notification settings - Fork 12
/
redis.go
59 lines (53 loc) · 1.52 KB
/
redis.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
/*
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
*/
package redis
import (
"encoding/json"
"fmt"
telegraf2 "github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs/redis"
"github.com/traas-stack/holoinsight-agent/pkg/collecttask"
"github.com/traas-stack/holoinsight-agent/pkg/logger"
"github.com/traas-stack/holoinsight-agent/pkg/plugin/api"
"github.com/traas-stack/holoinsight-agent/pkg/plugin/input/standard/providers"
"github.com/traas-stack/holoinsight-agent/pkg/telegraf"
)
type (
Conf struct {
Port int `json:"port,omitempty"`
Password string `json:"password,omitempty"`
}
)
func init() {
providers.RegisterInputProvider("telegraf_redis", func(task *collecttask.CollectTask) (api.Input, error) {
return ParseInputPlugin(task)
})
}
func ParseInputPlugin(task *collecttask.CollectTask) (api.Input, error) {
conf := &Conf{}
if err := json.Unmarshal(task.Config.Content, conf); err != nil {
return nil, err
}
var plugin telegraf2.Input
switch task.Target.Type {
case collecttask.TargetPod:
if conf.Port <= 0 {
conf.Port = 6379
}
server := fmt.Sprintf("tcp://%s:%d", task.Target.GetIP(), conf.Port)
plugin = &redis.Redis{
Servers: []string{server},
Password: conf.Password,
Log: logger.ZapLogger.InfoS,
}
case collecttask.TargetNone:
plugin = &redis.Redis{
Log: logger.ZapLogger.InfoS,
}
if err := json.Unmarshal(task.Config.Content, plugin); err != nil {
return nil, err
}
}
return telegraf.NewInputAdapter(plugin), nil
}