mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-03-17 20:17:48 +02:00
Add prometheus metrics for buffers
This commit is contained in:
parent
69549b878a
commit
e566aedcc3
13
bufpool.go
13
bufpool.go
@ -7,6 +7,7 @@ import (
|
||||
|
||||
type bufPool struct {
|
||||
mutex sync.Mutex
|
||||
name string
|
||||
size int
|
||||
top *bufPoolEntry
|
||||
}
|
||||
@ -16,8 +17,8 @@ type bufPoolEntry struct {
|
||||
next *bufPoolEntry
|
||||
}
|
||||
|
||||
func newBufPool(n int, size int) *bufPool {
|
||||
pool := bufPool{size: size}
|
||||
func newBufPool(name string, n int, size int) *bufPool {
|
||||
pool := bufPool{name: name, size: size}
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
pool.grow()
|
||||
@ -36,6 +37,10 @@ func (p *bufPool) grow() {
|
||||
}
|
||||
|
||||
p.top = &bufPoolEntry{buf: buf, next: p.top}
|
||||
|
||||
if prometheusEnabled {
|
||||
incrementBuffersTotal(p.name)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *bufPool) get() *bytes.Buffer {
|
||||
@ -59,4 +64,8 @@ func (p *bufPool) put(buf *bytes.Buffer) {
|
||||
defer p.mutex.Unlock()
|
||||
|
||||
p.top = &bufPoolEntry{buf: buf, next: p.top}
|
||||
|
||||
if prometheusEnabled {
|
||||
observeBufferSize(p.name, buf.Cap())
|
||||
}
|
||||
}
|
||||
|
@ -441,9 +441,9 @@ func init() {
|
||||
logFatal("GZip buffer size can't be creater than %d", ^uint32(0))
|
||||
}
|
||||
|
||||
initDownloading()
|
||||
initNewrelic()
|
||||
initPrometheus()
|
||||
initDownloading()
|
||||
initErrorsReporting()
|
||||
initVips()
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func initDownloading() {
|
||||
Transport: transport,
|
||||
}
|
||||
|
||||
downloadBufPool = newBufPool(conf.Concurrency, conf.DownloadBufferSize)
|
||||
downloadBufPool = newBufPool("download", conf.Concurrency, conf.DownloadBufferSize)
|
||||
}
|
||||
|
||||
func checkDimensions(width, height int) error {
|
||||
|
@ -16,6 +16,8 @@ var (
|
||||
prometheusRequestDuration prometheus.Histogram
|
||||
prometheusDownloadDuration prometheus.Histogram
|
||||
prometheusProcessingDuration prometheus.Histogram
|
||||
prometheusBuffersTotal *prometheus.CounterVec
|
||||
prometheusBufferSize *prometheus.HistogramVec
|
||||
)
|
||||
|
||||
func initPrometheus() {
|
||||
@ -48,12 +50,24 @@ func initPrometheus() {
|
||||
Help: "A histogram of the image processing latency.",
|
||||
})
|
||||
|
||||
prometheusBuffersTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "buffers_total",
|
||||
Help: "A counter of the total number of buffers imgproxy allocated.",
|
||||
}, []string{"type"})
|
||||
|
||||
prometheusBufferSize = prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Name: "buffer_size_megabytes",
|
||||
Help: "A histogram of the buffer size in megabytes.",
|
||||
}, []string{"type"})
|
||||
|
||||
prometheus.MustRegister(
|
||||
prometheusRequestsTotal,
|
||||
prometheusErrorsTotal,
|
||||
prometheusRequestDuration,
|
||||
prometheusDownloadDuration,
|
||||
prometheusProcessingDuration,
|
||||
prometheusBuffersTotal,
|
||||
prometheusBufferSize,
|
||||
)
|
||||
|
||||
prometheusEnabled = true
|
||||
@ -81,3 +95,12 @@ func startPrometheusDuration(m prometheus.Histogram) func() {
|
||||
func incrementPrometheusErrorsTotal(t string) {
|
||||
prometheusErrorsTotal.With(prometheus.Labels{"type": t}).Inc()
|
||||
}
|
||||
|
||||
func incrementBuffersTotal(t string) {
|
||||
prometheusBuffersTotal.With(prometheus.Labels{"type": t}).Inc()
|
||||
}
|
||||
|
||||
func observeBufferSize(t string, cap int) {
|
||||
size := float64(cap) / 1024.0 / 1024.0
|
||||
prometheusBufferSize.With(prometheus.Labels{"type": t}).Observe(size)
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func startServer() *http.Server {
|
||||
}
|
||||
|
||||
if conf.GZipCompression > 0 {
|
||||
responseGzipBufPool = newBufPool(conf.Concurrency, conf.GZipBufferSize)
|
||||
responseGzipBufPool = newBufPool("gzip", conf.Concurrency, conf.GZipBufferSize)
|
||||
responseGzipPool = newGzipPool(conf.Concurrency)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user