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
217 stars 71 forks source link

Sends data in UTC #16

Closed dchang0 closed 9 years ago

dchang0 commented 10 years ago

For whatever reason, Graphite-Powershell was sending metrics with the Unix timestamp at UTC regardless of whatever timezone I had set in the XML config file. In our case, both our Graphite server and the sending server are in PDT as of this writing. I could shift the Unix timestamp around a bit by changing the timezone to one that is purposefully wrong; in other words, it was possible to get the graphs to end up at the right time by purposefully setting the XML config to Azores Standard Time (even though we are in Pacific Daylight Time now).

Anyway, after doing some research, I found that the cause is that Get-Date -uformat %s produces the Unix timestamp (seconds since the epoch) relative to UTC.

The fix was to modify this code:

Get-Date $DateTime -UFormat %s

and change it to:

Get-Date (Get-Date $DateTime).ToUniversalTime() -UFormat %s

I did this in two places in the script, and it seems to work. However, I have by no means exhaustively tested this in all the modes the script can be run. It just works for me when using the script in its simplest, default mode, which I understand is the bulk send.

Matt, I figure you'll want to test and bless my suggested change before closing this issue.

MattHodge commented 9 years ago

@dchang0 this should now be fixed as of c4a439ed8c0cd7a3660b4e0d6ed280db43e84d71

The timezone is stripped in the script and data is always sent as UTC to the Graphite server.

dchang0 commented 9 years ago

Awesome! Thanks, Matt!

I’ll replace the version I had been using with yours and resubmit if any problems occur.

On Nov 10, 2014, at 4:19 PM, Matthew Hodgkins notifications@github.com wrote:

@dchang0 https://github.com/dchang0 this should now be fixed as of c4a439e https://github.com/MattHodge/Graphite-PowerShell-Functions/commit/c4a439ed8c0cd7a3660b4e0d6ed280db43e84d71 The timezone is stripped in the script and data is always sent as UTC to the Graphite server.

— Reply to this email directly or view it on GitHub https://github.com/MattHodge/Graphite-PowerShell-Functions/issues/16#issuecomment-62481255.