-
Notifications
You must be signed in to change notification settings - Fork 183
/
mongodb.go
91 lines (77 loc) · 2.92 KB
/
mongodb.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package mongodb
import (
"errors"
"github.com/signalfx/signalfx-agent/internal/monitors/collectd"
"github.com/signalfx/signalfx-agent/internal/core/config"
"github.com/signalfx/signalfx-agent/internal/monitors/collectd/python"
"github.com/signalfx/signalfx-agent/internal/monitors/pyrunner"
"github.com/signalfx/signalfx-agent/internal/monitors"
)
const monitorType = "collectd/mongodb"
// MONITOR(collectd/mongodb): Monitors an instance of MongoDB using the
// [collectd MongoDB Python plugin](https://github.com/signalfx/collectd-mongodb).
//
// Also see https://github.com/signalfx/integrations/tree/master/collectd-mongodb.
func init() {
monitors.Register(monitorType, func() interface{} {
return &Monitor{
python.PyMonitor{
MonitorCore: pyrunner.New("sfxcollectd"),
},
}
}, &Config{})
}
// Config is the monitor-specific config with the generic config embedded
type Config struct {
config.MonitorConfig `yaml:",inline" acceptsEndpoints:"true"`
pyConf *python.Config
Host string `yaml:"host" validate:"required"`
Port uint16 `yaml:"port" validate:"required"`
Databases []string `yaml:"databases" validate:"required"`
Username string `yaml:"username"`
Password string `yaml:"password" neverLog:"true"`
UseTLS *bool `yaml:"useTLS"`
CACerts string `yaml:"caCerts"`
TLSClientCert string `yaml:"tlsClientCert"`
TLSClientKey string `yaml:"tlsClientKey"`
TLSClientKeyPassPhrase string `yaml:"tlsClientKeyPassPhrase"`
}
// PythonConfig returns the embedded python.Config struct from the interface
func (c *Config) PythonConfig() *python.Config {
return c.pyConf
}
// Validate will check the config for correctness.
func (c *Config) Validate() error {
if len(c.Databases) == 0 {
return errors.New("You must specify at least one database for MongoDB")
}
return nil
}
// Monitor is the main type that represents the monitor
type Monitor struct {
python.PyMonitor
}
// Configure configures and runs the plugin in collectd
func (m *Monitor) Configure(conf *Config) error {
conf.pyConf = &python.Config{
MonitorConfig: conf.MonitorConfig,
Host: conf.Host,
Port: conf.Port,
ModuleName: "mongodb",
ModulePaths: []string{collectd.MakePath("mongodb")},
TypesDBPaths: []string{collectd.MakePath("types.db")},
PluginConfig: map[string]interface{}{
"Host": conf.Host,
"Port": conf.Port,
"Database": conf.Databases,
"UseTLS": conf.UseTLS,
"User": conf.Username,
"Password": conf.Password,
"CACerts": conf.CACerts,
"TLSClientCert": conf.TLSClientCert,
"TLSClientKey": conf.TLSClientKey,
"TLSClientKeyPassphrase": conf.TLSClientKeyPassPhrase,
},
}
return m.PyMonitor.Configure(conf)
}