PowerShell-Influx icon indicating copy to clipboard operation
PowerShell-Influx copied to clipboard

Question? DataType of Object in InflxDB

Open DerT94 opened this issue 2 years ago • 1 comments

By checking the code gound this if clause.

  if ($MetricObject.Metrics[$Metric] -isnot [ValueType]) { 
                        $MetricValue = '"' + $MetricObject.Metrics[$Metric] + '"'
                    }
                    else {
                        $MetricValue = $MetricObject.Metrics[$Metric] | Out-InfluxEscapeString
                    }
            
                    "$($MetricObject.Measure | Out-InfluxEscapeString)$TagData $($Metric | Out-InfluxEscapeString)=$MetricValue $timeStampNanoSecs"

Can you explain the $MetricObject.Metrics[$Metric] -isnot [ValueType] part? By testing, I found out that it checks which data types are used. However, I do not quite understand how

DerT94 avatar May 08 '23 13:05 DerT94

Sorry for the late response. This line is checking if the metric is numeric or not. If its not numeric then it assumes it should be treated as a string and wraps the value in quotation marks.

It works by checking if the value is of type [valuetype]. These are described here: https://learn.microsoft.com/en-us/powershell/scripting/lang-spec/chapter-04?view=powershell-7.3#42-value-types

Its not perfect as a single [char] value is treated as valuetype, but thats a pretty unlikely case in this instance.

markwragg avatar Aug 03 '23 13:08 markwragg