Skip to content

Commit 972bf61

Browse files
Add uptime and load average
1 parent 8893c4e commit 972bf61

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ authors = ["Satoshi Terasaki <[email protected]>"]
44
version = "0.0.1"
55

66
[deps]
7+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
78
Term = "22787eb5-b846-44ae-b979-8e399b8463ab"
89
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
10+
11+
[compat]
12+
Dates = "1.11.0"

src/TerminalSystemMonitor.jl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module TerminalSystemMonitor
22

3+
using Dates: Dates, Day, DateTime, Second
34
using UnicodePlots
4-
using Term # this is required by UnicodePlots.panel
5+
import Term # this is required by UnicodePlots.panel
56

67
idle_time(info::Sys.CPUinfo) = Int64(info.cpu_times!idle)
78

@@ -72,14 +73,30 @@ function layout(x, y)
7273
barplot(x[c], y[c], maximum = 100, width = max(5, 15), height = length(c)),
7374
)
7475
end
75-
memoryusage = round((Sys.total_memory() - Sys.free_memory()) / 2^20 / 1000, digits = 1)
76+
memoryusageGB = round((Sys.total_memory() - Sys.free_memory()) / 2^30, digits = 1)
77+
memorytotGB = Sys.total_memory() / 2 ^ 30
78+
(memorytot, memoryusage, memoryunit) = if memorytotGB 1.0
79+
1024memorytotGB, 1024memoryusageGB, "MB"
80+
else
81+
memorytotGB, memoryusageGB, "GB"
82+
end
7683

84+
seconds = Sys.uptime()
85+
datetime = DateTime(1970) + Second(seconds)
7786
push!(
7887
plts,
7988
barplot(
8089
["Mem: "],
8190
[memoryusage],
82-
maximum = Sys.total_memory() / 2^20 / 1000,
91+
title= join(
92+
[
93+
"Load average: " * join(string.(round.(Sys.loadavg(), digits=2)),' '),
94+
" Uptime: $(max(Day(0), Day(datetime)-Day(1))), $(Dates.format(datetime, "HH:MM:SS"))",
95+
],
96+
'\n',
97+
),
98+
name="$(memorytot) $(memoryunit)",
99+
maximum = Sys.total_memory() / 2^30,
83100
width = max(5, 15),
84101
),
85102
)

0 commit comments

Comments
 (0)