Making metrics faster
This commit is contained in:
		
							parent
							
								
									35a0c5acd1
								
							
						
					
					
						commit
						68121fda15
					
				
					 3 changed files with 18 additions and 15 deletions
				
			
		
							
								
								
									
										27
									
								
								glue/main.go
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								glue/main.go
									
									
									
									
									
								
							|  | @ -102,24 +102,27 @@ func (p *Processor) waitForApp() error { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // List returns list of apps
 | // 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{} | 	appList := apps.Apps{} | ||||||
| 
 | 
 | ||||||
| 	statsProcessor := StatsProcessor{ | 	if !noUpdate { | ||||||
| 		DB:         p.DB, | 		statsProcessor := StatsProcessor{ | ||||||
| 		DockerSock: p.DockerSock, | 			DB:         p.DB, | ||||||
| 		BindIPHTTP: p.BindIPHTTP, | 			DockerSock: p.DockerSock, | ||||||
| 		BindIPSSH:  p.BindIPSSH, | 			BindIPHTTP: p.BindIPHTTP, | ||||||
| 		AppsPath:   p.AppsPath, | 			BindIPSSH:  p.BindIPSSH, | ||||||
| 	} | 			AppsPath:   p.AppsPath, | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 	err := statsProcessor.GatherStates() | 		err := statsProcessor.GatherStates() | ||||||
| 	if err != nil { | 		if err != nil { | ||||||
| 		return appList, fmt.Errorf("backend error: %v", err) | 			return appList, fmt.Errorf("backend error: %v", err) | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	processor := p.getAppProcessor() | 	processor := p.getAppProcessor() | ||||||
| 	appList, err = processor.List() | 	appList, err := processor.List() | ||||||
| 
 | 
 | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return appList, fmt.Errorf("backend error: %v", err) | 		return appList, fmt.Errorf("backend error: %v", err) | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ func listAppsHandler(c echo.Context) error { | ||||||
| 		AppsPath:   config.AppsPath, | 		AppsPath:   config.AppsPath, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	applications, err := processor.List() | 	applications, err := processor.List(false) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent) | 		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_memory_index{hostname=\"%s\"} %f\n", hostname, node.MemoryIndex) | ||||||
| 	metrics += fmt.Sprintf("rosti_node_sold_memory{hostname=\"%s\"} %d\n", hostname, node.SoldMemory) | 	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 { | 	if err != nil { | ||||||
| 		return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent) | 		return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -101,7 +101,7 @@ func listEventHandler(m *nats.Msg, message *RequestMessage) error { | ||||||
| 		AppsPath:   config.AppsPath, | 		AppsPath:   config.AppsPath, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	applications, err := processor.List() | 	applications, err := processor.List(false) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return errorReplyFormater(m, "backend error", err) | 		return errorReplyFormater(m, "backend error", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue