added system status
84143300
2 file(s) · +58 −2
| 105 | 105 | <p>Bandwidth Out: <span id="rateOut">-</span></p> |
|
| 106 | 106 | <p>Total Data In: <span id="totalIn">-</span></p> |
|
| 107 | 107 | <p>Total Data Out: <span id="totalOut">-</span></p> |
|
| 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> |
|
| 111 | + | <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> |
|
| 119 | + | </div> |
|
| 120 | + | ||
| 108 | 121 | </div> |
|
| 109 | 122 | <script> |
|
| 110 | 123 | function formatBytes(bytes, decimals = 2) { |
|
| 165 | 178 | document.getElementById("totalOut").textContent = formatBytes( |
|
| 166 | 179 | data.TotalOut, |
|
| 167 | 180 | ); |
|
| 181 | + | document.getElementById("os").textContent = data.os; |
|
| 182 | + | document.getElementById("kernel").textContent = data.kernel; |
|
| 183 | + | document.getElementById("uptime").textContent = data.uptime; |
|
| 184 | + | 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); |
|
| 168 | 188 | } catch (error) { |
|
| 169 | 189 | console.error("Error parsing or updating data:", error); |
|
| 170 | 190 | } |
|
| 10 | 10 | "time" |
|
| 11 | 11 | ||
| 12 | 12 | "github.com/shirou/gopsutil/cpu" |
|
| 13 | + | "github.com/shirou/gopsutil/host" |
|
| 13 | 14 | "github.com/shirou/gopsutil/mem" |
|
| 14 | 15 | ) |
|
| 15 | 16 | ||
| 16 | 17 | type SystemStats struct { |
|
| 17 | 18 | CPUUsage float64 `json:"cpuUsage"` |
|
| 18 | - | MemoryUsage float64 `json:"memoryUsage"` |
|
| 19 | + | MemoryUsed uint64 `json:"memoryUsed"` |
|
| 20 | + | MemoryTotal uint64 `json:"memoryTotal"` |
|
| 21 | + | OS string `json:"os"` |
|
| 22 | + | Kernel string `json:"kernel"` |
|
| 23 | + | Uptime string `json:"uptime"` |
|
| 24 | + | CPUModel string `json:"cpuModel"` |
|
| 19 | 25 | } |
|
| 20 | 26 | ||
| 21 | 27 | type IPFSRepoStats struct { |
|
| 36 | 42 | type CombinedStats struct { |
|
| 37 | 43 | IPFSRepoStats |
|
| 38 | 44 | BandwidthStats |
|
| 45 | + | SystemStats |
|
| 39 | 46 | } |
|
| 40 | 47 | ||
| 41 | 48 | func main() { |
|
| 97 | 104 | return CombinedStats{}, err |
|
| 98 | 105 | } |
|
| 99 | 106 | ||
| 107 | + | sysStats, err := getSystemStats() |
|
| 108 | + | if err != nil { |
|
| 109 | + | return CombinedStats{}, err |
|
| 110 | + | } |
|
| 111 | + | ||
| 100 | 112 | return CombinedStats{ |
|
| 101 | 113 | IPFSRepoStats: repoStats, |
|
| 102 | 114 | BandwidthStats: bwStats, |
|
| 115 | + | SystemStats: sysStats, |
|
| 103 | 116 | }, nil |
|
| 104 | 117 | } |
|
| 105 | 118 | ||
| 164 | 177 | } |
|
| 165 | 178 | ||
| 166 | 179 | c, err := cpu.Percent(0, false) |
|
| 180 | + | if err != nil { |
|
| 181 | + | return SystemStats{}, err |
|
| 182 | + | } |
|
| 183 | + | ||
| 184 | + | hostInfo, err := host.Info() |
|
| 167 | 185 | if err != nil { |
|
| 168 | 186 | return SystemStats{}, err |
|
| 169 | 187 | } |
|
| 170 | 188 | ||
| 171 | 189 | return SystemStats{ |
|
| 172 | 190 | CPUUsage: c[0], |
|
| 173 | - | MemoryUsage: v.UsedPercent, |
|
| 191 | + | MemoryUsed: v.Used, |
|
| 192 | + | MemoryTotal: v.Total, |
|
| 193 | + | OS: "Debian GNU/Linux 12 (bookworm) aarch64", |
|
| 194 | + | Kernel: hostInfo.KernelVersion, |
|
| 195 | + | Uptime: (time.Duration(hostInfo.Uptime) * time.Second).String(), |
|
| 196 | + | CPUModel: "BCM2835 (4) @ 1.800GHz", |
|
| 174 | 197 | }, nil |
|
| 175 | 198 | } |
|
| 199 | + | ||
| 200 | + | func formatBytes(bytes int64) string { |
|
| 201 | + | const unit = 1024 |
|
| 202 | + | if bytes < unit { |
|
| 203 | + | return fmt.Sprintf("%d B", bytes) |
|
| 204 | + | } |
|
| 205 | + | div, exp := int64(unit), 0 |
|
| 206 | + | for n := bytes / unit; n >= unit; n /= unit { |
|
| 207 | + | div *= unit |
|
| 208 | + | exp++ |
|
| 209 | + | } |
|
| 210 | + | return fmt.Sprintf("%.1f %ciB", float64(bytes)/float64(div), "KMGTPE"[exp]) |
|
| 211 | + | } |
|