3 Commits
Author SHA1 Message Date
aziis98 c86785ecdf feat: added temperature command 2023-12-27 23:30:47 +01:00
aziis98 7ff45091c7 fix: added attribution to various stuff 2023-12-25 10:23:18 +01:00
aziis98 994cff1190 chore: updated github workflow 2023-12-25 10:10:45 +01:00
3 changed files with 61 additions and 8 deletions
+3 -3
View File
@@ -12,12 +12,12 @@ jobs:
contents: write
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version-file: './go.mod'
- name: Build
run: |
+11
View File
@@ -11,6 +11,7 @@ The protocol supports the following commands:
- `network` — returns the network usage in bytes
- `storage` — returns the storage usage in GB
- `uptime` — returns the system uptime in seconds
- `temperature` — returns the CPU temperature of Big and Little cores in Celsius
[TODO: check if the command docs are correct]
@@ -74,3 +75,13 @@ $ time ( echo '<command>' | nc <node> 12345 )
# stop and disable the systemd service on all nodes
$ parallel --nonall --slf nodes.txt 'systemctl disable --now stats-server.service'
```
## Credits
- The shell code for the commands was originally made by [@BachoSeven](https://github.com/bachoseven)
<https://git.phc.dm.unipi.it/phc/cluster-dashboard/src/branch/main/backend/scripts>
- Most of the code was initially made with the help of ChatGPT in this conversation
<https://chat.openai.com/share/40247aa0-76e9-4d9a-b0fa-356a5f51f208>
+47 -5
View File
@@ -25,12 +25,54 @@ ExecStart=/usr/local/bin/stats-server serve
WantedBy=default.target
`)
// cmdStrHelper removes indentation and newlines from a shell command string for
// better readability.
//
// Precisely, it first trims the string, then splits it by newlines, then trims
// each line, then joins them back with a space.
func cmdStrHelper(command string) string {
lines := strings.Split(strings.TrimSpace(command), "\n")
for i, line := range lines {
lines[i] = strings.TrimSpace(line)
}
return strings.Join(lines, " ")
}
// commands is a map of commands that can be run on the server, originally made
// by @BachoSeven
var commands = map[string]string{
"cpu": `top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | sed "s/^/100 - /" | bc`,
"memory": `free -m | awk '/Mem/{print $3 " " $2}'`,
"network": `cat /sys/class/net/[e]*/statistics/{r,t}x_bytes`,
"storage": `df -Ph | grep mmcblk0p5 | awk '{print $2 " " $3}' | sed 's/G//g'`,
"uptime": `cut -f1 -d. /proc/uptime`,
"cpu": cmdStrHelper(`
top -bn1
| grep "Cpu(s)"
| sed "s/.*, *\([0-9.]*\)%* id.*/\1/"
| sed "s/^/100 - /"
| bc
`),
"memory": cmdStrHelper(`
free -m
| awk '/Mem/{print $3 " " $2}'
`),
"network": cmdStrHelper(`
cat /sys/class/net/[e]*/statistics/{r,t}x_bytes
`),
"storage": cmdStrHelper(`
df -Ph
| grep mmcblk0p5
| awk '{print $2 " " $3}'
| sed 's/G//g'
`),
"uptime": cmdStrHelper(`
cut -f1 -d. /proc/uptime
`),
"temperature": cmdStrHelper(`
paste
<(cat /sys/class/thermal/thermal_zone*/type)
<(awk
'{printf "%.3f\n", $1/1000}'
/sys/class/thermal/thermal_zone*/temp
)
`),
}
func init() {