-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitoringactiveinstance.lua
68 lines (61 loc) · 2.14 KB
/
monitoringactiveinstance.lua
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
ActiveInstanceContainers = {}
EmptyContainerSpace = {}
-- updateContainer accepts 3 different states: running, stopped, created
-- sometimes "start" events arrive before "create" ones
-- in this case, we just ignore the update
function updateActiveInstanceContainer(id,name,realname,state)
LOG("Update container with ID: " .. id .. " state: " .. tostring(state))
-- first pass, to see if the container is
-- already displayed (maybe with another state)
for i=1, table.getn(ActiveInstanceContainers)
do
-- if container found with same ID, we update it
if ActiveInstanceContainers[i] ~= EmptyContainerSpace and ActiveInstanceContainers[i].id == id
then
ActiveInstanceContainers[i]:setInfos(id,name,realname,state)
ActiveInstanceContainers[i]:display(state)
LOG("found. updated. now return")
return
end
end
-- if container isn't already displayed, we see if there's an empty space
-- in the world to display the container
local x = ACTIVE_CONTAINER_START_X
local index = -1
for i=1, table.getn(ActiveInstanceContainers)
do
-- use first empty location
if ActiveInstanceContainers[i] == EmptyContainerSpace
then
LOG("Found empty location: ActiveInstanceContainers[" .. tostring(i) .. "]")
index = i
break
end
x = x + ACTIVE_CONTAINER_OFFSET_X
end
LOG("create a new active server container")
local container = NewActiveInstanceContainer()
container:init(x,ACTIVE_CONTAINER_START_Z)
container:setInfos(id,name,realname,true)
container:addGround()
container:display(true)
if index == -1
then
table.insert(ActiveInstanceContainers, container)
else
ActiveInstanceContainers[index] = container
end
end
-- updateStats update CPU and memory usage displayed
-- on container sign (container identified by id)
function updateActiveInstanceStats(id, cap, a)
for i=1, table.getn(ActiveInstanceContainers)
do
if ActiveInstanceContainers[i] ~= EmptyContainerSpace and ActiveInstanceContainers[i].id == id
then
ActiveInstanceContainers[i]:updateCapacitySign(cap)
ActiveInstanceContainers[i]:updateAvailabilitySign(a)
break
end
end
end