-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_history.lua
More file actions
78 lines (66 loc) · 1.84 KB
/
Copy pathdata_history.lua
File metadata and controls
78 lines (66 loc) · 1.84 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- SPDX-FileCopyrightText: Robert Ryszard Paciorek <rrp@opcode.eu.org>
-- SPDX-License-Identifier: MIT
require "stats_read"
require "hwmon_read"
---------------------------------
--- Stats collect globals ---
---------------------------------
if not HIST_SIZE then
HIST_SIZE = 30
end
HIST_INOUT_SIZE = HIST_SIZE // 2
mem_total = 1
hist_cpu = {}
hist_mem = {}
hist_mem_with_buf = {}
hist_down = {}
hist_up = {}
hist_rd = {}
hist_wr = {}
hist_ptr = 1
hist_ptr_inout = 1
-----------------------------------
--- Stats collect functions ---
-----------------------------------
function update_data(full)
hist_ptr = hist_ptr + 1
if hist_ptr > HIST_SIZE then hist_ptr = 1 end
hist_cpu[hist_ptr] = get_cpu_stats()
hist_mem[hist_ptr], hist_mem_with_buf[hist_ptr] = get_mem_stats()
if full then
hist_ptr_inout = hist_ptr_inout + 1
if hist_ptr_inout > HIST_INOUT_SIZE then hist_ptr_inout = 1 end
-- in/out (network and disks) data is collected twice less frequently,
-- because we the same width of graph and place up and down data on the same graph
hist_down[hist_ptr_inout], hist_up[hist_ptr_inout] = get_net_stats(1, NETDEV)
hist_rd[hist_ptr_inout], hist_wr[hist_ptr_inout] = get_disk_stats(1, DISKDEV)
-- sensors data are read twice less frequently also, but with some exception ...
read_hwmon_all()
hist_gpu[hist_ptr] = hwmon.gpu.power.ppt.fval
else
hist_gpu[hist_ptr] = read_hwmon(hwmon.gpu.power.ppt) * 0.000001
end
end
function init_stats()
-- init history tables
for i = 1, HIST_SIZE do
hist_cpu[i] = 0
hist_mem[i] = 0
hist_mem_with_buf[i] = 0
end
for i = 1, HIST_INOUT_SIZE do
hist_down[i] = 0
hist_up[i] = 0
hist_rd[i] = 0
hist_wr[i] = 0
end
-- init cpu and net stat
get_cpu_stats()
init_net_stats(NETDEV)
init_disk_stats(DISKDEV)
end
----------------
--- Init ---
----------------
init_stats()
init_hwmon()