Skip to content
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

Merged
merged 1 commit into from
Feb 25, 2022
Merged

initial prototype code #9

merged 1 commit into from
Feb 25, 2022

Conversation

rlankfo
Copy link
Member

@rlankfo rlankfo commented Feb 23, 2022

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 the PerformanceManager.

Please keep in mind, this is just a starting point for developing the exporter and most of this code won't be long lived.

Copy link
Member

@rfratto rfratto left a 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"))
Copy link
Member

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())
Copy link
Member

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)

Comment on lines +105 to +109
// 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]))
Copy link
Member

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

Comment on lines +105 to +109
// 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]))
Copy link
Member

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.

Comment on lines 116 to 113
level.Error(c.logger).Log("err", err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing continue here

Comment on lines 25 to 23
// TODO implement Describe
func (c *vsphereCollector) Describe(descs chan<- *prometheus.Desc) {
level.Debug(c.logger).Log("msg", "describe")
}
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants