-
Notifications
You must be signed in to change notification settings - Fork 8
/
handler_worker_stats.go
37 lines (30 loc) · 1013 Bytes
/
handler_worker_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"encoding/json"
"github.com/tokubai/kinu/resizer"
"github.com/julienschmidt/httprouter"
"net/http"
)
type WorkerStats struct {
WorkerTotalNum int `json:"total_worker_num"`
ResizeRequestBufferSize int `json:"resize_request_buffer_size"`
StackedResizeRequestNum int `json:"stacked_resize_request_num"`
TooManyResizeRequest bool `json:"too_many_resize_request"`
}
func WorkerStatsHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Content-Type", "application/json")
if !resizer.IsWorkerMode {
RespondBadRequest(w, "current kinu mode is not worker mode")
return
}
js, err := json.Marshal(&WorkerStats{
WorkerTotalNum: resizer.ResizeWorkerSize,
ResizeRequestBufferSize: resizer.ResizeWorkerWaitBufferNum,
StackedResizeRequestNum: resizer.RequestPayloadLen(),
TooManyResizeRequest: !resizer.CanResizeRequest(),
})
if err != nil {
RespondInternalServerError(w, err)
}
RespondJson(w, js)
}