1
0
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:
Jonathan Leibiusky
2016-12-15 17:12:17 -08:00
committed by GitHub
parent 946a8e1419
commit 70eaf37d4b
4 changed files with 54 additions and 2 deletions

View File

@@ -11,10 +11,22 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/prometheus/client_golang/prometheus"
)
var rw sync.Mutex
var (
instancesGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "instances",
Help: "Instances",
})
)
func init() {
prometheus.MustRegister(instancesGauge)
}
type Instance struct {
session *Session `json:"-"`
Name string `json:"name"`
@@ -90,6 +102,8 @@ func NewInstance(session *Session) (*Instance, error) {
wsServer.BroadcastTo(session.Id, "new instance", instance.Name, instance.IP, instance.Hostname)
instancesGauge.Inc()
return instance, nil
}
@@ -142,5 +156,7 @@ func DeleteInstance(session *Session, instance *Instance) error {
wsServer.BroadcastTo(session.Id, "delete instance", instance.Name)
instancesGauge.Dec()
return err
}