-
Notifications
You must be signed in to change notification settings - Fork 486
/
vmware_exporter.go
97 lines (83 loc) · 3.03 KB
/
vmware_exporter.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
92
93
94
95
96
97
package vmware_exporter_v2
import (
"fmt"
"net/url"
"time"
"github.com/go-kit/log"
"github.com/grafana/agent/pkg/integrations/v2"
"github.com/grafana/agent/pkg/integrations/v2/common"
"github.com/grafana/agent/pkg/integrations/v2/metricsutils"
"github.com/grafana/vmware_exporter/vsphere"
config_util "github.com/prometheus/common/config"
)
func init() {
integrations.Register(&Config{}, integrations.TypeMultiplex)
}
// DefaultConfig holds non-zero default options for hte Config when it is
// unmarshaled from YAML.
var DefaultConfig = Config{
ChunkSize: 256,
CollectConcurrency: 8,
ObjectDiscoveryInterval: 0,
EnableExporterMetrics: true,
}
// Config configures the vmware_exporter integration.
type Config struct {
ChunkSize int `yaml:"request_chunk_size,omitempty"`
CollectConcurrency int `yaml:"collect_concurrency,omitempty"`
VSphereURL string `yaml:"vsphere_url,omitempty"`
VSphereUser string `yaml:"vsphere_user,omitempty"`
VSpherePass config_util.Secret `yaml:"vsphere_password,omitempty"`
ObjectDiscoveryInterval time.Duration `yaml:"discovery_interval,omitempty"`
EnableExporterMetrics bool `yaml:"enable_exporter_metrics,omitempty"`
Common common.MetricsConfig `yaml:",inline"`
}
var _ integrations.Config = (*Config)(nil)
// UnmarshalYAML implements the Unmarshaler interface.
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultConfig
type plain Config
return unmarshal((*plain)(c))
}
// Name returns the name of this integration.
func (c *Config) Name() string {
return "vsphere"
}
// ApplyDefaults applies the integration's default configuration.
func (c *Config) ApplyDefaults(g integrations.Globals) error {
c.Common.ApplyDefaults(g.SubsystemOpts.Metrics.Autoscrape)
return nil
}
// Identifier returns a string that identifies the instance of the integration.
func (c *Config) Identifier(g integrations.Globals) (string, error) {
if c.Common.InstanceKey != nil {
return *c.Common.InstanceKey, nil
}
u, err := url.Parse(c.VSphereURL)
if err != nil {
return "", err
}
return fmt.Sprintf("%s:%s", u.Hostname(), u.Port()), nil
}
// NewIntegration constructs a new instance of this integration.
func (c *Config) NewIntegration(log log.Logger, g integrations.Globals) (integrations.Integration, error) {
vsphereURL, err := url.Parse(c.VSphereURL)
if err != nil {
return nil, err
}
vsphereURL.User = url.UserPassword(c.VSphereUser, string(c.VSpherePass))
exporterConfig := vsphere.Config{
ChunkSize: c.ChunkSize,
CollectConcurrency: c.CollectConcurrency,
VSphereURL: vsphereURL,
ObjectDiscoveryInterval: c.ObjectDiscoveryInterval,
EnableExporterMetrics: c.EnableExporterMetrics,
}
exporter, err := vsphere.NewExporter(log, &exporterConfig)
if err != nil {
return nil, err
}
return metricsutils.NewMetricsHandlerIntegration(
log, c, c.Common, g, exporter,
)
}