🔥 Removes prometheus metric exporting
This commit is contained in:
@@ -4,17 +4,29 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo-contrib/echoprometheus"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"github.com/labstack/gommon/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const TimeFormat = "2006-01-02 15:04:05"
|
||||
|
||||
// the condition is: distance >= threshold
|
||||
var value uint16 = 0
|
||||
var valueMutex sync.Mutex
|
||||
|
||||
type ReadReq struct {
|
||||
token string `body:"token"`
|
||||
}
|
||||
|
||||
type WriteReq struct {
|
||||
value uint16 `body:"value"`
|
||||
token string `body:"token"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := echo.New()
|
||||
app.Logger.SetLevel(log.INFO)
|
||||
@@ -60,22 +72,33 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
registry := prometheus.NewRegistry()
|
||||
counter := prometheus.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "custom_requests_total",
|
||||
Help: "How many HTTP requests processed, partitioned by status code and HTTP method.",
|
||||
},
|
||||
)
|
||||
if err := registry.Register(counter); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
app.GET("/", func(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, "Hello, World!")
|
||||
})
|
||||
|
||||
app.GET("/metrics", echoprometheus.NewHandlerWithConfig(echoprometheus.HandlerConfig{Gatherer: registry}))
|
||||
app.GET("/read", func(c echo.Context) error {
|
||||
var data ReadReq
|
||||
err := c.Bind(&data)
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, echo.Map{"value": value})
|
||||
})
|
||||
|
||||
app.POST("/write", func(c echo.Context) error {
|
||||
var data WriteReq
|
||||
err := c.Bind(&data)
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
valueMutex.Lock()
|
||||
value = data.value
|
||||
valueMutex.Unlock()
|
||||
|
||||
return c.NoContent(http.StatusOK)
|
||||
})
|
||||
|
||||
log.Fatal(app.Start(":1323"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user