What are valid names for the -metrics parameter in the get-ntnxclusterstat cmdlet


Badge +4
Trying to figure out how to automate getting cluster IOPS and latency stats via powershell. so far it looks like get-ntnxclusterstat is the cmdlet to do that but I can't crack the code and there is NO document I can find anywhere that gives real examples of how to provide the names for the -metrics parameter that each of the get-ntnx*stat cmdlets require.

I see that when you call get-cluster, the cluster object has a .stats property, which lists name-value pairs for the current 30 second interval, but trying to use any of those names such as 'num_iops' or 'num_read_iops' returns a failure
successful : False
message : Invalid stats field name specified
startTimeInUsecs : 0
intervalInSecs : 0
metric : System.String[]
values : {}

So where is the super-secret list of metrics names? * doesn't work either, and not providing the Metrics parameter is not allowed.


23 replies

Userlevel 7
Badge +30
Good question, I dont know offhand, I'll ask internally to see what I can find.
Userlevel 7
Badge +30
I'll admit, the metric switches are very poorly documented for this. I've opened an internal engineering ticket to get it all formally documented, but that may take some time.

If you've got a pressing need, we're always happy to help through SLA based support, by filing a ticket on portal.nutanix.com if you are NX or SX customer, or through your respective OEM partner for HX or XC gear. They can dig in and collaborate with engineering real time to pull out what you need.
Badge +4
Could you give me a hint about the basic syntax? Is it possible to figure out the valid names based on already available information? I appreciate the need for full documentation, but I'd rather be able to actually use the cmdlets right now.
Badge +4
any updates yet?
Userlevel 4
Badge +19
Hi geoffd
Please find the below commands to get the list of available stats.

(Get-NTNXCluster -Servers "server/ip").usagestats
(Get-NTNXCluster -Servers "server/ip").stats

Regards,
Sandeep MP
Badge +4
sandeepmp

Thanks for the reply. I'l looking for the following stats:
Cluster Disk IO latency
Cluster Disk IOPS
Host Disk IO Latency
Host Disk IOPS

I pulled the list of stats from (get-ntnxcluster -Server '').stats and decided to try 'avg_io_latency_usecs' in hopes it will correspond to 'Cluster Disk IO Latency'
My powershell session has an active connection following Connect-NTNXCluster
I created a start datetime $start = get-date '2/22/2017 10:00 AM', and an end datetime $stop = get-date '2/22/2017 11:00 AM'
I ran the following cmd:
get-ntnxclusterstat -Metrics 'avg_io_latency_usecs' -starttimeinusecs $start.ticks -endtimeinusecs $stop.ticks -IntervalInSecs 60

the result is
successful : False
message : Invalid stats field name specified
startTimeInUsecs : 0
endTimeInUsecs : 0
metric : System.String[]
values : {}

So what an I doing wrong?
Userlevel 4
Badge +19
Hi geoffd,

StartTimeInUsecs value should be in "microseconds". So we need to convert the time to microseconds.

Please follow the below to do the same

#date input section
-----------------------
$epoch = Get-Date -Date "01/01/1970" #donot change this line


$startdate = get-date 'Provide date here'$enddate = get-date 'provide date here'

#convert time to Microseconds=============================
[int64]$date_start = ((New-TimeSpan -Start $epoch -End $startdate).TotalMilliseconds)*1000[int64]$date_end = ((New-TimeSpan -Start $epoch -End $enddate).TotalMilliseconds)*1000

#Script
=======

get-ntnxclusterstat -Metrics 'avg_io_latency_usecs' -starttimeinusecs $date_start -endtimeinusecs $date_end -IntervalInSecs 60

Regards,
Sandeep MP

Badge +4
sandeepmp

OK, tried that configuration, but I'm still getting the same error about the invalid stats field name. are you able to get data using the 'avg_io_latency_usecs' metric? Could I have a version mismatch?

Badge +4
I am running version 4.7.3.1 starter license. NutanixCmdlets are version 1.7

Userlevel 4
Badge +19
Hi Geoffd,

I am currently testing this in V1.7.
As a workaround, you can use the Rest-API method to gather the necessary info.

$server = read-host "Enter the IP/FQDN"$username = "Username"$password = "password"$stats = "avg_io_latency_usecs"$Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))}$epoch = Get-Date -Date "01/01/1970" #dont change this line$startdate = Get-Date '2/26/2017 10:00 AM'$enddate = get-date '2/26/2017 11:00 AM'[int64]$start_time = ((New-TimeSpan -Start $epoch -End $startdate).TotalMilliseconds)*1000[int64]$end_time = ((New-TimeSpan -Start $epoch -End $enddate).TotalMilliseconds)*1000
$url = "https://${server}:9440/PrismGateway/services/rest/v1/cluster/stats/?metrics=$stats&startTimeInUsecs=$start_time&endTimeInUsecs=$end_time&intervalInSecs=60"
$out = Invoke-RestMethod -Uri $url -Headers $Header$out.statsSpecificResponses | ft$out.statsSpecificResponses.values

