Extracting cluster metrics script


Badge +7
Hey,

I'm trying to get Average Io latency.
I'm using this script which I found in another post, but I can't seem to get it to work:

$server = read-host "10.192.186.50"$username = "admin"$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 '3/1/2017 10:00 AM'$enddate = Get-Date '3/31/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://10.192.186.50: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

These are the powershell errors:

PS C:Program Files (x86)Nutanix IncNutanixCmdletsin> C:UsersAdministratorDesktopIOLATENCY.ps110.192.186.50:Get-Date : Cannot bind parameter 'Date'. Cannot convert value "3/31/2017 11:00 AM" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."At C:UsersAdministratorDesktopIOLATENCY.ps1:8 char:21+ $enddate = Get-Date '3/31/2017 11:00 AM'+ ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
New-TimeSpan : Cannot bind parameter 'End' to the target. Exception setting "End": "Object reference not set to an instance of an object."At C:UsersAdministratorDesktopIOLATENCY.ps1:10 char:54+ [int64]$end_time = ((New-TimeSpan -Start $epoch -End $enddate).TotalMilliseconds ...+ ~~~~~~~~ + CategoryInfo : WriteError: (:) [New-TimeSpan], ParameterBindingException + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.NewTimeSpanCommand


Any help is appreciated.


Seba

3 replies

Userlevel 4
Badge +19
sverhoevne

Please try this.

$server = "10.192.186.50"$username = "admin"$password = "password"$stats = "avg_io_latency_usecs"$epoch = Get-Date -Date "01/01/1970" #dont change this line$startdate = Get-Date '3/1/2017 10:00 AM'$enddate = Get-Date '3/31/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)*1000add-type @"using System.Net;using System.Security.Cryptography.X509Certificates;public class TrustAllCertsPolicy : ICertificatePolicy {public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate,WebRequest request, int certificateProblem) {return true;}}"@[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy$Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))}$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
Userlevel 7
Badge +35
Hi sverhoevne -- were you able to try out the suggestion from sandeepmp?

--If you find an answer helpful, consider clicking the 'Accept as Solution' button. Marking a reply as an accepted solution helps our community identify content that solves users’ problems.
Userlevel 4
Badge +19
We joined a webex meeting .
Created and shared the below script to sverhoevne

https://github.com/sandeepmp/nutanix/blob/master/Cluster-Report-NTNX.Ps1


Reply