MattHodge / Graphite-PowerShell-Functions

A group of PowerShell functions that allow you to send Windows Performance counters to a Graphite Server, all configurable from a simple XML file.
https://hodgkins.io/using-powershell-to-send-metrics-graphite
GNU General Public License v3.0
218 stars 71 forks source link

Unix time too long when sending to influxDB #34

Closed Rici11 closed 9 years ago

Rici11 commented 9 years ago

I've noticed that the date that gets sent is 15 characters long, for example: 141882399527883

When sending to InfluxDB this results in an error such as this: GraphiteServer:%!(EXTRA *strconv.NumError=strconv.ParseUint: parsing "141882399527883": value out of range).

A correct unix time would normally be 10 characters long, such as 1418823995 which in turn would result in: $ date --date='@1418823995' Wed Dec 17 13:46:35 UTC 2014

I'm guessing that you're adding microseconds or something to the output, in that case the number should be decimal such as:

$ date --date='@1418823995.27883' Wed Dec 17 13:46:35 UTC 2014

Do we really need microseconds in the output date? Any ideas on how to change the date to make it epoch time accurate to the second or decimal and thus allow compatibility with the InfluxDB storage engine?

Thanks!

Steps to reproduce:

  1. Enable input_graphite to InfluxDB by changing this part in /opt/influxdb/shared/config.toml

    Configure the graphite api

    [input_plugins.graphite] enabled = true port = 2003 database = "graphite_db"

  2. Direct Graphite-PowerShell metrics to InfluxDB
  3. tail -f /opt/influxdb/shared/log.txt
bonobo78 commented 9 years ago

reproduced with same scenario.

parsing "14192584153982": value out of range

edit: temporary solve this issue by dividing the value of the timestamp by 100000 before sending it.

enricnes commented 9 years ago

For some reason, in Send-BulkGraphiteMetrics.ps1, you need to add ".ToString()" to this statement: [uint64]$UnixTime = (Get-Date -Date $utcDate -UFormat %s) after $utcDate. It would be: [uint64]$UnixTime = (Get-Date -Date $utcDate.ToString() -UFormat %s)

We also commented this section: [Parameter(Mandatory = $true, ParameterSetName = 'Epoch / Unix Time')] [ValidateRange(1, 99999999999999)] [string]$UnixTime,

MattHodge commented 9 years ago

Can you all please try the following and let me know if you have success:

  1. Make sure you are running the latest version (v1.2.0)
  2. Open Send-BlukGraphiteMetrics.ps1 in text editor
  3. Change line 75

from: [uint64]$UnixTime = (Get-Date -Date $utcDate -UFormat %s)

to: [int]$UnixTime = [math]::Round((Get-Date -Date $utcDate -UFormat %s))

If you have success please let me know and I will release this with some InfluxDB documentation.

marconfus commented 9 years ago

The problem is that on some locales Get-Date returns a string with a "," instead of a "." as decimal point (in german for example). Make a string replace "," to "." and it works.

dillten commented 9 years ago

Based on this, seems like the most invariant fix to this would be: [uint64]$UnixTime = [double]::Parse((Get-Date -Date $utcDate -UFormat %s))

toni-moreno commented 9 years ago

Hi. We have the same issue on sending data to graphite.

There is any official fix for that ?

Lot of thanks!

tbolon commented 9 years ago

I can confirm that it caused errors too in our case (french regional settings on our server).

Graphite was reporting errors:

23/02/2015 14:40:28 :: Error writing to /opt/graphite/storage/whisper/local/internal/xxx/sqlserver/locks/database/averagewaittime/ms.wsp
23/02/2015 14:40:28 :: Unhandled Error
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/threadpool.py", line 207, in _worker
    result = context.call(ctx, function, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
  File "/opt/graphite/lib/carbon/writer.py", line 158, in writeForever
    writeCachedDataPoints()
--- <exception caught here> ---
  File "/opt/graphite/lib/carbon/writer.py", line 137, in writeCachedDataPoints
    whisper.update_many(dbFilePath, datapoints)
  File "/usr/local/lib/python2.7/dist-packages/whisper.py", line 577, in update_many
    return file_update_many(fh, points)
  File "/usr/local/lib/python2.7/dist-packages/whisper.py", line 611, in file_update_many
    __archive_update_many(fh,header,currentArchive,currentPoints)
  File "/usr/local/lib/python2.7/dist-packages/whisper.py", line 635, in __archive_update_many
    currentString += struct.pack(pointFormat,interval,value)
struct.error: 'L' format requires 0 <= number <= 4294967295

We have used the code suggested by @dillten

rgunst commented 9 years ago

Same problem here. For me the suggestion from @dillten worked.

MattHodge commented 9 years ago

Thanks @dillten, I will implement this and release a new version.

MattHodge commented 9 years ago

Fixed in Graphite-PowerShell v1.2.1.

Thanks for reporting the issue! Thanks @dillten for the fix.

MattHodge commented 9 years ago

v1.2.1 had a bug, please grab Graphite-PowerShell v1.2.2 instead.