Skip to content
This repository was archived by the owner on May 30, 2019. It is now read-only.

Commit 793fc9f

Browse files
committed
fixes #26
1 parent 6b53a4d commit 793fc9f

File tree

5 files changed

+5
-109
lines changed

5 files changed

+5
-109
lines changed

Functions/Internal.ps1

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,3 @@
1-
function Convert-TimeZone
2-
{
3-
<#
4-
.Synopsis
5-
Coverts from a given time zone to the specified time zone.
6-
7-
.Description
8-
Coverts from a given time zone to the specified time zone.
9-
10-
.Parameter DateTime
11-
A DateTime object will be converted to the new time zone.
12-
13-
.Parameter ToTimeZone
14-
The name of the target time zone you wish to convert to. You can get the names by using the -ListTimeZones parameter.
15-
16-
.Parameter ListTimeZones
17-
Lists all the time zones that can be used.
18-
19-
.Example
20-
Convert-TimeZone -ListTimeZones
21-
22-
Id : Dateline Standard Time
23-
DisplayName : (UTC-12:00) International Date Line West
24-
StandardName : Dateline Standard Time
25-
DaylightName : Dateline Daylight Time
26-
BaseUtcOffset : -12:00:00
27-
SupportsDaylightSavingTime : False
28-
29-
Id : UTC-11
30-
DisplayName : (UTC-11:00) Coordinated Universal Time-11
31-
StandardName : UTC-11
32-
DaylightName : UTC-11
33-
BaseUtcOffset : -11:00:00
34-
SupportsDaylightSavingTime : False
35-
36-
Lists available time zones to convert to.
37-
38-
.Example
39-
Convert-TimeZone -DateTime (Get-Date) -ToTimeZone UTC
40-
41-
Converts current time to UTC time.
42-
43-
.Notes
44-
NAME: Convert-TimeZone
45-
AUTHOR: Matthew Hodgkins
46-
WEBSITE: http://www.hodgkins.net.au
47-
48-
#>
49-
50-
param
51-
(
52-
[CmdletBinding(DefaultParametersetName = 'Convert Time Zone')]
53-
54-
[Parameter(Mandatory = $true,
55-
ParameterSetName = 'Convert Time Zone')]
56-
[ValidateNotNull()]
57-
[ValidateNotNullOrEmpty()]
58-
[datetime]$DateTime,
59-
60-
[Parameter(Mandatory = $true,
61-
ParameterSetName = 'Convert Time Zone')]
62-
[ValidateNotNull()]
63-
[ValidateNotNullOrEmpty()]
64-
[string]$ToTimeZone,
65-
66-
[Parameter(Mandatory = $false,
67-
ParameterSetName = 'List Time Zones')]
68-
[switch]$ListTimeZones
69-
)
70-
71-
# Loading dll for Windows 2003 R2
72-
[void][System.Reflection.Assembly]::LoadWithPartialName('System.Core')
73-
74-
# List TimeZones for the user
75-
if ($ListTimeZones)
76-
{
77-
[System.TimeZoneInfo]::GetSystemTimeZones()
78-
return
79-
}
80-
81-
# Run the Function
82-
else
83-
{
84-
$TimeZoneObject = [System.TimeZoneInfo]::FindSystemTimeZoneById($ToTimeZone)
85-
$TargetZoneTime = [System.TimeZoneInfo]::ConvertTime($DateTime, $TimeZoneObject)
86-
$OutObject = New-Object -TypeName PSObject -Property @{
87-
LocalTime = $DateTime
88-
LocalTimeZone = $(([System.TimeZoneInfo]::LOCAL).id)
89-
TargetTime = $TargetZoneTime
90-
TargetTimeZone = $($TimeZoneObject.id)
91-
}
92-
93-
Write-Output $OutObject
94-
}
95-
}
96-
971
Function Import-XMLConfig
982
{
993
<#
@@ -135,9 +39,6 @@ Function Import-XMLConfig
13539
#Get Metric Send Interval From Config
13640
[int]$Config.MetricSendIntervalSeconds = $xmlfile.Configuration.Graphite.MetricSendIntervalSeconds
13741

138-
# Get the Timezone Of the Graphite Server
139-
$Config.TimeZoneOfGraphiteServer = $xmlfile.Configuration.Graphite.TimeZoneOfGraphiteServer
140-
14142
# Convert Value in Configuration File to Bool for Sending via UDP
14243
[bool]$Config.SendUsingUDP = [System.Convert]::ToBoolean($xmlfile.Configuration.Graphite.SendUsingUDP)
14344

Functions/Send-BulkGraphiteMetrics.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function Send-BulkGraphiteMetrics
7070
if ($DateTime)
7171
{
7272
# Convert to a Unix time without any rounding
73-
$UnixTime = (Get-Date $DateTime -UFormat %s) -Replace ("[,\.]\d*", "")
73+
$UnixTime = [uint64]$DateTime.ToUniversalTime()
7474
}
7575

7676
# Create Send-To-Graphite Metric

Functions/Send-GraphiteMetric.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function Send-GraphiteMetric
7777
if ($DateTime)
7878
{
7979
# Convert to a Unix time without any rounding
80-
$UnixTime = (Get-Date $DateTime -UFormat %s) -Replace ("[,\.]\d*", "")
80+
$UnixTime = [uint64]$DateTime.ToUniversalTime()
8181
}
8282

8383
# Create Send-To-Graphite Metric

Functions/Start-StatsToGraphite.ps1

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,10 @@ Function Start-StatsToGraphite
106106
# Used to track execution time
107107
$iterationStopWatch = [System.Diagnostics.Stopwatch]::StartNew()
108108

109-
# Convert To The TimeZone of the Graphite Server
110-
$convertedTime = Convert-TimeZone -DateTime (Get-Date -Format s) -ToTimeZone $Config.TimeZoneOfGraphiteServer
111-
112-
# Get the TargetTime Part of the Script
113-
$convertedTime = $convertedTime.TargetTime
109+
$nowUtc = [datetime]::UtcNow
114110

115111
# Round Time to Nearest Time Period
116-
$convertedTime = $convertedTime.AddSeconds(- ($convertedTime.Second % $Config.MetricSendIntervalSeconds))
112+
$nowUtc = $nowUtc.AddSeconds(- ($nowUtc.Second % $Config.MetricSendIntervalSeconds))
117113

118114
$metricsToSend = @{}
119115

@@ -218,7 +214,7 @@ Function Start-StatsToGraphite
218214
"CarbonServer" = $Config.CarbonServer
219215
"CarbonServerPort" = $Config.CarbonServerPort
220216
"Metrics" = $metricsToSend
221-
"DateTime" = $convertedTime
217+
"DateTime" = $nowUtc
222218
"UDP" = $Config.SendUsingUDP
223219
"Verbose" = $Config.ShowOutput
224220
"TestMode" = $TestMode

StatsToGraphiteConfig.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<CarbonServerPort>2003</CarbonServerPort>
66
<MetricPath>datacenter1.servers</MetricPath>
77
<MetricSendIntervalSeconds>5</MetricSendIntervalSeconds>
8-
<TimeZoneOfGraphiteServer>UTC</TimeZoneOfGraphiteServer>
98
<SendUsingUDP>False</SendUsingUDP>
109
</Graphite>
1110
<PerformanceCounters>

0 commit comments

Comments
 (0)