Only show selected disks

This commit is contained in:
Mikko Ahlroth 2023-09-01 22:41:34 +03:00
parent 67abdef624
commit 7646c5ec3c
4 changed files with 31 additions and 23 deletions

View file

@ -16,7 +16,8 @@ config :tietopaketti,
uri: System.fetch_env!("INSTANCE_URI"),
name: System.fetch_env!("INSTANCE_NAME")
},
update_interval: String.to_integer(System.get_env("UPDATE_INTERVAL") || "2000")
update_interval: String.to_integer(System.get_env("UPDATE_INTERVAL") || "2000"),
disks_to_show: String.split(System.get_env("DISKS_TO_SHOW", ""), ",")
# ## Using releases
#

View file

@ -14,7 +14,8 @@ defmodule Tietopaketti.Application do
%Tietopaketti.Sysmon.Options{
name: Tietopaketti.Sysmon,
pubsub_name: Tietopaketti.PubSub,
update_interval: Application.fetch_env!(:tietopaketti, :update_interval)
update_interval: Application.fetch_env!(:tietopaketti, :update_interval),
disks_to_show: MapSet.new(Application.fetch_env!(:tietopaketti, :disks_to_show))
}},
# Start the Endpoint (http/https)
TietopakettiWeb.Endpoint

View file

@ -7,14 +7,16 @@ defmodule Tietopaketti.Sysmon do
deftypedstruct(%{
name: GenServer.name(),
pubsub_name: GenServer.name(),
update_interval: non_neg_integer()
update_interval: non_neg_integer(),
disks_to_show: MapSet.t(String.t())
})
end
defmodule State do
deftypedstruct(%{
pubsub_name: GenServer.name(),
update_interval: non_neg_integer()
update_interval: non_neg_integer(),
disks_to_show: MapSet.t(String.t())
})
end
@ -33,7 +35,8 @@ defmodule Tietopaketti.Sysmon do
{:ok,
%State{
pubsub_name: opts.pubsub_name,
update_interval: opts.update_interval
update_interval: opts.update_interval,
disks_to_show: opts.disks_to_show
}}
end
@ -53,6 +56,7 @@ defmodule Tietopaketti.Sysmon do
disk_data =
:disksup.get_disk_data()
|> Enum.filter(fn {name, _, _} -> MapSet.member?(state.disks_to_show, name) end)
|> Enum.with_index()
|> Enum.map(fn {{name, total, used}, i} ->
%Sysdata.Disk{id: i, name: name, total: total, used_percent: used}

View file

@ -47,22 +47,24 @@
</div>
</div>
<div id="disks">
<h2>Disks</h2>
<%= for disk <- @sysdata.disk do %>
<div class="disk">
<.live_component
module={TietopakettiWeb.Progress}
id={"disk-progress-#{disk.id}"}
label={disk.name}
value={disk.used_percent}
max={100}
value-display={"#{disk.used_percent} % of #{humanize_size_si(
disk.total * 1024,
true
)}"}
/>
</div>
<% end %>
</div>
<%= if @sysdata.disk != [] do %>
<div id="disks">
<h2>Disks</h2>
<%= for disk <- @sysdata.disk do %>
<div class="disk">
<.live_component
module={TietopakettiWeb.Progress}
id={"disk-progress-#{disk.id}"}
label={disk.name}
value={disk.used_percent}
max={100}
value-display={"#{disk.used_percent} % of #{humanize_size_si(
disk.total * 1024,
true
)}"}
/>
</div>
<% end %>
</div>
<% end %>
<% end %>