-
Notifications
You must be signed in to change notification settings - Fork 3
/
account_usage.ml
367 lines (365 loc) · 17 KB
/
account_usage.ml
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
let account_usage_layout policy unikernels blocks =
let deployed_unikernels = List.length unikernels in
let total_volume_used =
List.fold_left (fun total_size (_, size, _) -> total_size + size) 0 blocks
in
let total_free_space =
Option.value ~default:0 policy.Vmm_core.Policy.block - total_volume_used
in
let total_memory_used =
List.fold_left
(fun total_memory (_, unikernel) ->
total_memory + unikernel.Vmm_core.Unikernel.memory)
0 unikernels
in
let count_cpuid_usage =
let cpuid_count = Hashtbl.create (List.length unikernels) in
(* count usage of each cpuid in unikernels *)
List.iter
(fun (_, unikernel) ->
let cpuid = unikernel.Vmm_core.Unikernel.cpuid in
let count =
Hashtbl.find_opt cpuid_count cpuid |> Option.value ~default:0
in
Hashtbl.replace cpuid_count cpuid (count + 1))
unikernels;
(* Prepare list of all cpuids from policy *)
let policy_cpuids = Vmm_core.IS.elements policy.cpuids in
(* Generate the list with all policy.cpuids and their respective counts *)
List.map
(fun cpuid ->
let count =
Hashtbl.find_opt cpuid_count cpuid |> Option.value ~default:0
in
(cpuid, count))
policy_cpuids
in
let count_bridge_usage =
let bridge_count =
Hashtbl.create (Vmm_core.String_set.cardinal policy.bridges)
in
(* Initialize all policy bridges with a count of 0 *)
Vmm_core.String_set.iter
(fun bridge -> Hashtbl.replace bridge_count bridge 0)
policy.bridges;
(* Count each bridge usage from unikernel.bridges, but only if it's in policy.bridges *)
List.iter
(fun (_, unikernel) ->
List.iter
(fun (name, bridge, _) ->
let bridge_name = Option.value bridge ~default:name in
(* Only count if the bridge is in policy.bridges *)
if Vmm_core.String_set.mem bridge_name policy.bridges then
let count =
Hashtbl.find_opt bridge_count bridge_name
|> Option.value ~default:0
in
Hashtbl.replace bridge_count bridge_name (count + 1))
unikernel.Vmm_core.Unikernel.bridges)
unikernels;
(* Convert the hash table to a sorted list of (bridge_name, count) *)
let bridge_usage_list =
Hashtbl.fold
(fun bridge count acc -> (bridge, count) :: acc)
bridge_count []
in
(* Sort the list by bridge name *)
List.sort (fun (b1, _) (b2, _) -> String.compare b1 b2) bridge_usage_list
in
Tyxml_html.(
section
~a:[ a_class [ "col-span-7 p-4 bg-gray-50 my-1" ] ]
[
h1 ~a:[ a_class [ "text-3xl font-bold" ] ] [ txt "Resources" ];
section
~a:[ a_id "usage-display"; a_class [ "grid grid-cols-3 gap-4" ] ]
[
div
~a:[ a_class [ "mx-auto text-center my-4" ] ]
[
h1
~a:[ a_class [ "text-xl font-bold" ] ]
[ txt "Number of Unikernels" ];
div
~a:
[
Unsafe.string_attrib "x-data" "chart: null";
Unsafe.string_attrib "x-init"
("\n\
\ chart = new \
Chart(document.getElementById('unikernelChart').getContext('2d'), \
{\n\
\ type: 'pie',\n\
\ data: {\n\
\ labels: ['Available ("
^ string_of_int (policy.unikernels - deployed_unikernels)
^ ")','Running ("
^ string_of_int deployed_unikernels
^ ")'],\n\
\ datasets: [{\n\
\ label: 'Allocated',\n\
\ data: ["
^ string_of_int (policy.unikernels - deployed_unikernels)
^ ", "
^ string_of_int deployed_unikernels
^ "],\n\
\ backgroundColor: ['rgb(156, \
156, 156)','rgb(54, 156, 140)'],\n\
\ hoverOffset: 4,\n\
\ }]\n\
\ },\n\
\ options: {}\n\
\ });\n\
\ ");
a_class [ "flex justify-center items-center" ];
]
[ canvas ~a:[ a_id "unikernelChart" ] [] ];
];
div
~a:[ a_class [ "mx-auto text-center my-4" ] ]
[
h1 ~a:[ a_class [ "text-xl font-bold" ] ] [ txt "Storage" ];
div
~a:
[
Unsafe.string_attrib "x-data" "chart: null";
Unsafe.string_attrib "x-init"
("\n\
\ chart = new \
Chart(document.getElementById('storageChart').getContext('2d'), \
{\n\
\ type: 'pie',\n\
\ data: {\n\
\ labels: ['Free ("
^ string_of_int total_free_space
^ "MB)','Used ("
^ string_of_int total_volume_used
^ "MB)'],\n\
\ datasets: [{\n\
\ label: 'Size',\n\
\ data: ["
^ string_of_int total_free_space
^ ", "
^ string_of_int total_volume_used
^ "],\n\
\ backgroundColor: ['rgb(156, \
156, 156)','rgb(54, 156, 140)'],\n\
\ hoverOffset: 4,\n\
\ }]\n\
\ },\n\
\ options: {}\n\
\ });\n\
\ ");
a_class [ "flex justify-center items-center" ];
]
[ canvas ~a:[ a_id "storageChart" ] [] ];
];
div
~a:[ a_class [ "mx-auto text-center my-4" ] ]
[
h1 ~a:[ a_class [ "text-xl font-bold" ] ] [ txt "Memory" ];
div
~a:
[
Unsafe.string_attrib "x-data" "chart: null";
Unsafe.string_attrib "x-init"
("\n\
\ chart = new \
Chart(document.getElementById('memoryChart').getContext('2d'), \
{\n\
\ type: 'pie',\n\
\ data: {\n\
\ labels: ['Free ("
^ string_of_int (policy.memory - total_memory_used)
^ "MB)','Assigned ("
^ string_of_int total_memory_used
^ "MB)'],\n\
\ datasets: [{\n\
\ label: 'Allocated',\n\
\ data: ["
^ string_of_int (policy.memory - total_memory_used)
^ ", "
^ string_of_int total_memory_used
^ "],\n\
\ backgroundColor: ['rgb(156, \
156, 156)','rgb(54, 156, 140)'],\n\
\ hoverOffset: 4,\n\
\ }]\n\
\ },\n\
\ options: {}\n\
\ });\n\
\ ");
a_class [ "flex justify-center items-center" ];
]
[ canvas ~a:[ a_id "memoryChart" ] [] ];
];
];
section
~a:[ a_id "cpu-display"; a_class [ "block" ] ]
[
div
~a:[ a_class [ "mx-auto text-center my-4 mx-4" ] ]
[
h1
~a:[ a_class [ "text-xl font-bold" ] ]
[ txt "CPU ID usage in Unikernels" ];
div
~a:
[
Unsafe.string_attrib "x-data" "chart: null";
Unsafe.string_attrib "x-init"
("\n\
\ chart = new \
Chart(document.getElementById('cpuChart').getContext('2d'), \
{\n\
\ type: 'bar',\n\
\ data: {\n\
\ labels: [\n\
\ "
^ String.concat ", "
(List.map
(fun id -> "\"" ^ string_of_int id ^ "\"")
(Vmm_core.IS.elements policy.cpuids))
^ "\n\
\ ],\n\
\ datasets: [{\n\
\ label: 'Usage count',\n\
\ data: [\n\
\ "
^ String.concat ", "
(List.map
(fun (_, count) ->
"\"" ^ string_of_int count ^ "\"")
count_cpuid_usage)
^ "\n\
\ ],\n\
\ backgroundColor: \
['rgb(54, 156, 140)'],\n\
\ hoverOffset: 4\n\
\ }]\n\
\ },\n\
\ options: {\n\
\ scales: {\n\
\ x: {\n\
\ title: {\n\
\ display: true,\n\
\ text: 'CPU ID'\n\
\ }\n\
\ },\n\
\ y: {\n\
\ title: {\n\
\ display: true,\n\
\ text: 'Number \
of Unikernels'\n\
\ },\n\
\ ticks: {\n\
\ stepSize: 1,\n\
\ callback: \
function(value) {\n\
\ if \
(Number.isInteger(value)) {\n\
\ return value;\n\
\ }\n\
\ return null;\n\
\ }\n\
\ },\n\
\ beginAtZero: true\n\
\ }\n\
\ }\n\
\ }\n\
\ });\n\
\ ");
a_class [ "flex justify-center items-center" ];
]
[
div
~a:
[
a_class [ "chart-container" ];
a_style "position:relative; height:40vh; width:80vh;";
]
[ canvas ~a:[ a_id "cpuChart" ] [] ];
];
];
div
~a:[ a_class [ "mx-auto text-center my-4 mx-4" ] ]
[
h1
~a:[ a_class [ "text-xl font-bold" ] ]
[ txt "Bridge usage in Unikernels" ];
div
~a:
[
Unsafe.string_attrib "x-data" "chart: null";
Unsafe.string_attrib "x-init"
("\n\
\ chart = new \
Chart(document.getElementById('bridgeChart').getContext('2d'), \
{\n\
\ type: 'bar',\n\
\ data: {\n\
\ labels: [\n\
\ "
^ String.concat ", "
(List.map
(fun bridge -> "\"" ^ bridge ^ "\"")
(Vmm_core.String_set.elements policy.bridges))
^ "\n\
\ ],\n\
\ datasets: [{\n\
\ label: 'Usage Count',\n\
\ data: [\n\
\ "
^ String.concat ", "
(List.map
(fun (_, count) ->
"\"" ^ string_of_int count ^ "\"")
count_bridge_usage)
^ "\n\
\ ],\n\
\ backgroundColor: ['rgb(54, 156, 140)'],\n\
\ hoverOffset: 4\n\
\ }]\n\
\ },\n\
\ options: {\n\
\ scales: {\n\
\ x: {\n\
\ title: {\n\
\ display: true,\n\
\ text: 'Bridge Name'\n\
\ }\n\
\ },\n\
\ y: {\n\
\ title: {\n\
\ display: true,\n\
\ text: 'Number of Unikernels'\n\
\ },\n\
\ ticks: {\n\
\ stepSize: 1,\n\
\ callback: function(value) {\n\
\ if (Number.isInteger(value)) {\n\
\ return value;\n\
\ }\n\
\ return null;\n\
\ }\n\
\ },\n\
\ beginAtZero: true\n\
\ }\n\
\ }\n\
\ }\n\
\ });\n\
\ ");
a_class [ "flex justify-center items-center" ];
]
[
div
~a:
[
a_class [ "chart-container" ];
a_style "position:relative; height:40vh; width:80vh;";
]
[ canvas ~a:[ a_id "bridgeChart" ] [] ];
];
];
];
])