-
Notifications
You must be signed in to change notification settings - Fork 0
/
JJs_HashMonitor_mutley.ps1
3113 lines (2678 loc) · 104 KB
/
JJs_HashMonitor_mutley.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#requires -Version 5.0 -Modules Microsoft.PowerShell.Diagnostics, PnpDevice
Clear-Host
$startattempt = 0
Function Run-Miner {
do {
$ver = '4.4.12'
$debug = $false
#$verbosePreferenc='Continue'
$script:VerbosePreferenceDefault = 'silentlyContinue'
$ErrorActionPreference = 'silentlyContinue'
#$ErrorActionPreference = 'inquire'
Push-Location -Path $PSScriptRoot
$Host.UI.RawUI.WindowTitle = "JJ's XMR-STAK HashRate Monitor and Restart Tool, Reworked by Mutl3y v$ver"
$Host.UI.RawUI.BackgroundColor = 'Black'
######################################################################################
############# STATIC Variables - DO NOT CHANGE ##########################
$ScriptDir = (Get-Item -Path '.\' -Verbose ).FullName
$ScriptName = $MyInvocation.MyCommand.Name
$script:runDays = $null
$script:runHours = $null
$script:runMinutes = $null
$script:UpTime = $null
$script:web = New-Object -TypeName System.Net.WebClient
$script:ConnectedPool = $null
$script:TimeShares = $null
$supported_cards = @('Radeon Vega Frontier Edition', 'Radeon RX 570 Series', 'Radeon RX 580 Series', 'Radeon RX Vega', 'Radeon (TM) RX 470 Graphics', 'Radeon (TM) RX 480 Graphics')
#Initilisation values, Needed for metrics
$startTestHash = 0
$script:rTarget = 0
$script:maxhash = 0
$script:currHash = 0
$script:minhashrate = $null
$script:sharepercent = 0
$script:currDiff = 0
$script:TotalShares = 0
$script:GoodShares = 0
$script:STAKisup = $false
$script:threadArray = @()
$script:nanopoolLastUpdate = 0
$script:PoolsList = @{}
$script:pools = @{}
$script:lastRoomTemp = @{}
$script:timeDrift = 999999
$script:validSensorTime = $null
$script:profitCheckDateTime = (get-date )
$poolsdottext = "pools.txt"
$poolsfile = 'pools.json'
$script:displayOutput2 = [ ordered ]@{}
$script:balance = $NUL
$script:btcprice = $NUL
$script:coins = $NUL
$script:dollars = $NUL
$script:avghash1hr = $NUL
$script:bestcoins = {}
$script:nextSlackPeriod = (get-date )
$stakIP = '127.0.0.1' # IP or hostname of the machine running STAK (ALWAYS LOCAL) Remote start/restart of the miner is UNSUPPORTED.
$runTime = 0
########## END STATIC Variables - MAKE NO CHANGES ABOVE THIS LINE #######
#########################################################################
# Set the REQUIRED variables for your Mining Configuration #
#########################################################################
$defaults = "
#
# $ver Default Configuration file
# Log Directory
logdir = logs
# Logfile
Logfile = HashMonitor
# STAK folder, Seperation for neatness, You should set this ****
STAKdir = xmr-stak
# The miner. Expects to be in STAKdir folder
STAKexe = XMR-STAK.EXE
# STAK arguments. Not required, REMARK out if not needed
STAKcmdline = --noNVIDIA
# Max attempts at starting STAK before rebooting, only triggers where it hangs on startup, 0 to disable
STAKMaxStartAttempts = 3
# !! DON'T FORGET TO ENABLE THE WEBSERVER IN YOUR CONFIG FILE !!
# Port STAK is listening on
STAKPort = 420
# STAK retry timer, Retry time used in low hash rate if under minimum hash rate,
# This can allow recovery before a reset is tried
retrytimer = 10
# Sleep time in between checks, directly affects grafana metrics
5
# Height of console, Max 75
consoleHeight = 30
# Width of console, Max 250
consoleWidth = 100
#########################################################################
# Read this section carefully or you may end up overclocking your video
# card when you don't want to!! YOU HAVE BEEN WARNED
#########################################################################
##### Start Video Card Management Tools Definitions
# These will be executed in order prior to the miner
# Create as many as needed
#### Vid Tool 1
_vidTool = OverdriveNTool.exe -consoleonly -r1 -p1XMR
#_vidTool = OverdriveNTool.exe -consoleonly -r2 -r3 -p2580_low -p3580_low
# Delete or REMARK if you don't want use it
#### Vid Tool 2
#_vidTool = nvidiasetp0state.exe
# Delete or REMARK if you don't want use it
#### Vid Tool 3
#_vidTool = nvidiaInspector.exe -setBaseClockOffset:0,0,65 -setMemoryClockOffset:0,0,495 -setOverVoltage:0,0 -setPowerTarget:0,110 -setTempTarget:0,0,79
# Delete or REMARK if you don't want use it
#########################################################################
# Set drop trigger and startup timeout
#########################################################################
# This is the drop in total hash rate where we
# trigger a restart (Starting HASHRATE - hdiff)
hdiff = 300
# How many seconds to wait for a response from a running instance of XMR-STAK
runningSTAKtimeout = 2
# How long to wait for STAK to return a hashrate before we fail out and
# restart. There is no limiter on the number of restarts.
timeout = 60
#
STAKmin = 60
# How to wait before checking for low rates, Allows a low speed check during settling
# must be greater than the time it takes all your threads to start
minlowratecheck = 20
# Enable Vega card resets, Includes RX580's, Vega's, Vega FE
CardResetEnabled = True
# Force a card reset at startup
ResetCardOnStartup = True
# How long to wait for the hashrate to stabilize.
STAKstable = 60
# Minimum hashrate
minhashrate = 1850
# Reboot timeout
rebootTimeout = 10
# Reboot enabled on driver error
rebootEnabled = True
# enable grafana - Only influx udp supported, set default database in influx config file to 'xmrSTAK'
grafanaEnabled = True
# grafana utp url
grafanaUtpIP = 127.0.0.1
# grafana utp url
grafanaUtpPort = 8089
# Internet conection wait time
internetWaitTime = 600
# Notifications
# Email
# smsAddress='YOUR SMS eMail address' # Set YOUR SMS eMail address
# gUsername='YOUR Gmail eMail address' # Set YOUR Gmail eMail address
# gPassword='YOUR Gmail eMail password' # Set YOUR Gmail eMail password
# Slack
# Put your WebHooks URL here, Default is for this codes Slack space, Usefull if you can allow it to post at least once so I get to see it used out in the wild, your welcome to join and discuss
slackUrl=https://hooks.slack.com/services/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
# slackUsername= Defaults to computer name
# slackChannel='#Hashmonitor' # Channel to post message. Can be in the format @username or #channel
# slackEmoji=':clap:' # Example: :clap:. (Not Mandatory). (if slackEmoji is set, slackIconUrl will not be used)
# Slack uses the standard emoji codes found at Emoji Cheat Sheet (https://www.webpagefx.com/tools/emoji-cheat-sheet/)
# slackIconUrl='' # Url for an icon to use. (Not Mandatory)
# Periodically send script display output to Slack
slackPeriodicReporting = True
# How often to send display to slack, minimum 5 minutes,
slackPeriodicMinutes = 30
# Verbosoty level for Slack notification,
# 0 to disable
# 1 -> 5 Increasing verbosity
alertLevel = 1
# How long to pause between device resets
devwait = 3
# If a device takes longer than this to disable its concidered in error and a reboot is called
maxDeviceResetTime = 3
# expectedCards, How many cards should the script see if everythings OK, Do not exceed actual card count
# Updates on the fly if it finds other cards, this is used as an aditonal trigger for restarting
installedCards = 1
# enable nanopool stats if those pools are used, Will auto disable if mining another pool
enableNanopool = True
# Refresh rate for Nanopool stats, Please be sensible or you will get blocked,Minimun 60 seconds
poolStatRefreshRate = 60
# Estimated pool profitability, minute, day, hour, week, month, Default is day
coinStats = day
# How often to check the order of your pools for profitability, Minimum is 60 seconds but it operation its never going to be that low
# Leaving this at 60 for now during testing expect the default here should be about 20 minutes, It will only be checked during restarts for now
proftStatRefreshTime = 60
# Enable profit switching, Please read the ProfitReadme.md before enabling this
profitSwitching = False
# Enable profit checking whilst mining
profitLiveCheckingEnabled = True
# Kill STAK to switch coins
profitKillRunningStak = False
# Obey reset on startup setting during profit switching,
# If your miner is happy when profit switching then you don't need to reset your cards
ProfitResetCardOnRestart = false
# Minimum extra profit before switching coins
profitSwitchPercentage = 5
# Minimum uptime before concidering switching coins
ProfitCheckMinutes = 30
# Customise algorithm conversion factors
cryptonightheavy_factor = 0.6
cryptonightv2_factor = 0.95
cryptonightfast_factor = 1.8
cryptonightlite_factor = 2.5
# Enable temp reporting and control functions
#TempWatch = True
# Main sensor temp file, Works with TEMPer USB devices, Full path
#sensorDataFile = c:\sensor-data\TEMPerX1.csv
# Max room Temp, if you use a TEMPer usb temp sensor, This is when we stop mining
#TEMPerMaxTemp = 30
# Temp has to drop under max by this much before we start mining again
#TEMPerMinDiff = 0.2
# TEMPer Valid Reading Time, Reading has to be within this time period to be concidered valid in case
# sensor stops responding, Set to huge amount if you do not wish to stop mining on app stop but be careful
#TEMPerValidMinutes = 2
# TEMPer sensor feed OuterTemp or InnerTemp
TEMPerSensorLocation = OuterTemp
# If its too hot do we kill STAK and disable gpu's
killStakOnMaxTemp = False
"
#########################################################################
# USER VARIABLES from preferences file #
#########################################################################
$Path = "$ScriptDir\hashmonitor.ini"
# Test for preferences file, create from defaults if missing
IF( ! (Test-Path -Path ($Path ) ) ) {
Write-Host 'Creating preferences file'
$defaults | Set-Content -Path $Path
Write-host -fore yellow "Please review settings in hashmonitor.ini before re-running,`nBe careful and undervolt your cards, dont overclock its not worth it"
#Exit
}
try {
$error.Clear()
$inifilevalues = $null
$inifilevalues = (Get-Content -Path $Path |
Where-Object {($_.Contains( '=' ) ) -notcontains (($_.Contains( 'vidTool' ) ) )} |
Out-String ) -replace '\\', '\\' |
ConvertFrom-StringData
}
catch {
write-host "Issue reading hashmonitor.ini `n $( $Error[0] )" -fore Red
(Get-Content -Path $Path |
Where-Object {($_.Contains( '=' ) ) -notcontains (($_.Contains( 'vidTool' ) ) )} |
Out-String ) -replace '\\', '\\'
start-sleep -s 120
#EXIT
}
if( $debug ) {
Write-Output -InputObject "Confirming input vars from $Path `n", $inifilevalues
Write-Verbose -Message 'Sleeping for 10 seconds' -Verbose
Start-Sleep -Seconds 10 -Verbose
}
# Log Directory
if( $inifilevalues.Logdir ) {
$Logdir = $inifilevalues.Logdir
}
else {
$Logdir = 'logs'
}
# Create folder for logfiles
$null = New-Item -ItemType directory -Path $logdir -Force
# Log File
if( $inifilevalues.Logfile ) {
$log = $inifilevalues.Logfile
}
else {
$Log = 'HashMonitor'
}
# Stak Folder
if( $inifilevalues.STAKdir ) {
$STAKfolder = $inifilevalues.STAKdir
}
else {
$STAKfolder = 'xmr-stak'
}
# Stak Executable
if( $inifilevalues.STAKexe ) {
$stakexe = $inifilevalues.STAKexe
}
else {
$stakexe = 'XMR-STAK.EXE'
}
# Stak STAKStartAttempts
if( $inifilevalues.STAKMaxStartAttempts ) {
$STAKMaxStartAttempts = $inifilevalues.STAKMaxStartAttempts
}
else {
$STAKMaxStartAttempts = 3
}
# Command Line
if( $inifilevalues.STAKcmdline ) {
$STAKcmdline = $inifilevalues.STAKcmdline
}
# Port STAK is listening on
if( $inifilevalues.STAKPort ) {
$STAKPort = [ int ]$inifilevalues.STAKPort
}
else {
$STAKPort = 420
}
# Error retry timer
if( $inifilevalues.retrytimer ) {
$script:retrytimer = [ int ]$inifilevalues.retrytimer
}
Else {
$script:retrytimer = 60
}
# refresh rate
if( $inifilevalues.sleeptime ) {
$sleeptime = [ int ]$inifilevalues.sleeptime
}
Else {
$sleeptime = 5
}
# Console Height
if( $inifilevalues.consoleHeight ) {
$consoleHeight = [ int ]$inifilevalues.consoleHeight
Write-Verbose -Message "Console Height, $consoleHeight"
if( $consoleHeight -gt 75 ) {
$consoleHeight = 75
Write-Host "Console Height, Default MAX used $consoleHeight"
}
}
Else {
$consoleHeight = 30
}
# Console Width
if( $inifilevalues.consoleWidth ) {
$consoleWidth = [ int ]$inifilevalues.consoleWidth
Write-Verbose -Message "Console Width, $consoleWidth"
if( $consoleWidth -gt 230 ) {
$consoleWidth = 230
Write-Host "Console Width, Default MAX used $consoleWidth"
}
}
Else {
$consoleWidth = 81
}
if( $inifilevalues.hdiff ) {
$hdiff = [ int ]$inifilevalues.hdiff
}
Else {
$hdiff = 300
}
if( $inifilevalues.runningSTAKtimeout ) {
$runningSTAKtimeout = [ int ]$inifilevalues.runningSTAKtimeout
}
Else {
$runningSTAKtimeout = 10
}
if( $inifilevalues.timeout ) {
$timeout = [ int ]$inifilevalues.timeout
}
Else {
$timeout = 60
}
if( $inifilevalues.devwait ) {
$devwait = [ int ]$inifilevalues.devwait
}
Else {
$devwait = 3
}
if( $inifilevalues.maxDeviceResetTime ) {
$maxDeviceResetTime = [ int ]$inifilevalues.maxDeviceResetTime
}
Else {
$maxDeviceResetTime = 1
}
if( $inifilevalues.STAKstable ) {
$STAKstable = [ int ]$inifilevalues.STAKstable
}
Else {
$STAKstable = 60
}
# Minimum hashrate befor resetting cards
if( $inifilevalues.minhashrate ) {
$script:minhashrate = [ int ]$inifilevalues.minhashrate
}
Else {
$script:minhashrate = 60
}
# Times to wait when reboot triggered
if( $inifilevalues.rebootTimeout ) {
$rebootTimeout = [ int ]$inifilevalues.rebootTimeout
}
Else {
$rebootTimeout = 30
}
# rebootEnabled
if( $inifilevalues.rebootEnabled ) {
$rebootEnabled = $inifilevalues.rebootEnabled
}
Else {
$rebootEnabled = 'False'
}
# minlowratecheck
if( $inifilevalues.minlowratecheck ) {
$minlowratecheck = $inifilevalues.minlowratecheck
}
Else {
$minlowratecheck = 30
}
# CardResetEnabled
if( $inifilevalues.CardResetEnabled ) {
$CardResetEnabled = $inifilevalues.CardResetEnabled
}
Else {
$CardResetEnabled = 'False'
}
# ResetCardOnStartup
if( $inifilevalues.ResetCardOnStartup ) {
$ResetCardOnStartup = $inifilevalues.ResetCardOnStartup
}
Else {
$ResetCardOnStartup = 'False'
}
# enable grafana
if( $inifilevalues.grafanaEnabled ) {
$grafanaEnabled = $inifilevalues.grafanaEnabled
}
Else {
$grafanaEnabled = 'True'
}
# grafana utp url
if( $inifilevalues.grafanaUtpIP ) {
$grafanaUtpIP = $inifilevalues.grafanaUtpIP
}
Else {
$grafanaUtpIP = '127.0.0.1'
}
# grafana utp url
if( $inifilevalues.grafanaUtpPort ) {
$grafanaUtpPort = $inifilevalues.grafanaUtpPort
}
Else {
$grafanaUtpPort = 8089
}
# internetWaitTime
if( $inifilevalues.internetWaitTime ) {
$internetWaitTime = $inifilevalues.internetWaitTime
}
Else {
$internetWaitTime = 600
}
# Notifications
# smsAddress='YOUR SMS eMail address' # Set YOUR SMS eMail address
if( $inifilevalues.smsAddress ) {
$smsAddress = $inifilevalues.smsAddress
}
# gUsername='YOUR Gmail eMail address' # Set YOUR Gmail eMail address
if( $inifilevalues.gUsername ) {
$gUsername = $inifilevalues.gUsername
}
# gPassword='YOUR Gmail eMail password' # Set YOUR Gmail eMail password
if( $inifilevalues.gPassword ) {
$gPassword = $inifilevalues.gPassword
}
If( $smsAddress -and $gUsername -and $gPassword ) {
$secpasswd = ConvertTo-SecureString $gPassword -AsPlainText -Force
$gCredentials = New-Object System.Management.Automation.PSCredential ($gUsername, $secpasswd )
}
# Slack
# slackUrl='https://hooks.slack.com/services/xxxxxx' #Put your WebHooks URL here
if( $inifilevalues.slackUrl ) {
$slackUrl = $inifilevalues.slackUrl
}
# slackUsername='JJsHashMonitor' # Username to send from.
if( $inifilevalues.slackUsername ) {
$slackUsername = $inifilevalues.slackUsername
}
Else {
$slackUsername = $env:COMPUTERNAME
}
# slackChannel='#channel' # Channel to post message. Can be in the format @username or #channel
if( $inifilevalues.slackChannel ) {
$slackChannel = $inifilevalues.slackChannel
}
Else {
$slackChannel = "Hashmonitor"
}
# slackEmoji=':clap:' # Example: :clap:. (Not Mandatory). (if $slackEmoji is set, $slackIconUrl will not be used)
if( $inifilevalues.slackEmoji ) {
$slackEmoji = $inifilevalues.slackEmoji
}
Else {
$slackEmoji = ':white_check_mark:'
}
# slackIconUrl='' # Url for an icon to use. (Not Mandatory)
if( $inifilevalues.slackIconUrl ) {
$slackIconUrl = $inifilevalues.slackIconUrl
}
if( $inifilevalues.slackPeriodicReporting ) {
if( $inifilevalues.slackPeriodicReporting -eq 'True' ) {
$slackPeriodicReporting = $true
}
else {
$slackPeriodicReporting = $false
}
$slackPeriodicReporting = $inifilevalues.slackPeriodicReporting
}
Else {
$slackPeriodicReporting = $false
}
if( $inifilevalues.slackPeriodicMinutes ) {
if( $inifilevalues.slackPeriodicMinutes -lt 30 ) {
$slackPeriodicMinutes = 30
}
else {
$slackPeriodicMinutes = $inifilevalues.slackPeriodicMinutes
}
}
else {$slackPeriodicMinutes = 30}
# alertLevel='' # Verbosity of notifications, Defaults to 1
if( $inifilevalues.alertLevel ) {
$alertLevel = $inifilevalues.alertLevel
}
else {
$alertLevel = 1
}
# enableNanopool= True # Verbosity of notifications, Defaults to 1
if( $inifilevalues.enableNanopool ) {
$script:enableNanopool = $inifilevalues.enableNanopool
}
else {
$script:enableNanopool = 'True'
}
# poolStatRefreshRate= Default 60, Minimum 60
if( $inifilevalues.poolStatRefreshRate ) {
[ int ]$poolStatRefreshRate = $inifilevalues.poolStatRefreshRate
if( $poolStatRefreshRate -lt 60 ) {$poolStatRefreshRate = 60}
}
else {
$poolStatRefreshRate = 60
}
if( $inifilevalues.coinStats ) {
[ string ]$coinStats = $inifilevalues.coinStats
}
else {
$coinStats = 'day'
}
# installedCards, how many cards to check for
if( $inifilevalues.installedCards ) {
[ int ]$installedCards = $inifilevalues.installedCards
}
else {
$installedCards = 1
}
# How often to check profitability
if( $inifilevalues.proftStatRefreshTime ) {
[ int ]$proftStatRefreshTime = $inifilevalues.proftStatRefreshTime
if( $inifilevalues.proftStatRefreshTime -lt 60 ) {$inifilevalues.proftStatRefreshTime = 60}
}
else {
$proftStatRefreshTime = 300
}
# Check if profitSwitching is enabled
if( $inifilevalues.profitSwitching ) {
[ string ]$profitSwitching = $inifilevalues.profitSwitching
}
else {
$profitSwitching = 'False'
}
# Check if cryptonight-heavy_factor is set
if( $inifilevalues.cryptonightheavy_factor ) {
[ decimal ]$cryptonightheavy_factor = $inifilevalues.cryptonightheavy_factor
}
else {
$cryptonightheavy_factor = 0.6
}
# Check if cryptonightfast_factor is set
if( $inifilevalues.cryptonightfast_factor ) {
[ decimal ]$cryptonightfast_factor = $inifilevalues.cryptonightfast_factor
}
else {
$cryptonightfast_factor = 1.8
}
# Check if cryptonightlite_factor is set
if( $inifilevalues.cryptonightlite_factor ) {
[ decimal ]$cryptonightlite_factor = $inifilevalues.$cryptonightlite_factor
}
else {
$cryptonightlite_factor = 2.5
}
# Check if cryptonightv2_factor is set
if( $inifilevalues.cryptonightv2_factor ) {
[ decimal ]$cryptonightv2_factor = $inifilevalues.cryptonightv2_factor
}
else {
$cryptonightv2_factor = 0.95
}
# Enable live prifit checking
if( $inifilevalues.profitLiveCheckingEnabled ) {
[ string ]$profitLiveCheckingEnabled = $inifilevalues.profitLiveCheckingEnabled
}
else {
$profitLiveCheckingEnabled = 'False'
}
# Kill STAK to switch coins
if( $inifilevalues.profitKillRunningStak ) {
[ string ]$profitKillRunningStak = $inifilevalues.profitKillRunningStak
}
else {
$profitKillRunningStak = 'False'
}
if( $inifilevalues.ProfitResetCardOnRestart ) {
$s = $inifilevalues.ProfitResetCardOnRestart
if( lower($s ) = "false" ) {
$ProfitResetCardOnRestart = $false
}
else {
$ProfitResetCardOnRestart = $true
}
}
else {$ProfitResetCardOnRestart = $true}
# Minimum extra profit before switching coins
if( $inifilevalues.profitSwitchPercentage ) {
[ int ]$profitSwitchPercentage = $inifilevalues.profitSwitchPercentage
}
else {
$profitSwitchPercentage = 5
}
# Minimum uptime before concidering switching coins
if( $inifilevalues.ProfitCheckMinutes ) {
[ decimal ]$ProfitCheckMinutes = $inifilevalues.ProfitCheckMinutes
}
else {
$ProfitCheckMinutes = 30
}
# Check if TEMPerMaxTemp is enabled
if( $inifilevalues.TempWatch ) {
[ string ]$script:TempWatch = $inifilevalues.TempWatch
}
else {$script:TempWatch = 'False'}
# Check if TEMPerMaxTemp is enabled
if( $inifilevalues.TEMPerMaxTemp ) {
[ Decimal ]$TEMPerMaxTemp = $inifilevalues.TEMPerMaxTemp
}
# Check if TEMPerMinDiff is enabled
if( $inifilevalues.TEMPerMinDiff ) {
[ Decimal ]$TEMPerMinDiff = $inifilevalues.TEMPerMinDiff
}
# Check if TEMPerValidMinutes is enabled
if( $inifilevalues.TEMPerValidMinutes ) {
[ int ]$TEMPerValidMinutes = $inifilevalues.TEMPerValidMinutes
}
else {$TEMPerValidMinutes = 0}
# Check if TEMPerSensorLocation is enabled
if( $inifilevalues.TEMPerSensorLocation ) {
[ STRING ]$TEMPerSensorLocation = $inifilevalues.TEMPerSensorLocation
}
else {$TEMPerSensorLocation = 'OuterTemp'}
# Check if sensorDataFile is specified, If not temp setting are disabled
if( $inifilevalues.sensorDataFile ) {
$sensorDataFile = ($inifilevalues.sensorDataFile ) -replace '///', '/'
}
# Check if killStakOnMaxTemp is enabled
if( $inifilevalues.killStakOnMaxTemp ) {
[ string ]$killStakOnMaxTemp = $inifilevalues.killStakOnMaxTemp
}
else {$killStakOnMaxTemp = 'False'}
$logfile = ("$logdir\$log" + "_$( get-date -Format yyyy-MM-dd ).log" ) # Log what we do by the day
$script:STAKexe = $stakexe # The miner to run
$script:STAKcmdline = $STAKcmdline # STAK arguments
$script:STAKfolder = $STAKfolder # STAK folder
$script:STAKPort = $STAKPort
$script:hdiff = $hdiff
try {
$error.Clear()
$script:vidToolArray = (Get-Content -Path $Path |
Where-Object {($_.Contains( '_vidTool' ) )} |
ForEach-Object {ConvertFrom-StringData -StringData ($_ -replace '\n-\s+' )} ).Values
ForEach( $vidTool2 in $script:vidToolArray ) {
Write-Verbose -Message "Global vidTool defined = $vidTool2"
}
}
catch {
write-host "Issue reading tools from hashmonitor.ini $( $Error[0] )" -fore Red
start-sleep -s 120
EXIT
}
# try {
# $error.Clear()
# $poolpath = "$ScriptDir\$script:STAKfolder\pools.txt"
# IF ( Test-Path -Path ($poolpath ) ) {
# $rawcurrency = Get-Content -Path $poolpath |
# Where-Object { ($_.Contains( 'currency' ) ) -notcontains (($_.Contains( '#' ) ) ) } |
# Out-String |
# ConvertFrom-StringData -StringData { ($_ -replace ':', '=' -replace '"|,' ) }
# }
# }
# catch {
# write-host "Issue reading pools.txt`n $( $Error[ 0 ] )" -fore Red
# start-sleep -s 120
# EXIT
# }
##########################################################################
# Set the REQUIRED variables for your Mining Configuration after user vars
##########################################################################
$script:Url = "http://$stakIP`:$script:STAKPort/api.json" # DO NOT CHANGE THIS !!
##### BEGIN FUNCTIONS #####
Function log-Write {
param ([Parameter( Mandatory, HelpMessage = 'String' )][string]$logstring,
[Parameter( Mandatory, HelpMessage = 'Provide colour to display to screen' )][string]$fore,
[Parameter( Mandatory = $true )][int] $notification, [switch]$linefeed, [string]
$attachment, [string]$type, [switch]$silent
)
$timeStamp = (get-Date -format r )
if( $fore -ne '0' ) {
Write-Host -Fore $fore "$logstring"
}
If( $Logfile -and $linefeed ) {
$Logfile = ($Logfile + '.txt' )
Add-content -Path $Logfile -Value ("`n$timeStamp `t$logstring" )
}
elseif ($logfile) {
$Logfile = ($Logfile + '.txt' )
Add-content -Path $Logfile -Value ("$timeStamp `t$logstring" )
}
if( $attachment ) {
if( ! $silent ) {write-output $attachment}
Add-content -Path $Logfile -Value ("$timeStamp `n$attachment" )
}
$msgText = "$timeStamp`t $logstring"
if( $alertLevel -ge $notification ) {
If( ($smsAddress ) -and ($notification -eq 0 ) ) {
Send-MailMessage -From $gUsername -Subject $msgText -To $smsAddress -UseSSL -Port 587 -SmtpServer smtp.gmail.com -Credential $gCredentials
}
If( $slackUrl ) {
Send-SlackMessage $logstring, $slackUrl, $slackUsername, $slackChannel, $slackEmoji, $slackIconUrl, $attachment, $type
}
}
}
function Get-Nanopool-Metric {
[OutputType( [int] )]
Param
(# Which coin to check
[Parameter( Mandatory, HelpMessage = 'You must specify a coin', ValueFromPipelineByPropertyName )]
[string]
$coin,
# Over how many hours
#[Parameter(Mandatory=$true)][int]
[int]
$Xhrs,
# Operation to be performed
[Parameter( Mandatory = $true )][string]
$op,
# Hashrate to use in calculations
[decimal]
$hashrate,
# Offset to use
[int]
$offset,
# Count
[int]
$count
)
DynamicParam {
# Create a parameter dictionary
$paramDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary
# Check if op needs as wallet address
if( ($op -notin ('approximated_earnings', 'block_stats', 'blocks', 'network_avgblocktime', 'network_lastblocknumber', 'network_timetonextepoch', 'pool_activeminers', 'pool_activeworkers', 'pool_hashrate', 'pool_topminers', 'prices' ) -and ($op ) ) ) {
Write-Verbose -Message ('wallet check {0}' -f $op )
$walletattribute = New-Object -TypeName System.Management.Automation.ParameterAttribute
#$walletattribute.Position = 6
$walletattribute.Mandatory = $true
$walletattribute.HelpMessage = 'I need a wallet address for this'
#create an attributecollection object for the attribute we just created.
$attributeCollection = new-object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
#add our custom attribute
$attributeCollection.Add( $walletattribute )
#add our paramater specifying the attribute collection
$walletparam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter -ArgumentList ('wallet', [ string ], $attributeCollection )
#expose the name of our parameter
$paramDictionary.Add( 'wallet', $walletparam )
}
# Check if op needs a worker address
if( ($op -in ('avghashrateworker', 'avghashratelimited', 'avghashrateworkers', 'hashratechart', 'history', 'pool_activeworkers', 'reportedhashrate', 'shareratehistory', 'workers' ) ) ) {
Write-Verbose -Message ('Worker check {0}' -f $op )
#create a new ParameterAttribute Object
$workerattribute = New-Object -TypeName System.Management.Automation.ParameterAttribute
#$workerattribute.Position = 7
$workerattribute.Mandatory = $true
$workerattribute.HelpMessage = 'I need a worker name for this'
#create an attributecollection object for the attribute we just created.
$attributeCollection = new-object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
#add our custom attribute
$attributeCollection.Add( $workerattribute )
#add our paramater specifying the attribute collection
$workerparam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter -ArgumentList ('worker', [ string ], $attributeCollection )
#expose the name of our parameter
$paramDictionary.Add( 'worker', $workerparam )
}
return $paramDictionary
}
Begin {
if( $PSBoundParameters.wallet ) {$wallet = $PSBoundParameters.wallet}
if( $PSBoundParameters.worker ) {$worker = $PSBoundParameters.worker}
$null = 'True'
# Select Operation
$stat = switch( $op ) {
'accountexist' {('accountexist/{0}' -f $wallet )}
'approximated_earnings' {('approximated_earnings/{0}' -f $hashrate )}
'avghashrate' {('avghashrate/{0}' -f $wallet )}
'avghashrateworker' {('avghashrate/{0}/{1}' -f $wallet, $worker )}
'avghashratelimited' {('avghashratelimited/{0}/{1}/{2}' -f $wallet, $worker, $Xhrs )}
'avghashratelimited' {('avghashratelimited/{0}/{1}' -f $wallet, $Xhrs )}
'avghashrateworkers' {('avghashrateworkers/{0}' -f $wallet )}
'balance' {('balance/{0}' -f $wallet )}
'balance_hashrate' {('balance_hashrate/{0}' -f $wallet )}
'balance_unconfirmed' {('balance_unconfirmed/{0}' -f $wallet )}
'block_stats' {('block_stats/{0}/{1}' -f $offset, $count )}
'blocks' {('blocks/{0}/{1}' -f $offset, $count )}
'hashrate' {('hashrate/{0}' -f $wallet )}
'hashratechart' {('hashratechart/{0}/{1}' -f $wallet, $worker )}
'hashratechart' {('hashratechart/{0}' -f $wallet )}
'history' {('history/{0}' -f $wallet )}
'history' {('history/{0}/{1}' -f $wallet, $worker )}
'network_avgblocktime' {'network/avgblocktime'}
'network_lastblocknumber' {'network/lastblocknumber'}
'network_timetonextepoch' {'network/timetonextepoch'}
'payments' {('payments/{0}' -f $wallet )}
'paymentsday' {('paymentsday/{0}' -f $wallet )}
'pool_activeminers' {'pool/activeminers'}