Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

/stats returning JSON nested objects instead of array?

I noticed that requesting a list of virtuals returns a JSON array, while the stats for the same collection returns nested objects.

Is this intentional?

https://hostname/mgmt/tm/ltm/virtual             << returns JSON array

https://hostname/mgmt/tm/ltm/virtual/stats       << returns JSON nested objects
`</pre>

Details (tweaked to protect the innocent):

<pre>`https://hostname/mgmt/tm/ltm/virtual?$select=destination,name

{
    "kind": "tm:ltm:virtual:virtualcollectionstate",
    "selfLink": "https://localhost/mgmt/tm/ltm/virtual?$select=destination%2Cname&ver=12.1.2",
    "items": [
        {
            "name": "vs_vlan1",
            "destination": "/Common/10.15.15.0:0"
        },
        {
            "name": "vs_vlan2",
            "destination": "/Common/any:0"
        }
    ]
}

The above output stores the virtuals (and its details) in an array. However, /stats changes that to nested objects:

https://hostname/mgmt/tm/ltm/virtual/stats?$select=destination,tmName

{
    "kind": "tm:ltm:virtual:virtualcollectionstats",
    "selfLink": "https://localhost/mgmt/tm/ltm/virtual/stats?$select=destination%2Cname%2CtmName&ver=12.1.2",
    "entries": {
        "https://localhost/mgmt/tm/ltm/virtual/~Common~vs_vlan1/stats": {
            "nestedStats": {
                "entries": {
                    "destination": {
                        "description": "10.15.15.0:any"
                    },
                    "tmName": {
                        "description": "/Common/vs_vlan1"
                    }
                }
            }
        },
        "https://localhost/mgmt/tm/ltm/virtual/~Common~vs_vlan2/stats": {
            "nestedStats": {
                "entries": {
                    "destination": {
                        "description": "any:any"
                    },
                    "tmName": {
                        "description": "/Common/vs_vlan2"
                    }
                }
            }
        }
    }
}

0
Rate this Question
Comments on this Question
Comment made 21-Aug-2018 by Hamish 3391

Examples are always helpful for when people won't have immediate access to a BigIP to verify...

0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

The endpoint without stats is equivalent to tmsh list: it dumps the configuration information. The endpoint with stats is tmsh show and shows the stat information. They are different commands hence different outputs.

Please refer to pp. 35-38 of iControl REST User Guide Version 13.1 for more information on the statistical output. For those who would like to see example outputs, see iControl REST Cookbook - Virtual Server (ltm virtual).

If you are asking why /mgmt/tm/ltm/virtual returns {"items":[vs1object, vs2object, ...]} while /mgmt/tm/ltm/virtual/stats returns {"entries":{vs1statEndpoint: {statsObject1}, vs2statEndpoint:{statsObject2}, ....}, then I imagine that's just an implementation decision, most likely due to the differences between outputs from list/show tmsh commands.

0
Comments on this Answer
Comment made 21-Aug-2018 by Arie 2069

I realize that it's providing show vs list, but the behavior/output is inconsistent and nested objects are more difficult to parse than arrays. It also means that the same code cannot be (re)used even though the iControl request is virtually the same.

Sounds like two different project teams implemented the output differently...

Is F5 planning to update the output for list to use JSON arrays? Even adding a query string parameter to override the default output of nested objects to arrays would be great.

0
Comment made 22-Aug-2018 by Satoshi Toyosawa

To my knowledge, there is no plan for redesigning the iControl REST data structure. If you have a request for feature enhancement, my suggestion is to raise a support ticket to F5 Support.

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

That's not what I would call 'nested objects'. That's a hash with the name of the object used as a key. There's nothing inherently more difficult in passing through a hash, and it has the advantage that you can access each object directly (by key) rather than having to search from one end o the array to the other.

I thought you mean it was somehow corrupted and one object was nested inside the previous one. But it looks fine to me.

If you think about it, it makes sense... When grabbing the list of virtual you're probably going to run through them from one to the next anyway, because at the end of the day the only data is its name. But when accessing stats it's nicer to be able to directly grab the object you're interested in rather than having to run through the array and then work out where the data is for the object you're most interested in (Obviously if you wanted just one object you'd not have to worry about that)

As a programmer I think it makes far more sense the way they produce the data now.

0