reorg
f151f3a9
3 file(s) · +74 −52
| 106 | 106 | <p>Total Data In: <span id="totalIn">-</span></p> |
|
| 107 | 107 | <p>Total Data Out: <span id="totalOut">-</span></p> |
|
| 108 | 108 | <div class="system-info"> |
|
| 109 | - | <div class="ipfs-div"> |
|
| 110 | - | <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 32 32"><path fill="#888888" d="M21.479 23.12c-1.14 1.317-1.776 3.719-.943 4.495c.792.593 2.933.521 4.511-1.641c1.151-1.443.76-3.859.109-4.5c-.973-.739-2.369.22-3.677 1.663zm-10.739.396c-1.213-1.385-2.787-2.209-3.803-1.599c-.683.509-.807 2.249.161 3.957c1.437 2.032 3.464 2.24 4.297 1.745c.88-.651.401-2.855-.656-4.104zm5.473 4.192c-1.473-.031-3.735.589-3.703 1.38c-.027.537 1.776 2.095 3.609 2.016c1.765.041 3.593-1.52 3.573-2.197c-.005-.699-1.996-1.235-3.475-1.177zM16.115 9.12c-1.703-.041-3.339 1.244-3.339 1.989c-.005.907 1.344 1.833 3.349 1.86c2.057.009 3.353-.745 3.375-1.683c.021-1.057-1.86-2.183-3.36-2.167zm-4.099.708c-2.844-.459-5.213 1.199-5.12 4.255c.093 1.177 6.172-4.052 5.125-4.233zm13 4.333c.093-3.036-2.276-4.692-5.125-4.235c-1.047.183 5.031 5.417 5.125 4.235m.484 1.099c-1.651-.437-.557 6.735.787 6.156c1.479-1.161 1.953-4.599-.787-6.135zM5.636 21.495c1.343.599 2.437-6.573.785-6.135c-2.733 1.541-2.265 4.973-.785 6.156zm12.557-7.932c-1.532 1-1.808 3.24-.615 4.995c1.187 1.76 3.391 2.416 4.916 1.437c1.532-.973 1.808-3.213.62-4.995c-1.193-1.776-3.396-2.416-4.921-1.416zm-4.13.182c-1.527-.98-3.735-.339-4.917 1.416c-1.192 1.781-.916 4.016.615 5.016c1.527 1 3.729.359 4.923-1.417c1.177-1.76.896-4-.62-4.995zm5.822 9.547c-.011-1.855-1.667-3.355-3.703-3.333c-2.037.02-3.683 1.515-3.672 3.375v.036c.011 1.86 1.672 3.36 3.708 3.339c2.036 0 3.677-1.515 3.656-3.353v-.043zm4.282-20.177c-3.079 1.579-4.869 2.839-5.855 3.916c.505 2 3.125 2.079 4.089 2.016c-.199-.077-.365-.197-.423-.353c.24-.163 1.095-.021 1.693-.344c-.229-.037-.339-.079-.443-.261c.563-.176 1.167-.317 1.52-.619c-.187 0-.369.041-.619-.12c.5-.256 1.036-.48 1.457-.876c-.26 0-.541 0-.619-.099a5.2 5.2 0 0 0 1.167-.943c-.36.063-.516.027-.605-.036c.349-.344.792-.641 1-1.084c-.271.104-.52.12-.697 0c.125-.255.631-.416.921-1.036c-.285.041-.588.063-.651 0c.136-.521.36-.817.584-1.14c-.609 0-1.537 0-1.491-.037l.376-.38c-.595-.161-1.204.021-1.647.161c-.197-.14 0-.344.245-.541c-.521.083-.975.183-1.375.344c-.219-.204.135-.38.317-.584c-.797.161-1.12.36-1.459.557c-.24-.219-.02-.416.141-.593c-.6.219-.901.495-1.219.755c-.12-.14-.281-.239-.084-.599q-.622.361-.979.839c-.256-.177-.156-.401-.156-.599c-.443.359-.72.719-1.057 1.083c-.084-.041-.141-.203-.183-.463c-1.037 1-2.521 3.5-.38 4.473c1.796-1.459 3.973-2.536 6.375-3.339zm-16.344 0c2.396.803 4.557 1.88 6.371 3.359c2.124-1 .656-3.5-.381-4.473c-.052.255-.109.437-.176.479c-.339-.359-.615-.724-1.052-1.083c0 .203.104.443-.157.599a3.1 3.1 0 0 0-.963-.839c.197.344.031.443-.079.599c-.317-.296-.62-.577-1.197-.796c.161.197.4.401.161.62c-.319-.199-.661-.401-1.437-.563c.176.197.536.4.317.604a5.6 5.6 0 0 0-1.38-.349c.239.203.453.385.255.541c-.459-.161-1.073-.339-1.672-.176l.375.375c.043.052-.875.041-1.495.047c.224.303.453.599.584 1.14c-.063.057-.36.021-.645 0c.301.6.796.761.916 1.021c-.177.125-.417.099-.697 0c.219.417.661.719 1 1.079c-.1.057-.24.099-.62.052c.317.344.697.656 1.161.937c-.084.093-.365.088-.641.099c.417.407.959.62 1.459.885c-.26.183-.443.141-.62.141c.339.296.959.437 1.521.615c-.125.181-.219.224-.464.26c.599.339 1.437.183 1.683.359c-.063.161-.219.281-.421.365c.957.057 3.599-.021 4.099-2.021c-.985-1.077-2.781-2.339-5.86-3.896zM10.136.136c.312-.005.577.181.869.271c.703-.229.864.083 1.208.213c.771-.161 1.005.187 1.375.557l.428-.016c1.161.677 1.739 2.052 1.943 2.756c.203-.704.781-2.079 1.943-2.756l.427.011c.369-.375.604-.719 1.375-.557c.349-.141.505-.437 1.215-.219c.443-.141.828-.5 1.411-.063c.489-.197.969-.26 1.391.12c.661-.079.869.083 1.031.281c.147 0 1.079-.141 1.511.479c1.084-.12 1.423.62 1.032 1.317c.224.339.453.663-.063 1.303c.197.36.077.735-.365 1.213c.125.5-.099.844-.495 1.12c.079.683-.64 1.084-.839 1.219c-.083.401-.244.781-1.061.979c-.12.6-.62.699-1.1.819c1.584.9 2.917 2.077 2.917 4.973l.244.401c1.797 1.079 3.417 4.536.896 7.355c-.156.875-.437 1.495-.681 2.192c-.36 2.817-2.776 4.136-3.412 4.297c-.921.697-1.917 1.359-3.255 1.817c-1.261 1.281-2.636 1.781-3.996 1.781h-.119c-1.38 0-2.756-.5-4.016-1.781c-1.344-.459-2.344-1.115-3.265-1.817c-.641-.156-3.043-1.475-3.417-4.292c-.249-.697-.525-1.339-.687-2.219c-2.527-2.817-.912-6.271.885-7.355l.229-.396c0-2.895 1.337-4.077 2.916-4.973c-.479-.12-.959-.219-1.093-.823c-.823-.199-.985-.579-1.063-.98c-.199-.135-.917-.536-.839-1.233c-.401-.281-.62-.62-.5-1.141c-.417-.459-.536-.859-.36-1.219c-.52-.64-.281-.979-.061-1.297c-.381-.703-.037-1.457 1.041-1.337c.416-.62 1.359-.48 1.495-.48c.161-.203.38-.38 1.041-.301c.417-.381.901-.319 1.396-.136c.203-.161.38-.219.541-.219z"/></svg> |
|
| 109 | + | <div class="ipfs-div"> |
|
| 110 | + | <svg |
|
| 111 | + | xmlns="http://www.w3.org/2000/svg" |
|
| 112 | + | width="24" |
|
| 113 | + | height="24" |
|
| 114 | + | viewBox="0 0 32 32" |
|
| 115 | + | > |
|
| 116 | + | <path |
|
| 117 | + | fill="#888888" |
|
| 118 | + | d="M21.479 23.12c-1.14 1.317-1.776 3.719-.943 4.495c.792.593 2.933.521 4.511-1.641c1.151-1.443.76-3.859.109-4.5c-.973-.739-2.369.22-3.677 1.663zm-10.739.396c-1.213-1.385-2.787-2.209-3.803-1.599c-.683.509-.807 2.249.161 3.957c1.437 2.032 3.464 2.24 4.297 1.745c.88-.651.401-2.855-.656-4.104zm5.473 4.192c-1.473-.031-3.735.589-3.703 1.38c-.027.537 1.776 2.095 3.609 2.016c1.765.041 3.593-1.52 3.573-2.197c-.005-.699-1.996-1.235-3.475-1.177zM16.115 9.12c-1.703-.041-3.339 1.244-3.339 1.989c-.005.907 1.344 1.833 3.349 1.86c2.057.009 3.353-.745 3.375-1.683c.021-1.057-1.86-2.183-3.36-2.167zm-4.099.708c-2.844-.459-5.213 1.199-5.12 4.255c.093 1.177 6.172-4.052 5.125-4.233zm13 4.333c.093-3.036-2.276-4.692-5.125-4.235c-1.047.183 5.031 5.417 5.125 4.235m.484 1.099c-1.651-.437-.557 6.735.787 6.156c1.479-1.161 1.953-4.599-.787-6.135zM5.636 21.495c1.343.599 2.437-6.573.785-6.135c-2.733 1.541-2.265 4.973-.785 6.156zm12.557-7.932c-1.532 1-1.808 3.24-.615 4.995c1.187 1.76 3.391 2.416 4.916 1.437c1.532-.973 1.808-3.213.62-4.995c-1.193-1.776-3.396-2.416-4.921-1.416zm-4.13.182c-1.527-.98-3.735-.339-4.917 1.416c-1.192 1.781-.916 4.016.615 5.016c1.527 1 3.729.359 4.923-1.417c1.177-1.76.896-4-.62-4.995zm5.822 9.547c-.011-1.855-1.667-3.355-3.703-3.333c-2.037.02-3.683 1.515-3.672 3.375v.036c.011 1.86 1.672 3.36 3.708 3.339c2.036 0 3.677-1.515 3.656-3.353v-.043zm4.282-20.177c-3.079 1.579-4.869 2.839-5.855 3.916c.505 2 3.125 2.079 4.089 2.016c-.199-.077-.365-.197-.423-.353c.24-.163 1.095-.021 1.693-.344c-.229-.037-.339-.079-.443-.261c.563-.176 1.167-.317 1.52-.619c-.187 0-.369.041-.619-.12c.5-.256 1.036-.48 1.457-.876c-.26 0-.541 0-.619-.099a5.2 5.2 0 0 0 1.167-.943c-.36.063-.516.027-.605-.036c.349-.344.792-.641 1-1.084c-.271.104-.52.12-.697 0c.125-.255.631-.416.921-1.036c-.285.041-.588.063-.651 0c.136-.521.36-.817.584-1.14c-.609 0-1.537 0-1.491-.037l.376-.38c-.595-.161-1.204.021-1.647.161c-.197-.14 0-.344.245-.541c-.521.083-.975.183-1.375.344c-.219-.204.135-.38.317-.584c-.797.161-1.12.36-1.459.557c-.24-.219-.02-.416.141-.593c-.6.219-.901.495-1.219.755c-.12-.14-.281-.239-.084-.599q-.622.361-.979.839c-.256-.177-.156-.401-.156-.599c-.443.359-.72.719-1.057 1.083c-.084-.041-.141-.203-.183-.463c-1.037 1-2.521 3.5-.38 4.473c1.796-1.459 3.973-2.536 6.375-3.339zm-16.344 0c2.396.803 4.557 1.88 6.371 3.359c2.124-1 .656-3.5-.381-4.473c-.052.255-.109.437-.176.479c-.339-.359-.615-.724-1.052-1.083c0 .203.104.443-.157.599a3.1 3.1 0 0 0-.963-.839c.197.344.031.443-.079.599c-.317-.296-.62-.577-1.197-.796c.161.197.4.401.161.62c-.319-.199-.661-.401-1.437-.563c.176.197.536.4.317.604a5.6 5.6 0 0 0-1.38-.349c.239.203.453.385.255.541c-.459-.161-1.073-.339-1.672-.176l.375.375c.043.052-.875.041-1.495.047c.224.303.453.599.584 1.14c-.063.057-.36.021-.645 0c.301.6.796.761.916 1.021c-.177.125-.417.099-.697 0c.219.417.661.719 1 1.079c-.1.057-.24.099-.62.052c.317.344.697.656 1.161.937c-.084.093-.365.088-.641.099c.417.407.959.62 1.459.885c-.26.183-.443.141-.62.141c.339.296.959.437 1.521.615c-.125.181-.219.224-.464.26c.599.339 1.437.183 1.683.359c-.063.161-.219.281-.421.365c.957.057 3.599-.021 4.099-2.021c-.985-1.077-2.781-2.339-5.86-3.896zM10.136.136c.312-.005.577.181.869.271c.703-.229.864.083 1.208.213c.771-.161 1.005.187 1.375.557l.428-.016c1.161.677 1.739 2.052 1.943 2.756c.203-.704.781-2.079 1.943-2.756l.427.011c.369-.375.604-.719 1.375-.557c.349-.141.505-.437 1.215-.219c.443-.141.828-.5 1.411-.063c.489-.197.969-.26 1.391.12c.661-.079.869.083 1.031.281c.147 0 1.079-.141 1.511.479c1.084-.12 1.423.62 1.032 1.317c.224.339.453.663-.063 1.303c.197.36.077.735-.365 1.213c.125.5-.099.844-.495 1.12c.079.683-.64 1.084-.839 1.219c-.083.401-.244.781-1.061.979c-.12.6-.62.699-1.1.819c1.584.9 2.917 2.077 2.917 4.973l.244.401c1.797 1.079 3.417 4.536.896 7.355c-.156.875-.437 1.495-.681 2.192c-.36 2.817-2.776 4.136-3.412 4.297c-.921.697-1.917 1.359-3.255 1.817c-1.261 1.281-2.636 1.781-3.996 1.781h-.119c-1.38 0-2.756-.5-4.016-1.781c-1.344-.459-2.344-1.115-3.265-1.817c-.641-.156-3.043-1.475-3.417-4.292c-.249-.697-.525-1.339-.687-2.219c-2.527-2.817-.912-6.271.885-7.355l.229-.396c0-2.895 1.337-4.077 2.916-4.973c-.479-.12-.959-.219-1.093-.823c-.823-.199-.985-.579-1.063-.98c-.199-.135-.917-.536-.839-1.233c-.401-.281-.62-.62-.5-1.141c-.417-.459-.536-.859-.36-1.219c-.52-.64-.281-.979-.061-1.297c-.381-.703-.037-1.457 1.041-1.337c.416-.62 1.359-.48 1.495-.48c.161-.203.38-.38 1.041-.301c.417-.381.901-.319 1.396-.136c.203-.161.38-.219.541-.219z" |
|
| 119 | + | /> |
|
| 120 | + | </svg> |
|
| 111 | 121 | <h3>System Information</h3> |
|
| 112 | - | </div> |
|
| 113 | - | <p>OS: <span id="os">-</span></p> |
|
| 114 | - | <p>Kernel: <span id="kernel">-</span></p> |
|
| 115 | - | <p>Uptime: <span id="uptime">-</span></p> |
|
| 116 | - | <p>CPU Model: <span id="cpuModel">-</span></p> |
|
| 117 | - | <p>CPU Usage: <span id="cpuUsage">-</span>%</p> |
|
| 118 | - | <p>Memory: <span id="memoryUsed">-</span>/<span id="memoryTotal">-</span></p> |
|
| 122 | + | </div> |
|
| 123 | + | <p>OS: <span id="os">-</span></p> |
|
| 124 | + | <p>Kernel: <span id="kernel">-</span></p> |
|
| 125 | + | <p>Uptime: <span id="uptime">-</span></p> |
|
| 126 | + | <p>CPU Model: <span id="cpuModel">-</span></p> |
|
| 127 | + | <p>CPU Usage: <span id="cpuUsage">-</span>%</p> |
|
| 128 | + | <p> |
|
| 129 | + | Memory: <span id="memoryUsed">-</span>/<span id="memoryTotal">-</span> |
|
| 130 | + | </p> |
|
| 119 | 131 | </div> |
|
| 120 | - | ||
| 121 | 132 | </div> |
|
| 122 | 133 | <script> |
|
| 123 | 134 | function formatBytes(bytes, decimals = 2) { |
|
| 182 | 193 | document.getElementById("kernel").textContent = data.kernel; |
|
| 183 | 194 | document.getElementById("uptime").textContent = data.uptime; |
|
| 184 | 195 | document.getElementById("cpuModel").textContent = data.cpuModel; |
|
| 185 | - | document.getElementById("cpuUsage").textContent = data.cpuUsage.toFixed(2); |
|
| 186 | - | document.getElementById("memoryUsed").textContent = formatBytes(data.memoryUsed); |
|
| 187 | - | document.getElementById("memoryTotal").textContent = formatBytes(data.memoryTotal); |
|
| 196 | + | document.getElementById("cpuUsage").textContent = |
|
| 197 | + | data.cpuUsage.toFixed(2); |
|
| 198 | + | document.getElementById("memoryUsed").textContent = formatBytes( |
|
| 199 | + | data.memoryUsed, |
|
| 200 | + | ); |
|
| 201 | + | document.getElementById("memoryTotal").textContent = formatBytes( |
|
| 202 | + | data.memoryTotal, |
|
| 203 | + | ); |
|
| 188 | 204 | } catch (error) { |
|
| 189 | 205 | console.error("Error parsing or updating data:", error); |
|
| 190 | 206 | } |
|
| 7 | 7 | "io/ioutil" |
|
| 8 | 8 | "log" |
|
| 9 | 9 | "net/http" |
|
| 10 | - | "strings" |
|
| 11 | 10 | "time" |
|
| 12 | 11 | ||
| 13 | 12 | "github.com/shirou/gopsutil/cpu" |
|
| 69 | 68 | log.Println("SSE connection established") |
|
| 70 | 69 | ||
| 71 | 70 | for { |
|
| 72 | - | combinedStats, err := getIpfsStats() |
|
| 71 | + | combinedStats, err := getStats() |
|
| 73 | 72 | if err != nil { |
|
| 74 | 73 | log.Printf("Error getting IPFS Stats: %v", err) |
|
| 75 | 74 | time.Sleep(1 * time.Second) |
|
| 94 | 93 | } |
|
| 95 | 94 | } |
|
| 96 | 95 | ||
| 97 | - | func getIpfsStats() (CombinedStats, error) { |
|
| 96 | + | func getStats() (CombinedStats, error) { |
|
| 98 | 97 | repoStats, err := getIpfsRepoStat() |
|
| 99 | 98 | if err != nil { |
|
| 100 | 99 | return CombinedStats{}, err |
|
| 199 | 198 | CPUModel: "BCM2835 (4) @ 1.800GHz", |
|
| 200 | 199 | }, nil |
|
| 201 | 200 | } |
|
| 202 | - | ||
| 203 | - | func formatBytes(bytes int64) string { |
|
| 204 | - | const unit = 1024 |
|
| 205 | - | if bytes < unit { |
|
| 206 | - | return fmt.Sprintf("%d B", bytes) |
|
| 207 | - | } |
|
| 208 | - | div, exp := int64(unit), 0 |
|
| 209 | - | for n := bytes / unit; n >= unit; n /= unit { |
|
| 210 | - | div *= unit |
|
| 211 | - | exp++ |
|
| 212 | - | } |
|
| 213 | - | return fmt.Sprintf("%.1f %ciB", float64(bytes)/float64(div), "KMGTPE"[exp]) |
|
| 214 | - | } |
|
| 215 | - | ||
| 216 | - | func formatUptime(uptime time.Duration) string { |
|
| 217 | - | days := int(uptime.Hours() / 24) |
|
| 218 | - | hours := int(uptime.Hours()) % 24 |
|
| 219 | - | minutes := int(uptime.Minutes()) % 60 |
|
| 220 | - | seconds := int(uptime.Seconds()) % 60 |
|
| 221 | - | ||
| 222 | - | var parts []string |
|
| 223 | - | if days > 0 { |
|
| 224 | - | parts = append(parts, fmt.Sprintf("%dd", days)) |
|
| 225 | - | } |
|
| 226 | - | if hours > 0 { |
|
| 227 | - | parts = append(parts, fmt.Sprintf("%dh", hours)) |
|
| 228 | - | } |
|
| 229 | - | if minutes > 0 { |
|
| 230 | - | parts = append(parts, fmt.Sprintf("%dm", minutes)) |
|
| 231 | - | } |
|
| 232 | - | if seconds > 0 || len(parts) == 0 { |
|
| 233 | - | parts = append(parts, fmt.Sprintf("%ds", seconds)) |
|
| 234 | - | } |
|
| 235 | - | ||
| 236 | - | return strings.Join(parts, " ") |
|
| 237 | - | } |
|
| 1 | + | package main |
|
| 2 | + | ||
| 3 | + | import ( |
|
| 4 | + | "fmt" |
|
| 5 | + | "strings" |
|
| 6 | + | "time" |
|
| 7 | + | ) |
|
| 8 | + | ||
| 9 | + | func formatBytes(bytes int64) string { |
|
| 10 | + | const unit = 1024 |
|
| 11 | + | if bytes < unit { |
|
| 12 | + | return fmt.Sprintf("%d B", bytes) |
|
| 13 | + | } |
|
| 14 | + | div, exp := int64(unit), 0 |
|
| 15 | + | for n := bytes / unit; n >= unit; n /= unit { |
|
| 16 | + | div *= unit |
|
| 17 | + | exp++ |
|
| 18 | + | } |
|
| 19 | + | return fmt.Sprintf("%.1f %ciB", float64(bytes)/float64(div), "KMGTPE"[exp]) |
|
| 20 | + | } |
|
| 21 | + | ||
| 22 | + | func formatUptime(uptime time.Duration) string { |
|
| 23 | + | days := int(uptime.Hours() / 24) |
|
| 24 | + | hours := int(uptime.Hours()) % 24 |
|
| 25 | + | minutes := int(uptime.Minutes()) % 60 |
|
| 26 | + | seconds := int(uptime.Seconds()) % 60 |
|
| 27 | + | ||
| 28 | + | var parts []string |
|
| 29 | + | if days > 0 { |
|
| 30 | + | parts = append(parts, fmt.Sprintf("%dd", days)) |
|
| 31 | + | } |
|
| 32 | + | if hours > 0 { |
|
| 33 | + | parts = append(parts, fmt.Sprintf("%dh", hours)) |
|
| 34 | + | } |
|
| 35 | + | if minutes > 0 { |
|
| 36 | + | parts = append(parts, fmt.Sprintf("%dm", minutes)) |
|
| 37 | + | } |
|
| 38 | + | if seconds > 0 || len(parts) == 0 { |
|
| 39 | + | parts = append(parts, fmt.Sprintf("%ds", seconds)) |
|
| 40 | + | } |
|
| 41 | + | ||
| 42 | + | return strings.Join(parts, " ") |
|
| 43 | + | } |