forked from jriou/coller
feat: Add metrics
Fixes #7. Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
e486d3df98
commit
0ce540e92d
7 changed files with 141 additions and 18 deletions
|
@ -27,5 +27,9 @@ The file format is **JSON**:
|
|||
* **expiration** (int): Default expiration time in seconds
|
||||
* **max_upload_size** (int): Maximum number of bytes received by the server for notes (the base64 encoding may use more space than the real size of the note)
|
||||
* **show_version** (bool): Show version on the website
|
||||
* **enable_metrics** (bool): Enable Prometheus endpoint (default false)
|
||||
* **prometheus_route** (string): Route to expose Prometheus metrics (default "/metrics")
|
||||
* **prometheus_notes_metric** (string): Name of the notes count metric (default "collerd_notes")
|
||||
* **observation_internal** (int): Number of seconds to wait between two observations (default 60)
|
||||
|
||||
The configuration file is not required but the service might not be exposed to the public.
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"git.riou.xyz/jriou/coller/internal"
|
||||
"git.riou.xyz/jriou/coller/server"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -75,6 +76,16 @@ func handleMain() int {
|
|||
srv.SetIDLength(config.IDLength)
|
||||
srv.SetPasswordLength(config.PasswordLength)
|
||||
|
||||
if config.EnableMetrics {
|
||||
reg := prometheus.NewRegistry()
|
||||
metrics, err := server.NewMetrics(logger, reg, config, db)
|
||||
if err != nil {
|
||||
logger.Error("could not register metrics", slog.Any("error", err))
|
||||
return internal.RC_ERROR
|
||||
}
|
||||
srv.SetMetrics(metrics)
|
||||
}
|
||||
|
||||
err = srv.Start()
|
||||
if err != nil {
|
||||
logger.Error("could not start server", slog.Any("error", err))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue