Code Monkey home page Code Monkey logo

powershell-influx's Introduction

PowerShell-Influx

Build Status Test Coverage

This is a PowerShell module for interacting with the time-series database platform Influx: https://www.influxdata.com/. At the moment the primary purpose is to enable a consistent experience for writing metrics in to Influx via the REST API, UDP or StatsD.

Purpose

This module was written to allow metrics from different sources to be written to InfluxDB, for presentation via one or more Grafana Dashboards. By utilising this module, InfluxDB and Grafana you can create and populate interactive dashboards like these (note: sensitive data has been redacted from these screenshots):

For more details on how to implement these tools, check out my blog post. For more information on how to use the Influx PowerShell module, read on below.

Installation

The module is published in the PSGallery, so if you have PowerShell 5 can be installed by running:

Install-Module Influx -Scope CurrentUser

Usage

There are 3 methods for writing to Influx currently implemented:

  1. Write-Influx which uses the Influx REST API to submit metrics via TCP.
  2. Write-InfluxUDP which transmits metrics to an Influx UDP listener.
  3. Write-StatsD which transmits metrics via UDP to a StatsD listener (the StatsD listener can be enabled via the Influx Telegraf component -- see the Statsd Server section in the telegraf.conf).

For example:

#REST API
Write-Influx -Measure Server -Tags @{Hostname=$env:COMPUTERNAME} -Metrics @{Memory=50;CPU=10} -Database Web -Server http://myinflux.local:8086 -Verbose

#REST API with authentication
Write-Influx -Measure Server -Tags @{Hostname=$env:COMPUTERNAME} -Metrics @{Memory=50;CPU=10} -Database Web -Server http://myinflux.local:8086 -Credential (Get-Credential) -Verbose
 
#Influx UDP
Write-InfluxUDP -Measure Server -Tags @{Hostname=$env:COMPUTERNAME} -Metrics @{Memory=50;CPU=10} -Database Web -IP 1.2.3.4 -Port 8089 -Verbose
 
#StatsD UDP
Write-Statsd "Server.CPU,Hostname=$($env:COMPUTERNAME):10|g" -IP 1.2.3.4 -Port 8125 -Verbose

This project was created so that PowerShell could be used to routinely query various infrastructure metrics and then send those metrics in to Influx for storage, where they could then be presented via a Grafana dashboard.

As such the module also contains a number of cmdlets for retrieving data various sources. Current implementations include: VMWare, 3PAR, Isilon and TFS. You will find these cmdlets under \Public\<source>.

