mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-10-05 09:53:21 +08:00
Add metrics (#70)
* Add prometheus support to count sessions, instances and clientes over time * Track counters on server reload * Change to gauges
This commit is contained in:
committed by
GitHub
parent
946a8e1419
commit
70eaf37d4b
@@ -4,8 +4,20 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/googollee/go-socket.io"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
clientsGauge = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "clients",
|
||||
Help: "Clients",
|
||||
})
|
||||
)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(clientsGauge)
|
||||
}
|
||||
|
||||
type ViewPort struct {
|
||||
Rows uint
|
||||
Cols uint
|
||||
@@ -23,6 +35,7 @@ func (c *Client) ResizeViewPort(cols, rows uint) {
|
||||
}
|
||||
|
||||
func NewClient(so socketio.Socket, session *Session) *Client {
|
||||
clientsGauge.Inc()
|
||||
so.Join(session.Id)
|
||||
|
||||
c := &Client{so: so, Id: so.Id()}
|
||||
@@ -52,7 +65,9 @@ func NewClient(so socketio.Socket, session *Session) *Client {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
so.On("disconnection", func() {
|
||||
clientsGauge.Dec()
|
||||
// Client has disconnected. Remove from session and recheck terminal sizes.
|
||||
for i, cl := range session.clients {
|
||||
if cl.Id == c.Id {
|
||||
@@ -69,6 +84,5 @@ func NewClient(so socketio.Socket, session *Session) *Client {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return c
|
||||
}
|
||||
|
Reference in New Issue
Block a user