You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to get datastore name for host datastore performance metrics #3847
When I query the datastore.read.average or datastore.read.average, I get an EntityMetric where the Instance of the MetricSeries is some kind of uuid. For me it is unclear where the uuid maps to. I guess it maps to the datastore but I don't know how. Is there a way I can map the metrics back to the datastore name?
This is the code that I'm using. Note that this doesn't work on the vcsim. Only on a real vcenter. The vcsim doesn't return the same metrics like a real vcenter does.
metrics := []string{"datastore.read.average", "datastore.write.average"}
hostID := "host-14"
metricInstance := "*"
perfManager := performance.NewManager(client.Client)
start := time.Now().Add(-2 * time.Minute)
end := time.Now()
pq := types.PerfQuerySpec{
MaxSample: 5,
MetricId: []types.PerfMetricId{{Instance: metricInstance}},
IntervalId: int32(20),
StartTime: &start,
EndTime: &end,
}
refs := []types.ManagedObjectReference{{Type: "HostSystem", Value: hostID}}
sample, err := perfManager.SampleByName(ctx, pq, metrics, refs)
if err != nil {
Exit(err)
}
metricSeries, err := perfManager.ToMetricSeries(ctx, sample)
if err != nil {
Exit(err)
}
fmt.Printf("%s,%s,%s,%s,%s,%s\n", "Host", "Time", "MetricName", "Instance", "Unit", "Value")
for _, m := range metricSeries {
for id, sample := range m.SampleInfo {
for _, e := range m.Value {
value := func() string {
if e.Value != nil {
if len(m.SampleInfo) == len(e.Value) {
return strconv.Itoa(int(e.Value[id]))
} else {
return fmt.Sprint(strings.Fields(strings.Trim(fmt.Sprint(e.Value), "[]")), "|")
}
}
return "?"
}()
fmt.Printf("%s,%s,%s,%s,%s,%s\n", m.Entity.Value, sample.Timestamp.String(), e.Name, e.Instance, e.Unit, value)
}
}
}
Activity
github-actions commentedon Aug 29, 2025
Howdy 🖐 sanderdescamps ! Thank you for your interest in this project. We value your feedback and will respond soon.
If you want to contribute to this project, please make yourself familiar with the
CONTRIBUTIONguidelines.sanderdescamps commentedon Sep 2, 2025
I've found how to link the metrics to the datastore. The uuid is the uuid of the volume defined in the host.