feat: add prometheus metrics
This commit is contained in:
parent
b4c331daa0
commit
5c8c6eed63
7 changed files with 110 additions and 9 deletions
|
@ -31,13 +31,12 @@ type MetaResponse struct {
|
|||
func (s *Server) meta(w http.ResponseWriter, r *http.Request) error {
|
||||
ctx := r.Context()
|
||||
|
||||
var numUsers, numMembers int64
|
||||
err := s.DB.QueryRow(ctx, "SELECT COUNT(*) FROM users WHERE deleted_at IS NULL").Scan(&numUsers)
|
||||
numUsers, err := s.DB.TotalUserCount(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "querying user count")
|
||||
}
|
||||
|
||||
err = s.DB.QueryRow(ctx, "SELECT COUNT(*) FROM members WHERE unlisted = false AND user_id = ANY(SELECT id FROM users WHERE deleted_at IS NULL)").Scan(&numMembers)
|
||||
numMembers, err := s.DB.TotalMemberCount(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "querying user count")
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"codeberg.org/u1f320/pronouns.cc/backend/server"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
@ -23,6 +24,8 @@ func Mount(srv *server.Server, r chi.Router) {
|
|||
r.Patch("/reports/{id}", server.WrapHandler(s.resolveReport))
|
||||
})
|
||||
|
||||
r.With(MustAdmin).Handle("/metrics", promhttp.Handler())
|
||||
|
||||
r.With(server.MustAuth).Post("/users/{id}/reports", server.WrapHandler(s.createUserReport))
|
||||
r.With(server.MustAuth).Post("/members/{id}/reports", server.WrapHandler(s.createMemberReport))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue