-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtibber-price-publish.ps1
79 lines (71 loc) · 2.27 KB
/
tibber-price-publish.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
[CmdletBinding(DefaultParameterSetName = 'Tomorrow')]
param (
[string] $Path = '.',
[switch] $SkipPublish
)
# Import required modules
Import-Module -Name PSGraphite -Force -PassThru
Import-Module -Name $PSScriptRoot\tibber-pulse.psd1 -Force -PassThru
# Set log verbosity
$dbgpref = $global:DebugPreference
$vrbpref = $global:VerbosePreference
$global:DebugPreference = $DebugPreference
$global:VerbosePreference = $VerbosePreference
$priceInfo = Get-Content -Raw -Path "$Path\tibber-price.json" | ConvertFrom-Json
$priceInfoMetrics = @()
$priceInfo | ForEach-Object {
if ($_.price) {
$priceInfoMetrics += @(
@{
name = "$env:GRAPHITE_METRICS_PREFIX.hourly.price"
value = $_.price
time = $_.time
}
@{
name = "$env:GRAPHITE_METRICS_PREFIX.hourly.priceLevel"
value = $_.priceLevel
time = $_.time
}
@{
name = "$env:GRAPHITE_METRICS_PREFIX.hourly.priceScore"
value = $_.priceScore
time = $_.time
}
@{
name = "$env:GRAPHITE_METRICS_PREFIX.hourly.priceAvg"
value = $_.priceAvg
time = $_.time
}
)
}
if ($_.priceAvgToday) {
$priceInfoMetrics += @(
@{
name = "$env:GRAPHITE_METRICS_PREFIX.daily.priceAvg"
value = $_.priceAvgToday
time = $_.time
interval = 86400 # 1 day
}
)
}
if ($_.priceAvgTomorrow) {
$priceInfoMetrics += @(
@{
name = "$env:GRAPHITE_METRICS_PREFIX.daily.priceAvg"
value = $_.priceAvgTomorrow
time = $_.time
interval = 86400 # 1 day
}
)
}
}
$priceInfoMetrics = Get-GraphiteMetric -Metrics $priceInfoMetrics -IntervalInSeconds 3600 # 1 hour
if (-Not $SkipPublish.IsPresent) {
# Send metrics to Graphite
Send-Metrics $priceInfoMetrics
} else {
$priceInfoMetrics | Out-File -FilePath "$PSScriptRoot\tibber-price-publish.json" -Force
}
# Reset log verbosity
$global:DebugPreference = $dbgpref
$global:VerbosePreference = $vrbpref