Regards,
Sandeep MP
Userlevel 4
Badge +19
Hi Geoffd,

This issue is fixed in V1.7.5(AOS 4.7.5)

Regards,
Sandeep MP
Badge +4
Thank you this does work!
Badge +4
Just one more point. As I was finally getting lists of stats and putting them into CSV format, I found that the IOPS stats I was getting from the cluster and the hosts from the num_iops metric seemed to have no relation to the actual number for the same time period I could see in the Prism console. I believe the problem is that the actual timeframe is supposed to be UTC internally, is that right? So the $epoch should be 1/1/1970 0:00 UTC? I think in my case its defaulting to US Central time, which is 1/1/1970 6:00 UTC. for example if I run
PS > $epoch = Get-date -date "01/01/1970"
PS > $epoch.ToUniversalTime()
Thursday, January 1, 1970 6:00:00 AM

I think this is throwing off my results. Do you agree?
Badge +4
I have tested and confirmed that the start and end datetimes MUST be converted to UTC or else you will get an unexpected time offset

$epoch = Get-Date -Date "01/01/1970" #dont change this line$startdate = (Get-Date '2/26/2017 10:00 AM').ToUniversalTime()$enddate = (Get-Date '2/26/2017 11:00 AM').ToUniversalTime()[int64]$start_time = ((New-TimeSpan -Start $epoch -End $startdate).TotalMilliseconds)*1000[int64]$end_time = ((New-TimeSpan -Start $epoch -End $enddate).TotalMilliseconds)*1000

All good now, and rest stats correspond with Console CSV export data
Badge
What specifically worked? Did you upgrade to a version of NOS higher than 4.7.5 or did you get the Rest-API workaround working?


Badge +4
I'm constrained not to upgrade atm, so I'm using the rest API. However I believe the UTC conversion would apply in either case. Would be Super Helpful if the Get-NTNX*Stats cmdlets did their own internal conversion to usecs from epoch so we could just pass local zone DateTime objects like civilized people.
Badge +7
Hey,

I tried using the script you provided but I get this error:



What did i do wrong?


Seba
Badge +7
Empty
Userlevel 4
Badge +19
Please share the output for "$PSVersionTable"
Badge +7
Hey sandeepmp

Here is the ps version:




Seba
Userlevel 4
Badge +19
sverhoevneThe issue is due to the powershell version.The Rest calls can be done from powershell v3 onwards.Please update the powershell version to v3 or newer.RegardsSandeep MP
Badge +7
Solved!
Thx


Seba
Badge
Confirmed today that this cdmlet now works on NOS 5.0.1. Yippe! Thanks sandeepmp for the epoch conversion.

example output

successful : Truemessage :startTimeInUsecs : 1493225550000000intervalInSecs : 60metric : avg_io_latency_usecsvalues : {268, 238, 344, 272, 425, 664, 801, 453, 273, 219, 222, 344, 321, 1618, 329, 258, 248, 329, 259, 245, 296, 248, 241, 306, 244, 271, 365, 311, 342, 253, 276, 258, 234, 229, 266, 327, 221, 403, 396, 292, 353, 267, 331, 277, 290, 333, 274, 538, 405, 228, 307, 253, 261, 266, 319, 320, 472, 349, 613, 319, 295, 299, 422, 270, 446, 305, 222, 420, 365, 272, 301, 291, 339, 296, 251, 362, 276, 425, 387, 316, 274, 252, 235, 322, 255, 247, 302, 305, 337, 284, 309, 369, 264, 325, 371, 325, 288, 335, 384, 450, 456, 917, 275, 1665, 290, 309, 549, 385, 386, 302, 390, 308, 310, 1290, 1372, 270, 596, 1206, 1067, 296, 319, 260, 313, 316, 487, 333, 533, 556, 348, 300, 296, 351, 362, 268, 344, 294, 320, 269, 305, 234, 277, 311,}

sandeepmp wrote:Hi geoffd,

StartTimeInUsecs value should be in "microseconds". So we need to convert the time to microseconds.

Please follow the below to do the same

#date input section
-----------------------
$epoch = Get-Date -Date "01/01/1970" #donot change this line


$startdate = get-date 'Provide date here'$enddate = get-date 'provide date here'

#convert time to Microseconds=============================
[int64]$date_start = ((New-TimeSpan -Start $epoch -End $startdate).TotalMilliseconds)*1000[int64]$date_end = ((New-TimeSpan -Start $epoch -End $enddate).TotalMilliseconds)*1000

#Script
=======

get-ntnxclusterstat -Metrics 'avg_io_latency_usecs' -starttimeinusecs $date_start -endtimeinusecs $date_end -IntervalInSecs 60

Regards,
Sandeep MP


Reply