mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 12:12:40 +02:00
Add prometheus metrics for buffers
This commit is contained in:
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())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user