From 0e14b82ddbca05553ad5f7e86cc3b17a3e7caf0f Mon Sep 17 00:00:00 2001 From: Eric Westphal Date: Mon, 16 Jan 2017 22:25:26 -0500 Subject: [PATCH] Show CPU load on UI status page. --- main/gen_gdl90.go | 11 ++++++++--- web/plates/js/status.js | 1 + web/plates/status.html | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main/gen_gdl90.go b/main/gen_gdl90.go index 98f2e4e5..86fdf261 100644 --- a/main/gen_gdl90.go +++ b/main/gen_gdl90.go @@ -717,11 +717,11 @@ func isCPUTempValid() bool { } /* - cpuTempMonitor() reads the RPi board temperature every second and updates it in globalStatus. + cpuMonitor() reads the RPi board temperature every second and updates it in globalStatus. This is broken out into its own function (run as its own goroutine) because the RPi temperature monitor code is buggy, and often times reading this file hangs quite some time. */ -func cpuTempMonitor() { +func cpuMonitor() { timer := time.NewTicker(1 * time.Second) for { <-timer.C @@ -744,6 +744,9 @@ func cpuTempMonitor() { globalStatus.CPUTemp = t } + // Update CPULoad. + data, err := ioutil.ReadFile("/proc/loadavg") + globalStatus.CPULoad = string(data[0:14]) } } @@ -1067,6 +1070,7 @@ type status struct { Uptime int64 UptimeClock time.Time CPUTemp float32 + CPULoad string NetworkDataMessagesSent uint64 NetworkDataMessagesSentNonqueueable uint64 NetworkDataBytesSent uint64 @@ -1200,6 +1204,7 @@ func printStats() { log.Printf("stats [started: %s]\n", humanize.RelTime(time.Time{}, stratuxClock.Time, "ago", "from now")) log.Printf(" - Disk bytes used = %s (%.1f %%), Disk bytes free = %s (%.1f %%)\n", humanize.Bytes(usage.Used()), 100*usage.Usage(), humanize.Bytes(usage.Free()), 100*(1-usage.Usage())) log.Printf(" - CPUTemp=%.02f deg C, MemStats.Alloc=%s, MemStats.Sys=%s, totalNetworkMessagesSent=%s\n", globalStatus.CPUTemp, humanize.Bytes(uint64(memstats.Alloc)), humanize.Bytes(uint64(memstats.Sys)), humanize.Comma(int64(totalNetworkMessagesSent))) + log.Printf(" - CPU load %s\n", globalStatus.CPULoad) log.Printf(" - UAT/min %s/%s [maxSS=%.02f%%], ES/min %s/%s, Total traffic targets tracked=%s", humanize.Comma(int64(globalStatus.UAT_messages_last_minute)), humanize.Comma(int64(globalStatus.UAT_messages_max)), float64(maxSignalStrength)/10.0, humanize.Comma(int64(globalStatus.ES_messages_last_minute)), humanize.Comma(int64(globalStatus.ES_messages_max)), humanize.Comma(int64(len(seenTraffic)))) log.Printf(" - Network data messages sent: %d total, %d nonqueueable. Network data bytes sent: %d total, %d nonqueueable.\n", globalStatus.NetworkDataMessagesSent, globalStatus.NetworkDataMessagesSentNonqueueable, globalStatus.NetworkDataBytesSent, globalStatus.NetworkDataBytesSentNonqueueable) if globalSettings.GPS_Enabled { @@ -1435,7 +1440,7 @@ func main() { go printStats() // Monitor RPi CPU temp. - go cpuTempMonitor() + go cpuMonitor() reader := bufio.NewReader(os.Stdin) diff --git a/web/plates/js/status.js b/web/plates/js/status.js index ca763245..b1b1dfed 100644 --- a/web/plates/js/status.js +++ b/web/plates/js/status.js @@ -62,6 +62,7 @@ function StatusCtrl($rootScope, $scope, $state, $http, $interval) { $scope.UAT_PIREP_total = status.UAT_PIREP_total; $scope.UAT_NOTAM_total = status.UAT_NOTAM_total; $scope.UAT_OTHER_total = status.UAT_OTHER_total; + $scope.CPULoad = status.CPULoad; // Errors array. if (status.Errors.length > 0) { $scope.visible_errors = true; diff --git a/web/plates/status.html b/web/plates/status.html index d0dac2b4..0ae62847 100644 --- a/web/plates/status.html +++ b/web/plates/status.html @@ -123,6 +123,10 @@ CPU Temp: {{CPUTemp}} +
+ CPU Load: + {{CPULoad}} +