Prometheus metrics
This commit is contained in:
parent
8eb1f47f2c
commit
b8007500e7
2 changed files with 41 additions and 0 deletions
38
handlers.go
38
handlers.go
|
@ -1,9 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/labstack/echo"
|
||||
"github.com/rosti-cz/node-api/apps"
|
||||
|
@ -485,3 +487,39 @@ func getAppProcessesHandler(c echo.Context) error {
|
|||
|
||||
return c.JSON(http.StatusOK, processes)
|
||||
}
|
||||
|
||||
// Return metrics that are available for running node
|
||||
func metricsHandler(c echo.Context) error {
|
||||
var metrics string
|
||||
|
||||
// Node indexes
|
||||
node, err := node.GetNodeInfo()
|
||||
if err != nil {
|
||||
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
|
||||
}
|
||||
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
|
||||
}
|
||||
|
||||
metrics += fmt.Sprintf("rosti_node_index{hostname=\"%s\"} %f\n", hostname, node.Index)
|
||||
metrics += fmt.Sprintf("rosti_node_disk_space_index{hostname=\"%s\"} %f\n", hostname, node.DiskSpaceIndex)
|
||||
metrics += fmt.Sprintf("rosti_node_load1_index{hostname=\"%s\"} %f\n", hostname, node.Load1Index)
|
||||
metrics += fmt.Sprintf("rosti_node_load5_index{hostname=\"%s\"} %f\n", hostname, node.Load5Index)
|
||||
metrics += fmt.Sprintf("rosti_node_load15_index{hostname=\"%s\"} %f\n", hostname, node.Load15Index)
|
||||
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 := apps.List()
|
||||
if err != nil {
|
||||
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
|
||||
}
|
||||
|
||||
for _, app := range *apps {
|
||||
metrics += fmt.Sprintf("rosti_node_app_disk_usage_bytes{hostname=\"%s\", app=\"%s\"} %d\n", hostname, app.Name, app.DiskUsageBytes)
|
||||
metrics += fmt.Sprintf("rosti_node_app_disk_usage_inodes{hostname=\"%s\", app=\"%s\"} %d\n", hostname, app.Name, app.DiskUsageInodes)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, metrics)
|
||||
}
|
||||
|
|
3
main.go
3
main.go
|
@ -55,6 +55,9 @@ func main() {
|
|||
// UI
|
||||
e.GET("/", homeHandler)
|
||||
|
||||
// Prometheus metrics
|
||||
e.GET("/metrics", metricsHandler)
|
||||
|
||||
// Returns list of apps
|
||||
e.GET("/v1/apps", listAppsHandler)
|
||||
|
||||
|
|
Loading…
Reference in a new issue