forked from MTSR/mapserver
render metrics
This commit is contained in:
parent
b40b5dd86b
commit
757d460379
@ -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 {
|
||||
|
@ -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++ {
|
||||
|
19
server/tilerendererjob/metrics.go
Normal file
19
server/tilerendererjob/metrics.go
Normal file
@ -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)
|
||||
}
|
@ -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)
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user