-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadm_mnesia.ex
51 lines (41 loc) · 1.21 KB
/
adm_mnesia.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
defmodule ADM.MNESIA do
require NITRO
require Logger
def parse(_), do: []
def event(:init),
do:
[:user, :writers, :session, :enode]
|> Enum.map(fn x ->
[ :nitro.clear(x),
send(self(), {:direct, x})] end)
def event(:user),
do: :nitro.update(:user,
NITRO.span(body: parse(:n2o.user())))
def event(:session),
do: :nitro.update(:session,
NITRO.span(body: :n2o.sid()))
def event(:enode),
do: :nitro.update(:enode,
NITRO.span(body: :nitro.compact(:erlang.node())))
def event({:link, table}),
do: [
:nitro.clear(:feeds),
:ets.tab2list(table) |> Enum.map(fn t ->
:nitro.insert_bottom(:feeds,
NITRO.panel(body: :nitro.compact(t))) end)
]
def event(:writers),
do:
tables()
|> Enum.map(fn table ->
size = :mnesia.table_info(table, :size)
:nitro.insert_bottom(
:writers,
NITRO.panel(body:
[NITRO.link(body: :nitro.to_list(table), postback: {:link, table}),
' (' ++ :nitro.to_list(size) ++ ')']))
end)
def event(_), do: []
def tables(), do: :proplists.get_value(:tables, :mnesia.system_info(:all), [])
def ram(os), do: :nitro.compact(os)
end