The Get-SomeMetric cmdlets return a Metric type object which can be consumed by any of the Write-* cmdlets above via the pipeline or the `-InputObject' parameter. For example:

# Get metrics for VMWare Datastores and write to Influx via the REST API
Get-DatastoreMetric | Write-Influx

# Get metrics for 3PAR Systems and write to Influx via the Influx UDP listener
Get-3ParSystemMetric -SANIPAddress '3.4.5.6' -SANUserName someuser -SANPasswordFile 'C:\some3parpasswordfile.txt' | Write-InfluxUDP

# Get TFS Build data and send to Influx via StatsD (note that Write-StatsD converts the metric object received via the pipleine to StatsD formatted strings automatically)
Get-TFSBuildMetric -TFSRootURL 'https://mytfsurl.local/tfs' -TFSCollection somecollection -TFSProject someproject -Database tfs | Write-StatsD -Type g

There are also Send-SomeMetric cmdlets that were implemented to retrieve metrics from a datasource and send it to Influx via the REST API in one step. These continue to exist for backwards compatibility, but for more flexibility use the Get-SomeMetric cmdlets and pipe their results to whatever Write-* method you want to use for interacting with Influx.

Results of other Powershell commands or custom objects can be sent to Influx. Simply map the object properties to a Metric object using the ConvertTo-Metric cmdlet.

#Send data from Get-Process to InfluxDB using the REST API with authentication
Get-Process -Name <__Processname__> | ConvertTo-Metric -Measure test -MetricProperty CPU,PagedmemorySize -TagProperty Handles,Id,ProcessName | Write-Influx -Database windows_system_monitor -Server http://<__InfluxEndpoint__>:8086 -Credential (Get-Credential) -Verbose

Implementation Example

Here is an example script which could be run as a scheduled task every 5 minutes to send stats from various sources in to Influx. Note this requires a number of dependent modules be present such as the VMWare PowerShell cmdlets.

This script uses the Send-SomeMetric cmdlets which combine the equivalent Get-SomeMetric cmdlet with Write-Influx to transmit metrics in one command via the REST API.

Import-Module Influx

#VMWARE
Connect-VIServer 1.2.3.4 | Out-Null

Send-HostMetric
Send-DatastoreMetric
Send-ResourcePoolMetric
Send-DatastoreClusterMetric
Send-DatacenterMetric

#3PAR
Send-3ParSystemMetric -SANIPAddress '3.4.5.6' -SANUserName someuser -SANPasswordFile 'C:\some3parpasswordfile.txt'

#Isilon
Import-Module SSLValidation
Disable-SSLValidation

Send-IsilonStoragePoolMetric -IsilonName someisilon -Cluster test -IsilonPasswordFile 'C:\someIsilonpasswordfile.txt'

#TFS
Send-TFSBuildMetric -TFSRootURL 'https://mytfsurl.local/tfs' -TFSCollection somecollection -TFSProject someproject -Database tfs

Cmdlets

A full list of implemented cmdlets is provided below for your reference. Use Get-Help <cmdlet name> with these to learn more about their usage.

Cmdlet Description
Get-3ParSystemMetric Returns a metric object for 3PAR systems.
Get-3ParVirtualVolumeMetric Returns a metric object for 3PAR virtual volumes.
Get-DatacenterMetric Returns a metric object for VMWare datacenters.
Get-DatastoreClusterMetric Returns a metric object for VMWare datastore clusters.
Get-DatastoreMetric Returns a metric object for VMWare datastores.
Get-HostMetric Returns a metric object for VMWare hosts.
Get-IsilonStoragePoolMetric Returns a metric object for Isilon storage pools.
Get-ResourcePoolMetric Returns a metric object for VMWare resource pools.
Get-TFSBuildMetric Returns a metric object for TFS builds.
Get-VMMetric Returns a metric object for VMWare virtual machines.
Send-3ParSystemMetric Sends metrics via the Influx REST API for 3PAR systems.
Send-3ParVirtualVolumeMetric Sends metrics via the Influx REST API for 3PAR virtual volumes.
Send-DatacenterMetric Sends metrics via the Influx REST API for VMWare datacenters.
Send-DatastoreClusterMetric Sends metrics via the Influx REST API for VMWare datastore clusters.
Send-DatastoreMetric Sends metrics via the Influx REST API for VMWare datastores.
Send-HostMetric Sends metrics via the Influx REST API for VMWare hosts.
Send-IsilonStoragePoolMetric Sends metrics via the Influx REST API for Isilon storage pools.
Send-ResourcePoolMetric Sends metrics via the Influx REST API for VMWare resource pools.
Send-TFSBuildMetric Sends metrics via the Influx REST API for TFS builds.
Send-VMMetric Sends metrics via the Influx REST API for VMWare virtual machines.
Write-Influx Writes to Influx via the REST API.
Write-InfluxUDP Writes to Influx via UDP.
Write-StatsD Writes to Influx via a StatsD listener.
Send-Statsd Alias of Write-StatsD (for backwards compatibility).
ConvertTo-StatsDString Converts a metric object output from one of the Get-SomeMetric cmdlets to StatsD string format. This is also performed automatically if a metric object is piped to Write-StatsD.
ConvertTo-Metric Converts the specified properties of any object to a metric object, which can then be easily transmitted to Influx by piping to one of the Write- cmdlets.
ConvertTo-InfluxLineString Convert metrics to the Influx line protocol format, output as strings.

powershell-influx's People

Contributors

badbart avatar markwragg avatar trovalo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powershell-influx's Issues

Get all Services (name, displayname, status, start type) to write to Influx.

Hi all,

I'm trying to get all Windows server services to write to InfluxDB but am experiencing a slight issue. I initially tried to do the following (I left the basic metrics in to see if it was writing) until I realised that $Metrics does not like nested hash tables.

#Influx Database HTTP Address.
$influxDB = "http://localhost:8086"
    # Get all of your metrics.
    While($true){
        $ValuesList = Get-Counter -Counter "\Memory\Available Bytes","\Processor(*)\% Processor Time"
        $MemoryActive = [math]::Round($ValuesList.CounterSamples[0].CookedValue,3) /1024 /1024
        $MemoryFreeMB = [math]::Round($MemoryActive)
        $ProcessorActive = [math]::Round($ValuesList.CounterSamples[1].CookedValue,2)
        $GetWindowsServices = Get-Service | select -Property Name,DisplayName,Status,StartType
        $Metrics = @{
            "CPU Active" = $ProcessorActive
            "Free RAM MB" = $MemoryFreeMB
            "Services" = $GetWindowsServices
    }
    # Send all Metrics to InfluxDB.
    Write-Influx -Measure Server -Tags @{Prod=$env:COMPUTERNAME} -Metrics $Metrics -Database telegraf -Server http://localhost:8086 -Verbose}

I was wondering if I could do a foreach on the $GetWindowsServices hash table to get this to work. I am learning PowerShell fairly quickly but this has me stumped.

All in all I'm hoping that if this works for the Services then I can use the same format for Windows Event Logs.

Thanks

P.s. I'm very new to github and couldn't find how to add this as a request rather than an issue.

write-influx: using $inputObject, we can't use Timestamp parameter

Hello

using an inputobject (generated by ConvertTo-Metric), we can't specify a timestamp (PSDate).
Consequence the timestamp it'sq when the command is executed

so in a script if we execute 3 time convertto-metric and write-influx, because we collect the data from 3 different source, the timestamp will vary between the 3 collect.

Regards
Tonic8

Error when using "Write-Influx" without Tags

If the command "Write-Influx" is used without tags, an error occurs.

Working Code

Get-Process -Name winlogon | ConvertTo-Metric -Measure test -MetricProperty CPU,PagedmemorySize -TagProperty Handles,Id,ProcessName | Write-Influx -Bucket test -Server https://influxserver:8086 -Token "token" -Verbose

Not working Code

Get-Process -Name winlogon | ConvertTo-Metric -Measure test -MetricProperty CPU,PagedmemorySize  | Write-Influx -Bucket test -Server https://influxserver:8086 -Token "token" -Verbose

Error

Invoke-RestMethod : {"code":"invalid","message":"unable to parse 'test, CPU=\"\" ': missing tag key\nunable to parse 'test, PagedmemorySize=233472 ': missing tag key"}
In C:\Users\ant\Documents\WindowsPowerShell\Modules\Influx\1.0.101\Public\Write-Influx.ps1:202 Zeichen:25
+ ...             Invoke-RestMethod -Uri $URI -Method Post -Body $Body -Hea ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

The error is caused by setting an incorrect comma in the function
According to the following issue, no comma may be present if no tags are transmitted
influxdata/influxdb#3600

In the code, you are using
if ($MetricObject.Tags) { #Build String for Tags }

But $MetricObject.Tags is an emptry hashtable and an empty hastable evaluates "true".
PowerShell/PowerShell#10201

You have to change the code from

  if ($MetricObject.Tags)) {
                $TagData = foreach ($Tag in $MetricObject.Tags.Keys) {
                    if ([string]::IsNullOrEmpty($MetricObject.Tags[$Tag])) {
                        Write-Warning "$Tag skipped as it's value was null or empty, which is not permitted by InfluxDB."
                    }
                    else {
                        "$($Tag | Out-InfluxEscapeString)=$($MetricObject.Tags[$Tag] | Out-InfluxEscapeString)"
                    }
                }
                $TagData = $TagData -Join ','
                $TagData = ",$TagData"
            }

to

  if (($MetricObject.Tags).count -ne 0) {
                $TagData = foreach ($Tag in $MetricObject.Tags.Keys) {
                    if ([string]::IsNullOrEmpty($MetricObject.Tags[$Tag])) {
                        Write-Warning "$Tag skipped as it's value was null or empty, which is not permitted by InfluxDB."
                    }
                    else {
                        "$($Tag | Out-InfluxEscapeString)=$($MetricObject.Tags[$Tag] | Out-InfluxEscapeString)"
                    }
                }
                $TagData = $TagData -Join ','
                $TagData = ",$TagData"
            }

Write-Influx Fails to write zero values

Hi, Trying to send zeros using Write-Influx fails as it drops that part of the hash, simple example below.

Many thanks for writing this great module

Write-Influx -Measure WebServer -Tags @{Server='Host01'} -Metrics @{CPU=100; Memory=50} -Database db1 -Server http://127.0.0.1:8086 -Verbose

VERBOSE: Performing the operation "WebServer,Server=Host01 CPU=100
WebServer,Server=Host01 Memory=50
" on target "http://127.0.0.1:8086/write?&db=db1 ".
VERBOSE: POST http://127.0.0.1:8086/write?&db=db1 with -1-byte payload
VERBOSE: received -1-byte response of content type application/json

Write-Influx -Measure WebServer -Tags @{Server='Host01'} -Metrics @{CPU=100; Memory=0} -Database db1 -Server http://127.0.0.1:8086 -Verbose

VERBOSE: Performing the operation "WebServer,Server=Host01 CPU=100 " on target "http://127.0.0.1:
8086/write?&db=db1 ".
VERBOSE: POST http://127.0.0.1:8086/write?&db=db1 with -1-byte payload
VERBOSE: received -1-byte response of content type application/json

Same command just removed the 5 from the memory parameter on 2nd run

Improve handling of datetime and object properties

some further suggestions from @Tonic8:

  • if a field in an object is a DateType, you can convert it in something InfluxDB will understand:
(dir | select -first1).lastWriteTime | gm
(dir | select -first1).lastWriteTime | get-date -f "yyyy-MM-dd HH:mm:ss.fff"
(dir | select -first1).lastWriteTime | convertTo-UnixTimeNanoseconds

where fff is millisecond, (talked here https://stackoverflow.com/questions/28589520/how-to-store-dates-in-influxdb) and here https://docs.influxdata.com/influxdb/v1.5/query_language/data_exploration/#time-syntax

  • if a field in an object is something not a "string" but a internal field, like this in Citrix sdk (extract of get-brokerSession | GM):
ConnectionViaIP   NoteProperty string ConnectedViaIP=1.2.3.4
ConnectionMode    NoteProperty Citrix.Broker.Admin.SDK.ConnectionMode ConnectionMode=Brokered
  • if you pass it, the conversion is going wrong(missing doublequote), user must prepare the field, to convert it as string, before passing it to convertTo-Metric
  • example with a Boolean field (it should have double-quote),
    $test = New-Object PSObject -Property @{testBoolean=$True}
  • below the result from the Write-Influx commande in Verbose
    Xendesktop,computer1 testBoolean=true 12345678898

Originally posted by @Tonic8 in #15 (comment)

Feature Request: Output to console

Hi,
Would it be possible to add something to Write-Influx where instead of writing to the database, it outputs in the line protocol format that could be utilised by Telegrafs exec plugin?
I am writing various scripts right now and looking for an easy way to switch them between running under Task Scheduler (ie. direct to DB) and under Telegraf.
Thanks

when property have no value do not send property=""

Hello

thanks for the work done :). I have now a limitation:

some object property can have null value, the problem is that when this property is exported there will be conflict on the type of data.

Example with Citrix Xendesktop Powershell sdk, what is actually sent:

Xendesktop,computer1 brokeredTime=7, CatalogName="USA1_aa" 12345678898
Xendesktop,computer1 brokeredTime="", CatalogName="USA1_aa" 12345678898

the data is either int or string :)

it could be cool to have a option to set write-influx -emptyValueDoNotsent (please find something better for the name of the option :) ), with a result of:

Xendesktop,computer1 brokeredTime=7, CatalogName="USA1_aa" 12345678898
Xendesktop,computer1 CatalogName="USA1_aa" 12345678898

In this case, zero would not work as the field with no data represent something:

  • no data mean no event -> useful to check if a ressource is used or not
  • 0 representing user connected in the last hour

Thanks
Tonic8

Issue uploading and strange behaviour using -Whatif

Hello Mark,

Was using Write-Influx successfully to upload data to local InfluxDb 1.7.9. on Windows.

Used the same command to upload to remote server (Unix & cloud based using https and authentication) which did not work. FOr testing I tried -Whatif and saw this unexpected output:
The unexpected thing is that I see multiple lines (one for each Metric value where I was expecting multiple columns and only one line/record. This behaviour was the same for localhost and remote server. Still not sure why remote does not work (Error 400).
Is this an issue with the -Whatif statement or is it really sending out one line per Metric (that would be very ineffecient in regard to DB updates and traffic)

PS C:\Users> Write-Influx -Measure $Measurement -Tags $Tags -Metrics $Metrics -TimeStamp $InfluxTimeStampUTC -Database $Database -Server http://localhost:8086 -whatif
What if: Performing the operation "azo,ChargeID=428569,RunID=51-000022,WorkCtr=0551,Shift_ID=2020-01-27.07,Shift=O,ShopfloorDatum=2020-01-27 ChargeStart="2020-01-27 08:09:03" 1580108943000000000
azo,ChargeID=428569,RunID=51-000022,WorkCtr=0551,Shift_ID=2020-01-27.07,Shift=O,ShopfloorDatum=2020-01-27 Recipe="S41351v1/2" 1580108943000000000
azo,ChargeID=428569,RunID=51-000022,WorkCtr=0551,Shift_ID=2020-01-27.07,Shift=O,ShopfloorDatum=2020-01-27 Weight_pv=0.499 1580108943000000000
azo,ChargeID=428569,RunID=51-000022,WorkCtr=0551,Shift_ID=2020-01-27.07,Shift=O,ShopfloorDatum=2020-01-27 Weight_sv=0.5 1580108943000000000
azo,ChargeID=428569,RunID=51-000022,WorkCtr=0551,Shift_ID=2020-01-27.07,Shift=O,ShopfloorDatum=2020-01-27 ChargeEnd="2020-01-27 08:22:11" 1580108943000000000
azo,ChargeID=428569,RunID=51-000022,WorkCtr=0551,Shift_ID=2020-01-27.07,Shift=O,ShopfloorDatum=2020-01-27 RecipeName="Middenlaag B" 1580108943000000000
azo,ChargeID=428569,RunID=51-000022,WorkCtr=0551,Shift_ID=2020-01-27.07,Shift=O,ShopfloorDatum=2020-01-27 ArticleID="G10236" 1580108943000000000
azo,ChargeID=428569,RunID=51-000022,WorkCtr=0551,Shift_ID=2020-01-27.07,Shift=O,ShopfloorDatum=2020-01-27 ArticleDesc1="101395" 1580108943000000000" on target "http://localhost:8086/write?&db=afp".

PS C:\Users> $Metrics
Name Value


ChargeStart 2020-01-27 08:09:03
Recipe S41351v1/2
Weight_pv 0,499
Weight_sv 0,5
ChargeEnd 2020-01-27 08:22:11
RecipeName Middenlaag B
ArticleID G10236
ArticleDesc1 101395

PS C:\Users> $Tags

Name Value


ChargeID 428569
RunID 51-000022
WorkCtr 0551
Shift_ID 2020-01-27.07
Shift O
ShopfloorDatum 2020-01-27

Tag with single \ ends up with \\\\ and invalid tag format?

reading vmware guest disk space and returing free / used space along with tagging vm name and drive path

example drive path is C:\ being returned from vmware, but when calling Write-Influx verbose shows Path=C:\\ now and when invoke-restmethod is called its is now c:\\ and flags invalid tag format\nunamble to parse

i can kind of fudge it by adding a white space after the path, but then they all end up in influx as C:\\ and not C:\

Thanks

Username and Password for InfluxDB

We are using a username and password to connect to our InfluxDB. The function Write-Influx does not include options/parameters to parse username and password to the body part. Are you able to add this functionality?
Thank you
Torben

Write-Influx multiple Measures

Thank you for creating this. It helped me a lot in a pinch.

I spent a few days working on collecting my own metrics and reading write-influx several times over to understand how and why everything was set up the way it was, and one thing became really apparent as a missing feature. There isn't an ability to send more than one Measure to influx all in one request (mostly impacting TCP since it's so much slower). If you are storing all of your data in one Measure then there's no issue, but I doubt that's the case for many people. And since Influx supports accepting more than one measure in a single TCP packet, this certainly seems do-able.

I was wondering if this is something you've ever looked at or worked on? I was about to start on a PR for it when someone convinced me that I better check with the author first to see if this is something he would even commit.

Implementation
I was thinking of adding a function like 'Append-InfluxQueue' (or Add-...) which appends data onto a list. Basically all of the params like InputObject, Measure, Metrics, and Tags would be moved from Write-Influx onto Append-InfluxQueue and Write-Influx would become a simple writer (also looping through the list turning it into text). The same is true for UDP as well of course.

Thoughts on this?

P.S. Ever considered building in some windows metrics collectors?

Influx is seemingly trying to convert an object type that already exists

I'm writing a fairly straight forward powershell script for getting the dhcp leases from my pihole instance and displaying them for Grafana.

#!/usr/bin/pwsh
$Leases = (ssh -l user pihole "cat /etc/pihole/dhcp.leases")

$metrics = Foreach ($obj in $Leases) {
    [hashtable]@{
        $obj.Split(" ")[3] = $obj.Split(" ")[2]
    }
}

$InfluxParams = @{
    Measure = 'pihole_dhcp_leases'
    Metrics = $metrics
    Database = 'MyDB'
    Server   = 'http://<influxdb.example.com>:8086'
    Verbose = $true
    Credential = (Get-Credential)
}

Write-Influx @InfluxParams

As an example output, $leases comes in the following format:

1536231722 11:11:11:11:11:11 192.168.x.x host01 11:11:11:11:11:11:11
1536205906 11:11:11:11:11:11 192.168.x.x host02 11:11:11:11:11:11:11

I see where Metrics is properly typed:

$metrics

Name                           Value
----                           -----
host01                     192.168.x.x
host02                     192.168.x.x

$metrics | Get-Member

    TypeName: System.Collections.Hashtable

However, Write-Influx errors at:

Write-Influx : Cannot process argument transformation on parameter 'Metrics'. Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Collections.Hashtable".

Is there any explicit typecasting that might interfere here?

Empty Metric gets (wrong) value

Hello Mark,

Many thanks for your development of the InfluxDb module. It is the best by far and makes working with Influx from scripts a lot easier.

I ran into this behaviour that I would like to verify because it is different from the intention.
Expected -ExcludeEmptymetric to not pass Metric TestValue but in my test it received the value of 38 (Same as Metric 'Mem')

Thanks,
GWS65

*************** Test *******************

$Tags = @{
Server2 = 'ServerTag2'
Location = 'Anywhere'
}

$Metrics = @{
CPU = 44
Mem = 38
TestValue = $null
}

$InfluxLine = ConvertTo-InfluxLineString -Measure WebServer -Tags $Tags -Metrics $Metrics -ExcludeEmptyMetric

Escaping '\' not needed & missing whitespace escaping in 'FieldTextValue'

Hi
I forked your really cool project and noticed following in your private PowerShell-function "Influx/Private/Out-InfluxEscapeString.ps1":

  • Escaping of '' is not needed (InfluxLine protocol docs: line protocol does not require users to escape the backslash character \ but will not complai)
  • Missing whitespace escaping in 'FieldTextValue'

your code in "Influx/Private/Out-InfluxEscapeString.ps1":

"Measurement" { $String -Replace '(\s|,|\\)', '\$1' }
"FieldTextValue" { $String -Replace '("|\\)', '\$1' }
"Other" { $String -Replace '(\s|=|,|\\|")', '\$1' }
default { $String -Replace '(\s|=|,|\\|")', '\$1' }

my changes in "Influx/Private/Out-InfluxEscapeString.ps1":

"Measurement" { $String -Replace '(\s|,)', '\$1' }
"FieldTextValue" { $String -Replace '(\s|")', '\$1' }
"Other" { $String -Replace '(\s|=|,|")', '\$1' }
default { $String -Replace '(\s|=|,|")', '\$1' }

-> More informations about the changes.

PS: Excuse me for not making an pull request, but nevertheless I hope it helps.

Improve debug possibilities in write-influx function

Hello

on my last usages i got "random" errors in the result formatting. When sending thousands of lines it's hard to see which line got a return HTTP error 400.

It could be useful to get a error debug possibility, like write errors in a file (the data sent and the error code sent back)
like a try and catch and send the data to a variable we can then write in a log file when needed.

Tonic8
(sorry as i'm a newbie on GitHub i don't know how to set this as "enhancement" and not an issue)

Batch inserts

It appears that this module only lets you submit a single data point at a time. Is there a method to insert multiple points per request?

Perhaps accept an object in this format : @{ Measure = ''; Tags = @{}; Metrics = @{}; TimeStamp = '' }

InfluxDB 2 support

Any plans or ETA for supporting InfluxDB 2 also? It is in only minor changes to the REST query for posting afaik.

Force INT / Strings

Is there a way to force the format of sent requests to be an Integer or a String? Im having some issues when some of my values are a mixed of INT / String's like this when doing a ForEach loop.

The JobName Var sometimes has values that start like 00250-Name. I I know with influx I can do an "I" or a double quote

$JobName =$_.BackupJobName
$Date =$_.Date
$Name =$_.Name
$Status =$_.Status

Write-Influx -Measure backup_info -Tags @{VMname=$Name} -Metrics @{Date=$Date;Status=$Status;JobName=$JobName} -Database it-stats -Server http://pap-graf01:8086 -Verbose

Write-Influx issue with first parameter only work through Pipe and not as a parameter

Hello

  • we cannot use the command line
    write-influx -inputObject $data -Database "Data" -Server "Server"

  • the command cannot even be used in splatting

$splat = @{
  InputObject = $Data
  Database = "Data"
  Server = "Server"
}
write-influx @splat
  • We can mix the concepts but the InputObject must be passed by the Pipe
$splat = @{
  Database = "Data"
  Server = "Server"
}
$Data |write-influx @splat

or

$Data | write-influx -Database "Data" - Server "Server"

When doing that the error message is:

Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Collections.Hashtable".
At c:\test\_modules\Influx\Public\Write-Influx.ps1:101 char:13
+                  $Metrics = $InputObject.Metrics
+                  ~~~~~~~~~~~~~~~~~~~~~
       + CategoryInfo             : Invalid Argument: (:) [], RuntimeException
       + FullyQualifiedErrorId : ConvertToFinalInvalidCastException

Thanks
Tonic8

Module try to write line with empty tag value

Hello

i finally catch the issue i saw with some data, here the data sent
xdsession,desktopgroupename=spain-prod,PowerState=On,launchedViaHostName=,hypervizor=vcenter1 LogonInProgress="False"

"launchedViaHostname=" had not value, and all the line is not written to the DB.

it should be usefull to not send the empty tag.
REgards
Tonic8

Doesn't seem to work with current version of TFS Module

I have installed your module as well as the TFS Module which you are consuming to make the TFS related calls.

It seems that the underlying TFS Module relies upon instantiating the following global variable before importing the module (either implicitly or explicitly):

$global:tfs=@{
    root_url='https://sometfsserver.com'
    collection='CollectionName'
    project='ProjectName'
}

Per your guide at http://wragg.io/windows-based-grafana-analytics-platform-via-influxdb-and-powershell/ you show calling

Get-TFSBuildMetric -TFSRootURL 'https://mytfsurl.local/tfs' -TFSCollection somecollection -TFSProject someproject

However that call does not return as expected since nowhere in the Get-TFSBuildMetric code do you create/set the $global:tfs variable based upon the parameters passed to Get-TFSBuildMetric. Am I not understanding how this should work? Or is this broken due to changes in the underlying TFS Module? If I have to manually create the global variables, what then is the point of the Parameters being passed to Get-TFSBuildMetric?

Question? DataType of Object in InflxDB

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

Wrong Position Value parameter in Write-Influx function

Hello

$InputObject and Measure got the same position number,

        [Parameter(ParameterSetName = 'MetricObject', ValueFromPipeline = $True, Position = 0)]
        [PSTypeName('Metric')]
        $InputObject,

        [Parameter(ParameterSetName = 'Measure', Mandatory = $true, Position = 0)]
        [string]
        $Measure,

for example we should have for Measure "Position = 1"

Regards
Tonic8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.