-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial prototype code #9
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, still early on so I don't have any major feedback
} | ||
|
||
func newClient() *vim25.Client { | ||
u, err := soap.ParseURL(os.Getenv("GOVC_URL")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be eventually settable via the config struct so importers can create multiple exporters for multiple vCenters.
var logger log.Logger | ||
logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) | ||
logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) | ||
logger = level.NewFilter(logger, level.AllowDebug()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Allowing debug logs is the default FWIW)
// create desc | ||
constLabels := make(prometheus.Labels) | ||
constLabels["name"] = name | ||
desc := prometheus.NewDesc( | ||
fqName, fmt.Sprintf("metric: %s units: %s", v.Name, units), | ||
nil, | ||
constLabels) | ||
|
||
// send metric | ||
m, err := prometheus.NewConstMetric(desc, prometheus.UntypedValue, float64(v.Value[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll have to be wary of allocations here, since we're reallocate the desc and metric every scrape atm
// create desc | ||
constLabels := make(prometheus.Labels) | ||
constLabels["name"] = name | ||
desc := prometheus.NewDesc( | ||
fqName, fmt.Sprintf("metric: %s units: %s", v.Name, units), | ||
nil, | ||
constLabels) | ||
|
||
// send metric | ||
m, err := prometheus.NewConstMetric(desc, prometheus.UntypedValue, float64(v.Value[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having these be untyped, we should find a way to convert metric.Entity.Type to a Prometheus type. Grafana looks at the type metadata to infer some user hints like using rate for counters.
vsphere/collector.go
Outdated
level.Error(c.logger).Log("err", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing continue here
vsphere/collector.go
Outdated
// TODO implement Describe | ||
func (c *vsphereCollector) Describe(descs chan<- *prometheus.Desc) { | ||
level.Debug(c.logger).Log("msg", "describe") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(You probably won't be able to implement Describe, IIRC it's called once when a collector is registered and doesn't work if you dynamically create new metrics between scrapes. This is fine though, Describe is just used for checked metrics so make sure you don't register the same metric twice)
This is some sample prototype code created when researching govmomi. The collector here discovers all resources in a cluster using a single call to the
ViewManager
and then requests the metrics for the returned resources from thePerformanceManager
.Please keep in mind, this is just a starting point for developing the exporter and most of this code won't be long lived.