void0028 commited on
Commit
7682ee7
·
verified ·
1 Parent(s): e5a5cdb

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +17 -14
Dockerfile CHANGED
@@ -3,6 +3,7 @@ FROM node:18-bullseye-slim
3
  USER root
4
 
5
  # 1. Install System Tools
 
6
  RUN apt-get update && \
7
  apt-get install -y wget ffmpeg dumb-init procps && \
8
  apt-get autoremove -y && \
@@ -26,6 +27,7 @@ ENV STREAMING_DISABLED=0
26
  ENV PORT=11470
27
 
28
  # 6. DASHBOARD V2 (With Speedometer)
 
29
  RUN echo "const http = require('http'); \
30
  const httpProxy = require('http-proxy'); \
31
  const { execSync } = require('child_process'); \
@@ -44,6 +46,7 @@ let stats = { \
44
  }; \
45
  \
46
  let lastRx = 0; \
 
47
  try { lastRx = parseInt(fs.readFileSync('/sys/class/net/eth0/statistics/rx_bytes', 'utf8')); } catch(e) {} \
48
  \
49
  // Update Stats every second \
@@ -60,7 +63,7 @@ setInterval(() => { \
60
  // Update Max \
61
  if (mbps > stats.max) stats.max = mbps; \
62
  \
63
- // Update Min (Only count non-idle speeds > 0.1 Mbps) \
64
  if (mbps > 0.1) { \
65
  if (stats.min === 0 || mbps < stats.min) stats.min = mbps; \
66
  } \
@@ -68,7 +71,7 @@ setInterval(() => { \
68
  // Update Avg \
69
  stats.totalBytes += diff; \
70
  stats.samples++; \
71
- // Avg = (Total Bits) / (Total Seconds) / 1M \
72
  stats.avg = (stats.totalBytes * 8) / stats.samples / 1000000; \
73
  \
74
  } catch(e) {} \
@@ -86,6 +89,7 @@ proxy.on('error', (err, req, res) => { \
86
  }); \
87
  \
88
  const server = http.createServer((req, res) => { \
 
89
  if (req.url === '/' || req.url === '/health') { \
90
  let disk = 'Unknown', ram = 'Unknown', uptime = 'Unknown'; \
91
  try { \
@@ -95,28 +99,27 @@ const server = http.createServer((req, res) => { \
95
  uptime = Math.floor(upSec / 3600) + 'h ' + Math.floor((upSec % 3600) / 60) + 'm'; \
96
  } catch (e) {} \
97
  \
98
- const duration = ((Date.now() - stats.startTime) / 1000 / 60 / 60).toFixed(1); \
99
  \
100
  const html = \` \
101
  <body style='background:#0d1117; color:#3fb950; font-family:monospace; display:flex; flex-direction:column; align-items:center; justify-content:center; height:100vh; margin:0;'> \
102
- <div style='border: 1px solid #3fb950; padding: 25px; border-radius: 12px; min-width: 300px; box-shadow: 0 0 20px rgba(63, 185, 80, 0.2); background:#161b22;'> \
103
  <h2 style='margin:0 0 15px 0; text-align:center; border-bottom: 1px solid #30363d; padding-bottom:10px;'>🚀 NETWORK METRICS</h2> \
104
  \
105
- <div style='margin-bottom: 20px;'> \
106
- <div style='font-size: 24px; color:white; text-align:center; margin-bottom:5px;'>⬇️ \${stats.current.toFixed(2)} Mbps</div> \
107
- <div style='text-align:center; font-size:12px; color:#8b949e;'>Live Throughput</div> \
108
  </div> \
109
  \
110
- <div style='display:grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 13px; color:#c9d1d9; border-top: 1px solid #30363d; padding-top:15px;'> \
111
- <div>📈 Max: <span style='color:#white'>\${stats.max.toFixed(2)}</span> Mbps</div> \
112
- <div>📉 Min (Act): <span style='color:#white'>\${stats.min.toFixed(2)}</span> Mbps</div> \
113
- <div>📊 Avg: <span style='color:#white'>\${stats.avg.toFixed(2)}</span> Mbps</div> \
114
- <div>⏱️ Monitored: <span style='color:#white'>\${duration}</span> Hrs</div> \
115
  </div> \
116
  \
117
  <div style='margin-top: 20px; border-top: 1px solid #30363d; padding-top: 15px; font-size: 12px; color:#8b949e;'> \
118
- <p>💾 Disk: \${disk}</p> \
119
- <p>🧠 RAM: \${ram}</p> \
120
  <p>⚡ Uptime: \${uptime}</p> \
121
  </div> \
122
  </div> \
 
3
  USER root
4
 
5
  # 1. Install System Tools
6
+ # We need 'procps' for system stats and 'bc' for math if needed
7
  RUN apt-get update && \
8
  apt-get install -y wget ffmpeg dumb-init procps && \
9
  apt-get autoremove -y && \
 
27
  ENV PORT=11470
28
 
29
  # 6. DASHBOARD V2 (With Speedometer)
30
+ # This script monitors the network interface (eth0) directly from the kernel.
31
  RUN echo "const http = require('http'); \
32
  const httpProxy = require('http-proxy'); \
33
  const { execSync } = require('child_process'); \
 
46
  }; \
47
  \
48
  let lastRx = 0; \
49
+ // Try to read initial network counter \
50
  try { lastRx = parseInt(fs.readFileSync('/sys/class/net/eth0/statistics/rx_bytes', 'utf8')); } catch(e) {} \
51
  \
52
  // Update Stats every second \
 
63
  // Update Max \
64
  if (mbps > stats.max) stats.max = mbps; \
65
  \
66
+ // Update Min (Only count active usage > 0.1 Mbps) \
67
  if (mbps > 0.1) { \
68
  if (stats.min === 0 || mbps < stats.min) stats.min = mbps; \
69
  } \
 
71
  // Update Avg \
72
  stats.totalBytes += diff; \
73
  stats.samples++; \
74
+ // Avg calculation \
75
  stats.avg = (stats.totalBytes * 8) / stats.samples / 1000000; \
76
  \
77
  } catch(e) {} \
 
89
  }); \
90
  \
91
  const server = http.createServer((req, res) => { \
92
+ // Serve Dashboard on Home Page \
93
  if (req.url === '/' || req.url === '/health') { \
94
  let disk = 'Unknown', ram = 'Unknown', uptime = 'Unknown'; \
95
  try { \
 
99
  uptime = Math.floor(upSec / 3600) + 'h ' + Math.floor((upSec % 3600) / 60) + 'm'; \
100
  } catch (e) {} \
101
  \
102
+ const duration = ((Date.now() - stats.startTime) / 1000 / 60 / 60).toFixed(2); \
103
  \
104
  const html = \` \
105
  <body style='background:#0d1117; color:#3fb950; font-family:monospace; display:flex; flex-direction:column; align-items:center; justify-content:center; height:100vh; margin:0;'> \
106
+ <div style='border: 1px solid #3fb950; padding: 25px; border-radius: 12px; min-width: 320px; box-shadow: 0 0 20px rgba(63, 185, 80, 0.2); background:#161b22;'> \
107
  <h2 style='margin:0 0 15px 0; text-align:center; border-bottom: 1px solid #30363d; padding-bottom:10px;'>🚀 NETWORK METRICS</h2> \
108
  \
109
+ <div style='margin-bottom: 20px; text-align:center;'> \
110
+ <div style='font-size: 32px; color:white; font-weight:bold;'>⬇️ \${stats.current.toFixed(2)} Mbps</div> \
111
+ <div style='font-size:12px; color:#8b949e;'>Live Throughput</div> \
112
  </div> \
113
  \
114
+ <div style='display:grid; grid-template-columns: 1fr 1fr; gap: 15px; font-size: 13px; color:#c9d1d9; border-top: 1px solid #30363d; padding-top:15px;'> \
115
+ <div>📈 Max: <span style='color:white'>\${stats.max.toFixed(2)}</span> Mbps</div> \
116
+ <div>📉 Min: <span style='color:white'>\${stats.min.toFixed(2)}</span> Mbps</div> \
117
+ <div>📊 Avg: <span style='color:white'>\${stats.avg.toFixed(2)}</span> Mbps</div> \
118
+ <div>⏱️ Run: <span style='color:white'>\${duration}</span> Hrs</div> \
119
  </div> \
120
  \
121
  <div style='margin-top: 20px; border-top: 1px solid #30363d; padding-top: 15px; font-size: 12px; color:#8b949e;'> \
122
+ <p>💾 Disk: \${disk} | �� RAM: \${ram}</p> \
 
123
  <p>⚡ Uptime: \${uptime}</p> \
124
  </div> \
125
  </div> \