forked from frstrtr/c2pool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphysical_miner_monitor.py
More file actions
executable file
·182 lines (147 loc) · 6.52 KB
/
physical_miner_monitor.py
File metadata and controls
executable file
·182 lines (147 loc) · 6.52 KB
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
#!/usr/bin/env python3
"""
Physical Miner Real-time Monitor for C2Pool
Monitors active physical miner connections and Stratum activity
"""
import subprocess
import time
import socket
import json
import sys
from datetime import datetime
def get_physical_miner_connections():
"""Get detailed information about physical miner connections"""
connections = []
try:
# Get network connections to port 8084
result = subprocess.run(['netstat', '-an'], capture_output=True, text=True, timeout=5)
if result.returncode == 0:
lines = result.stdout.split('\n')
for line in lines:
if ':8084' in line and 'ESTABLISHED' in line:
parts = line.split()
if len(parts) >= 4:
local_addr = parts[3]
remote_addr = parts[4]
# Extract remote IP (remove port)
remote_ip = remote_addr.split(':')[0]
connections.append({
'remote_ip': remote_ip,
'remote_addr': remote_addr,
'local_addr': local_addr
})
# Get unique miners by IP
unique_miners = {}
for conn in connections:
ip = conn['remote_ip']
if ip not in unique_miners:
unique_miners[ip] = {'ip': ip, 'connections': 0, 'ports': []}
unique_miners[ip]['connections'] += 1
port = conn['remote_addr'].split(':')[1]
unique_miners[ip]['ports'].append(port)
return list(unique_miners.values()), len(connections)
except Exception as e:
print(f"Error getting connections: {e}")
return [], 0
def test_stratum_activity():
"""Test if the Stratum server is responsive"""
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(3)
sock.connect(("localhost", 8084))
# Quick subscribe test
subscribe_req = {
"id": 1,
"method": "mining.subscribe",
"params": ["monitor/1.0"]
}
message = json.dumps(subscribe_req) + "\n"
sock.send(message.encode())
sock.settimeout(2)
response = sock.recv(1024).decode().strip()
sock.close()
# Parse response to check if it's valid
if response and "result" in response:
return True, "Active"
else:
return False, "No Response"
except Exception as e:
return False, str(e)
def monitor_physical_miners():
"""Real-time monitoring of physical miners"""
print("🔋 C2Pool Physical Miner Real-time Monitor")
print("==========================================")
print("Press Ctrl+C to stop monitoring\n")
start_time = datetime.now()
check_count = 0
try:
while True:
check_count += 1
current_time = datetime.now()
runtime = current_time - start_time
# Get miner connections
miners, total_connections = get_physical_miner_connections()
# Test Stratum responsiveness
stratum_ok, stratum_status = test_stratum_activity()
# Clear screen and show header
print(f"\033[2J\033[H", end="") # Clear screen, move cursor to top
print("🔋 C2Pool Physical Miner Real-time Monitor")
print("==========================================")
print(f"Runtime: {str(runtime).split('.')[0]} | Check: {check_count} | {current_time.strftime('%H:%M:%S')}")
print(f"Stratum Server: {'🟢 Active' if stratum_ok else '🔴 ' + stratum_status}")
print()
if miners:
print(f"👥 Physical Miners Connected: {len(miners)}")
print(f"📡 Total Connections: {total_connections}")
print("─" * 60)
for i, miner in enumerate(miners, 1):
ports_str = ", ".join(miner['ports'][:3]) # Show first 3 ports
if len(miner['ports']) > 3:
ports_str += f" +{len(miner['ports'])-3} more"
print(f"{i:2d}. 🖥️ {miner['ip']:<15} │ "
f"{miner['connections']:2d} conn │ "
f"Ports: {ports_str}")
print()
print("💡 Status: Physical miners are actively connected!")
print("⚡ Miners should be receiving work and submitting shares")
else:
print("❌ No Physical Miners Connected")
print(" • C2Pool is running and ready for connections")
print(" • Miners should connect to: stratum+tcp://192.168.86.30:8084")
print(" • Check miner configuration and network connectivity")
print()
print("Press Ctrl+C to stop monitoring...")
# Wait before next check
time.sleep(5)
except KeyboardInterrupt:
print("\n\n⏹️ Monitoring stopped by user")
print("📊 Final Summary:")
print(f" Runtime: {str(datetime.now() - start_time).split('.')[0]}")
print(f" Total checks: {check_count}")
if miners:
print(f" Miners detected: {len(miners)}")
print(f" Total connections: {total_connections}")
else:
print(" No miners were connected during monitoring")
def quick_status():
"""Show a quick status check"""
print("🔍 Quick Status Check")
print("====================")
miners, total_connections = get_physical_miner_connections()
stratum_ok, stratum_status = test_stratum_activity()
print(f"Stratum Server: {'✅ Active' if stratum_ok else '❌ ' + stratum_status}")
print(f"Physical Miners: {len(miners)} unique miners")
print(f"Total Connections: {total_connections}")
if miners:
print("\nConnected Miners:")
for i, miner in enumerate(miners, 1):
print(f" {i}. {miner['ip']} ({miner['connections']} connections)")
return len(miners) > 0
def main():
if len(sys.argv) > 1 and sys.argv[1] == "--quick":
success = quick_status()
sys.exit(0 if success else 1)
else:
monitor_physical_miners()
if __name__ == "__main__":
main()