forked from MultiPoolMiner/MultiPoolMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportStatus.ps1
64 lines (54 loc) · 2.92 KB
/
ReportStatus.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
using module .\Include.psm1
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[String]$APIUrl
)
Write-Log "Miner status reporting process started. "
Do {
if ($Config = Invoke-WebRequest -Uri "$($APIUrl)/config" -Timeout 5 -ErrorAction SilentlyContinue | ConvertFrom-Json) {
$RunningMiners = [Array](Invoke-WebRequest -Uri "$($APIUrl)/runningminers" -Timeout 5 -ErrorAction SilentlyContinue | ConvertFrom-Json)
if ($Config.ReportStatusInterval -and $Config.MinerStatusKey -and $RunningMiners.Count) {
Write-Log "Pinging monitoring server. Your miner status key is: $($Config.MinerStatusKey). "
$Profit = ($RunningMiners | Measure-Object Profit -Sum).Sum | ConvertTo-Json
# Format the miner values for reporting. Set relative path so the server doesn't store anything personal (like your system username, if running from somewhere in your profile)
$Minerreport = ConvertTo-Json @(
$RunningMiners | Foreach-Object {
# Create a custom object to convert to json. Type, Pool, CurrentSpeed and EstimatedSpeed are all forced to be arrays, since they sometimes have multiple values.
[PSCustomObject]@{
Name = $_.Name
Path = Resolve-Path -Relative $_.Path
Type = @($_.DeviceName)
Active = "{0:dd} Days {0:hh} Hours {0:mm} Minutes" -f ((Get-Date).ToUniversalTime() - $_.BeginTime)
Algorithm = @($_.Algorithm)
Pool = @($_.Pool)
CurrentSpeed = @($_.Speed_Live)
EstimatedSpeed = @($_.Speed)
PID = @($_.ProcessID)
'BTC/day' = $_.Profit
}
}
)
try {
$Response = Invoke-RestMethod -Uri $Config.MinerStatusURL -Method Post -Body @{address = $($Config.MinerStatusKey); workername = $Config.WorkerName; miners = $Minerreport; profit = $Profit} -UseBasicParsing -TimeoutSec 10 -ErrorAction Stop
if ($Response -eq "success") {
Write-Log "Miner Status ($($Config.MinerStatusURL)): $Response"
}
else {
Write-Log -Level Warn "Miner Status ($($Config.MinerStatusURL)): $Response"
}
}
catch {
Write-Log -Level Warn "Miner Status ($($Config.MinerStatusURL)) has failed. "
}
Start-Sleep (30, $Config.ReportStatusInterval | Measure-Object -Maximum).Maximum
}
else {Start-Sleep 5}
}
} While ($Config)
if ($Config) {
Write-Log "Miner status reporting process stopped. "
}
else {
Write-Log -Level Warn "Miner status reporting process exited due to missing config information. API down??? "
}