Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/v2/vmware_exporter/vmware_exporter.go
5371 views
1
package vmware_exporter
2
3
import (
4
"fmt"
5
"net/url"
6
"time"
7
8
"github.com/go-kit/log"
9
"github.com/grafana/agent/pkg/integrations/v2"
10
"github.com/grafana/agent/pkg/integrations/v2/common"
11
"github.com/grafana/agent/pkg/integrations/v2/metricsutils"
12
"github.com/grafana/vmware_exporter/vsphere"
13
config_util "github.com/prometheus/common/config"
14
)
15
16
func init() {
17
integrations.Register(&Config{}, integrations.TypeMultiplex)
18
}
19
20
// DefaultConfig holds non-zero default options for hte Config when it is
21
// unmarshaled from YAML.
22
var DefaultConfig = Config{
23
ChunkSize: 256,
24
CollectConcurrency: 8,
25
ObjectDiscoveryInterval: 0,
26
EnableExporterMetrics: true,
27
}
28
29
// Config configures the vmware_exporter integration.
30
type Config struct {
31
ChunkSize int `yaml:"request_chunk_size,omitempty"`
32
CollectConcurrency int `yaml:"collect_concurrency,omitempty"`
33
VSphereURL string `yaml:"vsphere_url,omitempty"`
34
VSphereUser string `yaml:"vsphere_user,omitempty"`
35
VSpherePass config_util.Secret `yaml:"vsphere_password,omitempty"`
36
ObjectDiscoveryInterval time.Duration `yaml:"discovery_interval,omitempty"`
37
EnableExporterMetrics bool `yaml:"enable_exporter_metrics,omitempty"`
38
Common common.MetricsConfig `yaml:",inline"`
39
}
40
41
var _ integrations.Config = (*Config)(nil)
42
43
// UnmarshalYAML implements the Unmarshaler interface.
44
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
45
*c = DefaultConfig
46
type plain Config
47
return unmarshal((*plain)(c))
48
}
49
50
// Name returns the name of this integration.
51
func (c *Config) Name() string {
52
return "vsphere"
53
}
54
55
// ApplyDefaults applies the integration's default configuration.
56
func (c *Config) ApplyDefaults(g integrations.Globals) error {
57
c.Common.ApplyDefaults(g.SubsystemOpts.Metrics.Autoscrape)
58
return nil
59
}
60
61
// Identifier returns a string that identifies the instance of the integration.
62
func (c *Config) Identifier(g integrations.Globals) (string, error) {
63
if c.Common.InstanceKey != nil {
64
return *c.Common.InstanceKey, nil
65
}
66
67
u, err := url.Parse(c.VSphereURL)
68
if err != nil {
69
return "", err
70
}
71
return fmt.Sprintf("%s:%s", u.Hostname(), u.Port()), nil
72
}
73
74
// NewIntegration constructs a new instance of this integration.
75
func (c *Config) NewIntegration(log log.Logger, g integrations.Globals) (integrations.Integration, error) {
76
vsphereURL, err := url.Parse(c.VSphereURL)
77
if err != nil {
78
return nil, err
79
}
80
vsphereURL.User = url.UserPassword(c.VSphereUser, string(c.VSpherePass))
81
82
exporterConfig := vsphere.Config{
83
ChunkSize: c.ChunkSize,
84
CollectConcurrency: c.CollectConcurrency,
85
VSphereURL: vsphereURL,
86
ObjectDiscoveryInterval: c.ObjectDiscoveryInterval,
87
EnableExporterMetrics: c.EnableExporterMetrics,
88
}
89
exporter, err := vsphere.NewExporter(log, &exporterConfig)
90
if err != nil {
91
return nil, err
92
}
93
94
return metricsutils.NewMetricsHandlerIntegration(
95
log, c, c.Common, g, exporter,
96
)
97
}
98
99