-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
173 lines (159 loc) · 7.99 KB
/
Program.cs
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
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
namespace MinerHashRateMonitor
{
public class Program
{
static void Main(string[] args)
{
try
{
IList<Miner> miners = GetMinersList();
using (IWebDriver chrome = new ChromeDriver())
{
//chrome.Manage().Timeouts().ImplicitWait = new TimeSpan(0,0,5);
//Logger.Log(string.Empty);
Logger.Log("Session Started - " + DateTime.Now.ToString());
foreach (var miner in miners)
{
try
{
if (miner.IsOnline)
{
string rootUrl = string.Format("http://root:root1@{0}", miner.Ip);
string statusUrl = string.Format("http://{0}/cgi-bin/minerStatus.cgi", miner.Ip);
string rebootUrl = string.Format("http://{0}/reboot.html", miner.Ip);
INavigation navigator = chrome.Navigate();
navigator.GoToUrl(rootUrl);
navigator.GoToUrl(statusUrl);
//Logger.Log(string.Format("[{0}]",miner.Name));
IWebElement time_elapsed = chrome.FindElement(By.Id("ant_elapsed"));
if (!string.IsNullOrEmpty(time_elapsed.Text))
{
int totalMinutes = ConvertToMinutes(time_elapsed.Text);
//Logger.Log(string.Format("Total minutes elapsed - {0}", totalMinutes));
if (totalMinutes >= 13)
{
IWebElement ant_ghs5s = chrome.FindElement(By.Id("ant_ghs5s"));
IWebElement avg_hash = chrome.FindElement(By.Id("ant_ghsav"));
if (!string.IsNullOrEmpty(avg_hash.Text))
{
var ant_ghs5s_value = (int)Convert.ToDecimal(ant_ghs5s.Text.Replace(",", string.Empty));
var avg_hash_value = (int)Convert.ToDecimal(avg_hash.Text.Replace(",", string.Empty));
//Logger.Log(string.Format("Average hashrate - {0}/ {1}", avg_hash_value, miner.HashRate));
if (ant_ghs5s_value < miner.HashRate || avg_hash_value < miner.HashRate)
{
Logger.Log(string.Format("[{0}] - Below threashold {1}-{2}/{3}. Restarting...", miner.Name, ant_ghs5s_value, avg_hash_value, miner.HashRate));
navigator.GoToUrl(rebootUrl);
IWebElement reboot_button = chrome.FindElement(By.ClassName("cbi-button-save"));
reboot_button.Click();
}
else
{
Logger.Log(string.Format("[{0}] - {1} @{2}h - OK", miner.Name, avg_hash_value, ConvertToHrs(totalMinutes)));
}
}
}
else
{
Logger.Log(string.Format("[{0}] - Warming Up @{1}m", miner.Name, totalMinutes));
}
}
else
{
Logger.Log(string.Format("[{0}] - Starting up.", miner.Name));
}
}
else
{
Logger.Log(string.Format("[{0}] - OFFLINE", miner.Name));
}
}
catch (Exception ex)
{
Logger.Log("Error:" + ex.Message);
Logger.Log(ex.Message + Environment.NewLine + ex.StackTrace, false, true);
}
}
}
// Check internet connection statitics
InternetManager.CheckInternetSpeed();
// Session end
Logger.Log(string.Empty, true);
}
catch (Exception ex)
{
Logger.Log("Error:" + ex.Message);
Logger.Log(ex.Message + Environment.NewLine + ex.StackTrace, false, true);
Logger.Log(string.Empty, true);
}
finally
{
Logger.CleanupWebDriver();
}
}
private static decimal ConvertToHrs(decimal totalMinutes)
{
decimal hrs = Math.Round(totalMinutes / 60, 1);
return hrs;
}
private static IList<Miner> GetMinersList()
{
return new List<Miner>()
{
//new Miner() { Name = "S9-1", Type = MinerType.Bitcoin, Ip = "192.168.1.11", HashRate = 4500},
new Miner() { Name = "S9-2", Type = MinerType.Bitcoin, Ip = "192.168.1.12", HashRate = 13000},
new Miner() { Name = "S9-3", Type = MinerType.Bitcoin, Ip = "192.168.1.13", HashRate = 12000},
new Miner() { Name = "T9-1", Type = MinerType.Bitcoin, Ip = "192.168.1.14", HashRate = 7000},
new Miner() { Name = "T9-2", Type = MinerType.Bitcoin, Ip = "192.168.1.15", HashRate = 11000},
new Miner() { Name = "L3-1", Type = MinerType.Litecoin, Ip = "192.168.1.16", HashRate = 500},
new Miner() { Name = "L3-2", Type = MinerType.Litecoin, Ip = "192.168.1.17", HashRate = 450},
new Miner() { Name = "L3-3", Type = MinerType.Litecoin, Ip = "192.168.1.18", HashRate = 450}
};
}
public static int ConvertToMinutes(string time_elapsed)
{
int days = 0, hours = 0, minutes = 0;
int length = time_elapsed.Length;
int d_index = time_elapsed.IndexOf("d");
int h_index = time_elapsed.IndexOf("h");
int m_index = time_elapsed.IndexOf("m");
if (d_index > 0)
{
days = Convert.ToInt32(time_elapsed.Substring(0, d_index));
}
if (h_index > 0)
{
if (d_index > 0)
{
hours = Convert.ToInt32(time_elapsed.Substring(d_index + 1, h_index - (d_index + 1)));
}
else
{
hours = Convert.ToInt32(time_elapsed.Substring(0, h_index));
}
}
if (m_index > 0)
{
if (h_index > 0)
{
minutes = Convert.ToInt32(time_elapsed.Substring(h_index + 1, m_index - (h_index + 1)));
}
else
{
if (d_index > 0)
{
minutes = Convert.ToInt32(time_elapsed.Substring(d_index + 1, m_index - 2));
}
else
{
minutes = Convert.ToInt32(time_elapsed.Substring(0, m_index));
}
}
}
return (days*24*60 + hours * 60 + minutes);
}
}
}