Making metrics faster
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Adam Štrauch 2022-05-06 18:40:22 +02:00
parent 35a0c5acd1
commit 68121fda15
Signed by: cx
GPG Key ID: 018304FFA8988F8D
3 changed files with 18 additions and 15 deletions

View File

@ -102,9 +102,11 @@ func (p *Processor) waitForApp() error {
}
// List returns list of apps
func (p *Processor) List() (apps.Apps, error) {
// noUpdate skips stats gathering to speed things up
func (p *Processor) List(noUpdate bool) (apps.Apps, error) {
appList := apps.Apps{}
if !noUpdate {
statsProcessor := StatsProcessor{
DB: p.DB,
DockerSock: p.DockerSock,
@ -117,9 +119,10 @@ func (p *Processor) List() (apps.Apps, error) {
if err != nil {
return appList, fmt.Errorf("backend error: %v", err)
}
}
processor := p.getAppProcessor()
appList, err = processor.List()
appList, err := processor.List()
if err != nil {
return appList, fmt.Errorf("backend error: %v", err)

View File

@ -29,7 +29,7 @@ func listAppsHandler(c echo.Context) error {
AppsPath: config.AppsPath,
}
applications, err := processor.List()
applications, err := processor.List(false)
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
@ -430,7 +430,7 @@ func metricsHandler(c echo.Context) error {
metrics += fmt.Sprintf("rosti_node_memory_index{hostname=\"%s\"} %f\n", hostname, node.MemoryIndex)
metrics += fmt.Sprintf("rosti_node_sold_memory{hostname=\"%s\"} %d\n", hostname, node.SoldMemory)
apps, err := processor.List()
apps, err := processor.List(true)
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}

View File

@ -101,7 +101,7 @@ func listEventHandler(m *nats.Msg, message *RequestMessage) error {
AppsPath: config.AppsPath,
}
applications, err := processor.List()
applications, err := processor.List(false)
if err != nil {
return errorReplyFormater(m, "backend error", err)
}