Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Created December 6, 2018 03:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamdriscoll/2761b9066254556d0b4b856c041ed69f to your computer and use it in GitHub Desktop.
Save adamdriscoll/2761b9066254556d0b4b856c041ed69f to your computer and use it in GitHub Desktop.
Function to retrieve data from InfluxDB from PowerShell
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