Skip to content

How to get datastore name for host datastore performance metrics #3847

Closed

Description

@sanderdescamps

Hi,

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

  1. github-actions commented on Aug 29, 2025

    @github-actions
    Contributor

    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 CONTRIBUTION guidelines.

  2. sanderdescamps commented on Sep 2, 2025

    @sanderdescamps
    Author

    I've found how to link the metrics to the datastore. The uuid is the uuid of the volume defined in the host.

  3. locked and limited conversation to collaborators on Sep 2, 2025
  4. converted this issue into a discussion #3849 on Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions