Created
December 6, 2018 03:34
-
-
Save adamdriscoll/2761b9066254556d0b4b856c041ed69f to your computer and use it in GitHub Desktop.
Function to retrieve data from InfluxDB from PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-InfluxDb { | |
param( | |
[Parameter()] | |
$Url = 'http://localhost:8086/query?db=performance_data', | |
[Parameter()] | |
$Query | |
) | |
$Results = Invoke-RestMethod -Uri "$Url&q=$Query" | |
foreach($series in $results.results.series) { | |
$ResultSeries = @{ | |
Fields = @() | |
} | |
foreach($tag in $series.tags.PSObject.Properties) { | |
$ResultSeries[$tag.Name] = $Tag.Value | |
} | |
$Columns = $series.columns | |
foreach($value in $series.values) { | |
$Result = @{} | |
for($i = 0; $i -lt $Columns.Length; $i++) { | |
if ($Columns[$i] -eq 'time') { | |
$result.time = [DateTime]$value[$i] | |
} else { | |
$Result[$columns[$i]] = $value[$i] | |
} | |
} | |
$ResultSeries.fields += $result | |
} | |
$ResultSeries | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment