Skip to content

Commit

Permalink
connections metric
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudkov committed Nov 10, 2023
1 parent 6bf6823 commit 98b68ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/goatak_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ func (app *App) NewCotMessage(msg *cot.CotMessage) {

func (app *App) AddClientHandler(ch client.ClientHandler) {
app.handlers.Store(ch.GetName(), ch)
connectionsMetric.Inc()
}

func (app *App) RemoveClientHandler(name string) {
if _, ok := app.handlers.Load(name); ok {
app.Logger.Infof("remove handler: %s", name)
app.handlers.Delete(name)
if _, ok := app.handlers.LoadAndDelete(name); ok {
connectionsMetric.Dec()
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/goatak_server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ var (
Name: "cots_processed",
Help: "The total number of cots processed",
})

connectionsMetric = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "goatak",
Name: "connections",
Help: "The total number of connections",
})
)

0 comments on commit 98b68ca

Please sign in to comment.