From 8eb1f47f2c7c7d74e24630cd10af87937055e605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Fri, 2 Apr 2021 18:10:34 +0200 Subject: [PATCH] Various changes * Stop using docker stats API (no replacement yet) * Ruby and Deno support * Meassure how much time stats loading takes --- api.http | 18 +++++++----------- docker/types.go | 17 ++++++++++------- handlers.go | 14 ++++++++++++++ main.go | 6 +++++- types.go | 2 ++ 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/api.http b/api.http index 75e4d6b..d608399 100644 --- a/api.http +++ b/api.http @@ -3,7 +3,7 @@ Authorization: Token fee60059-f554-4c35-b44f-74b6be377095 Content-type: application/json { - "name": "test_1235", + "name": "test_1234", "ssh_port": 46502, "http_port": 46503, "image": "docker.io/rosti/runtime:2020.04-1", @@ -27,7 +27,7 @@ Content-type: application/json # Start -PUT http://localhost:1323/v1/apps/test_1234/start +PUT http://localhost:1323/v1/apps/test_4567/start Content-type: application/json ### @@ -50,15 +50,14 @@ Authorization: Token fee60059-f554-4c35-b44f-74b6be377095 # Delete of app -DELETE http://localhost:1323/v1/apps/test_1234 +DELETE http://localhost:1323/v1/apps/test_4567 Content-type: application/json ### -# Stats +# Processes -GET http://localhost:1323/v1/apps/test_1234/stats -Content-type: application/json +GET http://localhost:1323/v1/apps/test_1234/processes ### @@ -99,10 +98,7 @@ Content-type: application/json # Set password -PUT http://localhost:1323/v1/apps/test_1235/keys +PUT http://localhost:1323/v1/apps/test_1234/keys Content-type: application/json -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmgl6/h44nBJciIX2xTO2ABzDDIU0apHQz6p8uLG2o4DBOXj4iVP5/kwTjcwQAJQBeqEHtjetnnamWbrChh8vu9VeIC8UIUpcf/iFKfhXZq3tJDXDLfiGsN/L/LmbsjhW84QRms0pUp9qV+wGP5+L7Qyws8NKFaODmK/FUFhanFhF2JxzAeMu492HvmfWmpDb0MdD8MwV58NAyd1N+ygh+QiirFx/NzFPWtQZpvBZvxCgtdNi9X6ajmYcvLregtovXQh4vwSGrNqpA5yyyNcR/JdsH2nqmUfsFo9mGs5et2s+TiZweGObsJBHX1dl4bV3oMPvtwh1zjA903jmQ0Bab cx@bimbo -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmgl6/h44nBJciIX2xTO2ABzDDIU0apHQz6p8uLG2o4DBOXj4iVP5/kwTjcwQAJQBeqEHtjetnnamWbrChh8vu9VeIC8UIUpcf/iFKfhXZq3tJDXDLfiGsN/L/LmbsjhW84QRms0pUp9qV+wGP5+L7Qyws8NKFaODmK/FUFhanFhF2JxzAeMu492HvmfWmpDb0MdD8MwV58NAyd1N+ygh+QiirFx/NzFPWtQZpvBZvxCgtdNi9X6ajmYcvLregtovXQh4vwSGrNqpA5yyyNcR/JdsH2nqmUfsFo9mGs5et2s+TiZweGObsJBHX1dl4bV3oMPvtwh1zjA903jmQ0Bab cx@bimbo - - +testrr diff --git a/docker/types.go b/docker/types.go index 205645d..c5cb851 100644 --- a/docker/types.go +++ b/docker/types.go @@ -53,10 +53,11 @@ func (c *Container) GetState() (*apps.AppState, error) { return nil, err } - cpu, memory, err := c.ResourceUsage() - if err != nil { - return nil, err - } + // TODO: this implementation takes more than one hour for 470 containers. It needs to be implemented differently. + // cpu, memory, err := c.ResourceUsage() + // if err != nil { + // return nil, err + // } bytes, inodes, err := c.DiskUsage() if err != nil { @@ -64,9 +65,11 @@ func (c *Container) GetState() (*apps.AppState, error) { } state := apps.AppState{ - State: status, - CPUUsage: cpu, - MemoryUsage: memory, + State: status, + // CPUUsage: cpu, + // MemoryUsage: memory, + CPUUsage: -1.0, + MemoryUsage: -1.0, DiskUsageBytes: bytes, DiskUsageInodes: inodes, } diff --git a/handlers.go b/handlers.go index 0d5dea3..83259cc 100644 --- a/handlers.go +++ b/handlers.go @@ -312,6 +312,20 @@ func setServicesHandler(c echo.Context) error { } } + if quickServices.Ruby { + err = container.SetTechnology("ruby") + if err != nil { + return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent) + } + } + + if quickServices.Deno { + err = container.SetTechnology("deno") + if err != nil { + return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent) + } + } + if quickServices.Memcached { err = container.SetTechnology("memcached") if err != nil { diff --git a/main.go b/main.go index 61195f8..853f3a4 100644 --- a/main.go +++ b/main.go @@ -23,11 +23,15 @@ func main() { // Stats loop go func() { for { + log.Println("Stats gathering started") + start := time.Now() err := gatherStats() if err != nil { log.Println("LOOP ERROR:", err.Error()) } - time.Sleep(5 * time.Minute) + elapsed := time.Since(start) + log.Printf("Stats gathering elapsed time: %.2fs\n", elapsed.Seconds()) + time.Sleep(30 * time.Second) } }() diff --git a/types.go b/types.go index d87aef8..3844a9c 100644 --- a/types.go +++ b/types.go @@ -29,6 +29,8 @@ type QuickServices struct { Python bool `json:"python"` Node bool `json:"node"` PHP bool `json:"php"` + Ruby bool `json:"ruby"` + Deno bool `json:"deno"` Memcached bool `json:"memcached"` Redis bool `json:"redis"` }