VMware {code}

 View Only
  • 1.  Unable to retrieve performance metric for a vm

    Posted Jun 01, 2023 02:51 PM

    Hello, 

    I'd like to retrieve advanced performance metrics via a vmware API, but I can't figure out how (even after trying documentation and googling).

    I want to get power usage data for single VMs in an ESXI Cluster. I am able to see a chart based based on this data in vSphere representing the power usage by clicking on VM > Monitor > Performance > Advanced.

    I am using the System Version 7.0.3.01300

    I tried the routes 

     

    /rest/vcenter/vm/my-vm-id

     

    which unfortunately does not contain the power usage metrics

    and 

     

    /api/stats/data/dp?metric=power.capacity.usage&types=VM=my-vm-id

     

    trying to specify the vm id and vm type in varous combinations always receiving the error message: 

    Invalid data points filter
     
    Any thoughts/advice on this?

    (Please excuse me if the location of the post is wrong - this is my first post in the vmware communities)

     



  • 2.  Re: Unable to retrieve performance metric for a vm

    Posted Jun 30, 2023 09:39 PM

    Same here!

    I know this feature is experimental, but I'm not able squeeze any kind of performance information out of this API and get the following error no matter what parameters I provide:

    {
        "messages": [
            {
                "args": [],
                "default_message": "Invalid data points filter: found empty set of Counters for provided set of (cid,metric,types,resources)",
                "localized": "Invalid data points filter: found empty set of Counters for provided set of (cid,metric,types,resources)",
                "id": "com.vmware.vstats.data_points_invalid_counter_filter"
            }
        ]
    }

     

    I'm guessing it's user error due to not understanding this API call. 

    If anyone could provide an example of how to invoke this API, it would be greatly appreciated.

    Thank you much!

       R.



  • 3.  Re: Unable to retrieve performance metric for a vm

    Posted Jul 04, 2023 04:32 PM

    Looks like Create Acq Spec is not created.
    vStats collects data only for the configured AcqSpecs.

    Try these steps:

    1. Create AcqSpecs with POST Create AcqSpec API
    POST: https://{api_host}/api/stats/acq-specs
    Spec:

     

    {
        "counters": {
            "cid_mid": {
                "cid":"power.capacity.usage.VM"
            }
        },
        "interval" :"30",
        "expiration":"10000000000",
        "resources": [       
             {
                "type":"VM",
                "id_value":"<vm-moid>",
                "predicate":"EQUAL"
            }
        ]
    }

     

    2. Query Data Points Data:

    GEThttps://{api_host}/api/stats/data/dp?cid=power.capacity.usage.VM&types=VM

     

     

     



  • 4.  RE: Re: Unable to retrieve performance metric for a vm

    Posted 17 days ago

    Hi there,

    I have been looking for a way to get the stats too and have tried something like this for a host before seeing this thread, but still, I'm stuck.

    Two examples:

    • What I tried earlier:
    curl -sk -X POST -H "vmware-api-session-id: ${TOKEN}" "https://${VC}/api/stats/acq-specs" -d '{"counters": {"cid": "cpu.capacity.usage.HOST"}, "interval" :"30", "resources": [{"type":"HOST", "id_value": "host-22", "predicate":"EQUAL"}] }'

    What I got:

    {
      "error_type": "INVALID_REQUEST",
      "messages": [
        {
          "args": [],
          "default_message": "Unsupported media type.",
          "id": "com.vmware.vapi.rest.unsupportedMediaType"
        }
      ]
    }
    
    • What I tried after reading this thread:
    curl -sk -X POST -H "vmware-api-session-id: ${TOKEN}" "https://${VC}/api/stats/acq-specs" -d '
    {
        "counters": {
            "cid_mid": {
                "cid":"power.capacity.usage.VM"
            }                                  
        },
        "interval" :"30",
        "expiration":"10000000000",
        "resources": [       
             {               
                "type":"VM",
                "id_value":"vm-5175",
                "predicate":"EQUAL"
            }                      
        ]    
    }' | jq

    Same result:

    {
      "error_type": "INVALID_REQUEST",
      "messages": [
        {
          "args": [],
          "default_message": "Unsupported media type.",
          "id": "com.vmware.vapi.rest.unsupportedMediaType"
        }
      ]
    }

    Did I miss anything?

    Any hints are welcome!

    PS my vCenter vSphere client indicates version 8.0.2.00300.




  • 5.  RE: Re: Unable to retrieve performance metric for a vm

    Posted 17 days ago

    OK, I found where I was wrong: my curl command lacked the Content-Type header for the POST request to work...

    Here's how it worked for me:

    • First you need to create an AcqSpecs entry. For example if you need to monitor memory usage on a ESX host:
      curl -sk -X POST -H "vmware-api-session-id: ${TOKEN}" "https://${VC}/api/stats/acq-specs" -H 'Content-type: application/json' -d '{"counters": { "cid_mid": {"cid": "mem.capacity.usage.HOST"}}, "interval" :"30", "resources": [{"type":"HOST", "id_value": "host-22", "predicate":"EQUAL"}] }'
      You should get a quoted integer as a response. For example in my case I got "103".

    • Then, if you need to make sure it worked, you may send a GET request to the same endpoint and check in the list that yours has been created with curl -sk -X GET -H "vmware-api-session-id: ${TOKEN}" "https://${VC}/api/stats/acq-specs" | jq
      {
        "acq_specs": [
          {
            "counters": {
              "cid_mid": {
                "mid": "",
                "cid": "mem.capacity.usage.HOST"
              },
              "set_id": ""
            },
            "resources": [
              {
                "predicate": "EQUAL",
                "scheme": "moid",
                "type": "HOST",
                "id_value": "host-22"
              }
            ],
            "expiration": 1738256420,
            "interval": 30,
            "memo_": "",
            "id": "103",
            "status": "ENABLED"
          }
        ]
      }

    • Then you should be able to get the vstats this way: curl -sk -X GET -H "vmware-api-session-id: ${TOKEN}" "https://${VC}/api/stats/data/dp?rsrcs=type.HOST.moid=host-22&cid=mem.capacity.usage.HOST" | jq
      {
        "data_points": [
          {
            "val": 11997.39,
            "mid": "-6666431365540150058",
            "rid": "102",
            "cid": "mem.capacity.usage.HOST",
            "ts": 1738250439
          },
          ...
        ]
      }

    My suggestion for the people that maintain the documentation: an explanation in the /data/dp endpoint's documentation page mentioning that the previous operations are mandatory would have saved me a certain number of hours of perplexity.