Scripts

Welcome to the Nutanix NEXT community. To get started please read our short welcome post. Thanks!

cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting cluster metrics script

Trailblazer

Extracting cluster metrics script

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&startTimeInUs..."
$out = Invoke-RestMethod -Uri $url -Headers $Header
$out.statsSpecificResponses | ft
$out.statsSpecificResponses.values

 

These are the powershell errors:

 

PS C:\Program Files (x86)\Nutanix Inc\NutanixCmdlets\bin> C:\Users\Administrator\Desktop\IOLATENCY.ps1
10.192.186.50:
Get-Date : Cannot bind parameter 'Date'. Cannot convert value "3/31/2017 11:00 AM" to type "System.DateTime". Error: "S
tring was not recognized as a valid DateTime."
At C:\Users\Administrator\Desktop\IOLATENCY.ps1:8 char:21
+ $enddate = Get-Date '3/31/2017 11:00 AM'
+                     ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Smiley Happy [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 inst
ance of an object."
At C:\Users\Administrator\Desktop\IOLATENCY.ps1:10 char:54
+ [int64]$end_time = ((New-TimeSpan -Start $epoch -End $enddate).TotalMilliseconds ...
+                                                      ~~~~~~~~
    + CategoryInfo          : WriteError: (Smiley Happy [New-TimeSpan], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.NewTimeSpanCommand

 

 

Any help is appreciated.

 

 

Seba

 

Tags (2)
3 REPLIES
Nutanix Employee

Re: Extracting cluster metrics script

@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)*1000
add-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

Tags (2)
Community Manager

Re: Extracting cluster metrics script

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.

Tags (2)
Nutanix Employee

Re: Extracting cluster metrics script

We joined a webex meeting .

Created and shared the below script to @sverhoevne

 

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