-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade /programs, add desksaver #171
Closed
Closed
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
aa3e414
Add static /programs upgrade; todo: live sync with ws
cwervo dba0cf5
Add program watchdog and equivalent web endpoint
cwervo dc23e73
Add resource usage claims, broken HTML display for them
cwervo 291efbe
Add refactor note
cwervo 98fe1f6
Add basic desksaver
cwervo cc2fd3a
Add full-fledged desksaver
cwervo 586819b
Merge branch 'main' into ac/desksaver
cwervo 3ed5af5
Fix variable substitutions in resource webpage
cwervo dcc4c09
Center desksaver message
cwervo 8b898f2
Fix categorization of live-build page, fix RAM reporting
cwervo fac2f9b
Avoid loading desksaver before screen init
cwervo 8410b98
Merge remote-tracking branch 'origin/main' into ac/desksaver
cwervo bfc6c9e
Move server route handling to folk files
cwervo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
set ::watchdog_debug 0 | ||
|
||
When the collected matches for [list /someone/ claims /page/ has program /program/] are /matches/ & the clock time is /t/ { | ||
# Analyze the matches, watch for non-virtual programs | ||
set webPrograms [list] | ||
set realPrograms [list] | ||
foreach match $matches { | ||
set page [dict get $match page] | ||
switch -glob $page { | ||
"virtual-programs/*" { | ||
continue; | ||
} | ||
"setup.folk.default" { | ||
continue; | ||
} | ||
"web-program-*" { | ||
lappend webPrograms $page | ||
} | ||
default { | ||
lappend realPrograms $page | ||
} | ||
} | ||
} | ||
|
||
Claim there are [llength $webPrograms] web programs | ||
Claim there are [llength $realPrograms] real programs | ||
} | ||
|
||
When the clock time is /t/ { | ||
# Monitor RAM, CPU, and disk usage | ||
set ramInfo [exec free -m] | ||
set lines [split $ramInfo "\n"] | ||
set memLine [lindex $lines 1] | ||
set memParts [regexp -all -inline {\S+} $memLine] | ||
set totalMem [lindex $memParts 1] | ||
set usedMem [lindex $memParts 2] | ||
set freeMem [lindex $memParts 3] | ||
|
||
if {$::watchdog_debug} { | ||
puts "Total Memory: $totalMem MB" | ||
puts "Used Memory: $usedMem MB" | ||
puts "Free Memory: $freeMem MB" | ||
} | ||
|
||
set ramUsage [expr {$usedMem / $totalMem * 100}] | ||
|
||
if {$::watchdog_debug} { | ||
puts "RAM Usage: $ramUsage%" | ||
} | ||
|
||
# Calculate CPU usage | ||
set cpuInfo [exec top -bn1 | grep "Cpu(s)"] | ||
set cpuUsage [lindex [regexp -all -inline {\d+\.\d+} $cpuInfo] 0] | ||
|
||
if {$::watchdog_debug} { | ||
puts "CPU Usage: $cpuUsage%" | ||
} | ||
|
||
# Calculate disk usage | ||
set dfOutput [exec df -h /] | ||
set diskLine [lindex [split $dfOutput "\n"] 1] | ||
set diskParts [regexp -all -inline {\S+} $diskLine] | ||
set diskUsage [string map {% {}} [lindex $diskParts 4]] | ||
|
||
if {$::watchdog_debug} { | ||
puts "Disk Usage: $diskUsage%" | ||
} | ||
|
||
Claim RAM usage is $ramUsage | ||
Claim CPU usage is $cpuUsage | ||
Claim disk usage is $diskUsage | ||
|
||
# # Check for high resource usage and make warnings if necessary | ||
if {$ramUsage > 90} { | ||
Claim $this has warning"High RAM usage: $ramUsage MB" | ||
} | ||
if {$cpuUsage > 80} { | ||
Claim $this has warning "High CPU usage: $cpuUsage%" | ||
} | ||
if {$diskUsage > 90} { | ||
Claim $this has warning "High disk usage: $diskUsage%" | ||
} | ||
} | ||
|
||
Wish the web server handles route "/resource-usage" with handler { | ||
set ramUsage 0 | ||
set cpuUsage 0 | ||
set diskUsage 0 | ||
|
||
When /someone/ claims RAM usage is /ramUsage/ & /someone/ claims CPU usage is /cpuUsage/ & /someone/ claims disk usage is /diskUsage/ { | ||
set ramUsage $ramUsage | ||
set cpuUsage $cpuUsage | ||
set diskUsage $diskUsage | ||
} | ||
|
||
html { | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="/style.css"> | ||
<title>Statements</title> | ||
</head> | ||
<body> | ||
<nav> | ||
<a href="/new"><button>New program</button></a> | ||
<a href="/programs">Running programs</a> | ||
<a href="/timings">Timings</a> | ||
<a href="/keyboards">Keyboards</a> | ||
<a href="/statementClauseToId.pdf">statementClauseToId graph</a> | ||
<a href="/statements.pdf">statements graph</a> | ||
</nav> | ||
<h1>Resource Usage</h1> | ||
<div> | ||
<!-- TODO: how to subs the real values into the html proc? --> | ||
<p>RAM Usage: $ramUsage %</p> | ||
<p>CPU Usage: $cpuUsage %</p> | ||
<p>Disk Usage: $diskUsage %</p> | ||
</div> | ||
</body> | ||
</html> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I'm missing something @osnr ... when I use
subst
here instead ofhtml
the page doesn't render at all,html
doesn't fill in the$.*Usage
variables though.