diff --git a/server/tilerendererjob/common.go b/server/tilerendererjob/common.go index 78ab901..fca6c34 100644 --- a/server/tilerendererjob/common.go +++ b/server/tilerendererjob/common.go @@ -17,6 +17,7 @@ func getTileKey(tc *coords.TileCoords) string { func renderMapblocks(ctx *app.App, jobs chan *coords.TileCoords, mblist []*mapblockparser.MapBlock) int { tileRenderedMap := make(map[string]bool) tilecount := 0 + totalRenderedMapblocks.Add(float64(len(mblist))) for i := 12; i >= 1; i-- { for _, mb := range mblist { diff --git a/server/tilerendererjob/job.go b/server/tilerendererjob/job.go index c5ea8a4..d233579 100644 --- a/server/tilerendererjob/job.go +++ b/server/tilerendererjob/job.go @@ -7,7 +7,8 @@ import ( ) func Job(ctx *app.App) { - + initMetrics() + jobs := make(chan *coords.TileCoords, ctx.Config.RenderingQueue) for i := 0; i < ctx.Config.RenderingJobs; i++ { diff --git a/server/tilerendererjob/metrics.go b/server/tilerendererjob/metrics.go new file mode 100644 index 0000000..b981343 --- /dev/null +++ b/server/tilerendererjob/metrics.go @@ -0,0 +1,19 @@ +package tilerendererjob + +import ( + "github.com/prometheus/client_golang/prometheus" +) + + +var ( + totalRenderedMapblocks = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "total_rendered_mapblocks", + Help: "Overall rendered mapblocks", + }, + ) +) + +func initMetrics(){ + prometheus.MustRegister(totalRenderedMapblocks) +} diff --git a/server/web/tiles.go b/server/web/tiles.go index cc2a6a7..c9e2961 100644 --- a/server/web/tiles.go +++ b/server/web/tiles.go @@ -8,6 +8,16 @@ import ( "net/http" "strconv" "strings" + "github.com/prometheus/client_golang/prometheus" +) + +var ( + tilesCumulativeSize = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "tiles_cumulative_size_served", + Help: "Overall sent bytes of tiles", + }, + ) ) type Tiles struct { @@ -17,6 +27,7 @@ type Tiles struct { func (t *Tiles) Init() { t.blank = tilerenderer.CreateBlankTile(color.RGBA{255, 255, 255, 255}) + prometheus.MustRegister(tilesCumulativeSize) } func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) { @@ -49,6 +60,7 @@ func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) { //TODO: cache/layer color } else { + tilesCumulativeSize.Add(float64(len(tile.Data))) resp.Write(tile.Data) } diff --git a/server/web/ws.go b/server/web/ws.go index bfccd49..f43b35e 100644 --- a/server/web/ws.go +++ b/server/web/ws.go @@ -9,18 +9,28 @@ import ( "sync" "github.com/gorilla/websocket" + "github.com/prometheus/client_golang/prometheus" +) + +var ( + wsClients = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "ws_client_count", + Help: "Websocket client count", + }) ) type WS struct { ctx *app.App channels map[int]chan []byte mutex *sync.RWMutex + clients int } func NewWS(ctx *app.App) *WS { ws := WS{} ws.mutex = &sync.RWMutex{} ws.channels = make(map[int]chan []byte) + prometheus.MustRegister(wsClients) return &ws } @@ -62,6 +72,8 @@ func (t *WS) ServeHTTP(resp http.ResponseWriter, req *http.Request) { t.mutex.Lock() t.channels[id] = ch + t.clients++ + wsClients.Set(float64(t.clients)) t.mutex.Unlock() for { @@ -73,6 +85,8 @@ func (t *WS) ServeHTTP(resp http.ResponseWriter, req *http.Request) { } t.mutex.Lock() + t.clients-- + wsClients.Set(float64(t.clients)) delete(t.channels, id) close(ch) t.mutex.Unlock()