VMware Cloud Community
kcross
Contributor
Contributor

VROps API: Mapping from a statkey instance to its resource

Hi,

I'm attempting to use the API to extract some monitoring data about VM's.  I'm interested in getting the allocated space in a datastore for each VM.

I can get the required stat for each datastore by first listing the statkeys for the VM, then running the query below for each statkey that matches config|hardware:*|disk_Space

suite-api/api/resources/stats/query

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ops:stat-query xmlns:ops="http://webservice.vmware.com/vRealizeOpsMgr/1.0/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <ops:resourceId>***</ops:resourceId>

    <ops:statKey>config|hardware:3351|disk_Space</ops:statKey>

    <ops:rollUpType>AVG</ops:rollUpType>

    <ops:intervalType>DAYS</ops:intervalType>

    <ops:intervalQuantifier>4</ops:intervalQuantifier>

    <ops:dt>false</ops:dt>

    <ops:metrics>false</ops:metrics>

    <ops:currentOnly>false</ops:currentOnly>

    <ops:begin>1515369600000</ops:begin>

    <ops:end>1515624194000</ops:end>

</ops:stat-query>

I get a response back like this with the stats that I need:

<ops:stat>

<ops:timestamps>1515686399999</ops:timestamps>

<ops:statKey>

<ops:key>config|hardware:3351|disk_Space</ops:key>

</ops:statKey>

<ops:rollUpType>AVG</ops:rollUpType>

<ops:intervalUnit>

<ops:quantifier>4</ops:quantifier>

<ops:intervalType>DAYS</ops:intervalType>

</ops:intervalUnit>

<ops:data>60.0</ops:data>

</ops:stat>

The issue I am facing is how do I resolve the statkey with instance, eg 3351 back to the datastore resource, or even just its name?  This happens in the UI, but I cannot figure out where the reference is

0 Kudos
2 Replies
paruljain
Contributor
Contributor

Were you able to find a solution? I am struggling with the same issue. Thanks!

0 Kudos
kcross
Contributor
Contributor

Hi

The way I had to do this was to get the internal ID directly from vrops postgres DB:

"SELECT resource_id, internal_id, adapter_kind, resource_kind, resource_name, creation_time FROM public.resource"

The drawback here was having to change pg_hba.conf on the appliance to allow a remote connection in.

0 Kudos