mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-04-01 20:34:23 +02:00
Use GaugeFunc for vips metrics
This commit is contained in:
parent
b783e8bebf
commit
ec545138ac
@ -21,9 +21,9 @@ var (
|
||||
prometheusBufferSize *prometheus.HistogramVec
|
||||
prometheusBufferDefaultSize *prometheus.GaugeVec
|
||||
prometheusBufferMaxSize *prometheus.GaugeVec
|
||||
prometheusVipsMemory prometheus.Gauge
|
||||
prometheusVipsMaxMemory prometheus.Gauge
|
||||
prometheusVipsAllocs prometheus.Gauge
|
||||
prometheusVipsMemory prometheus.GaugeFunc
|
||||
prometheusVipsMaxMemory prometheus.GaugeFunc
|
||||
prometheusVipsAllocs prometheus.GaugeFunc
|
||||
)
|
||||
|
||||
func initPrometheus() {
|
||||
@ -79,23 +79,23 @@ func initPrometheus() {
|
||||
Help: "A gauge of the buffer max size in bytes.",
|
||||
}, []string{"type"})
|
||||
|
||||
prometheusVipsMemory = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
prometheusVipsMemory = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||
Namespace: conf.PrometheusNamespace,
|
||||
Name: "vips_memory_bytes",
|
||||
Help: "A gauge of the vips tracked memory usage in bytes.",
|
||||
})
|
||||
}, vipsGetMem)
|
||||
|
||||
prometheusVipsMaxMemory = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
prometheusVipsMaxMemory = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||
Namespace: conf.PrometheusNamespace,
|
||||
Name: "vips_max_memory_bytes",
|
||||
Help: "A gauge of the max vips tracked memory usage in bytes.",
|
||||
})
|
||||
}, vipsGetMemHighwater)
|
||||
|
||||
prometheusVipsAllocs = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
prometheusVipsAllocs = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||
Namespace: conf.PrometheusNamespace,
|
||||
Name: "vips_allocs",
|
||||
Help: "A gauge of the number of active vips allocations.",
|
||||
})
|
||||
}, vipsGetAllocs)
|
||||
|
||||
prometheus.MustRegister(
|
||||
prometheusRequestsTotal,
|
||||
|
23
vips.go
23
vips.go
@ -13,7 +13,6 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@ -100,8 +99,6 @@ func initVips() error {
|
||||
return fmt.Errorf("Can't load watermark: %s", err)
|
||||
}
|
||||
|
||||
vipsCollectMetrics()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -109,16 +106,16 @@ func shutdownVips() {
|
||||
C.vips_shutdown()
|
||||
}
|
||||
|
||||
func vipsCollectMetrics() {
|
||||
if prometheusEnabled {
|
||||
go func() {
|
||||
for range time.Tick(5 * time.Second) {
|
||||
prometheusVipsMemory.Set(float64(C.vips_tracked_get_mem()))
|
||||
prometheusVipsMaxMemory.Set(float64(C.vips_tracked_get_mem_highwater()))
|
||||
prometheusVipsAllocs.Set(float64(C.vips_tracked_get_allocs()))
|
||||
}
|
||||
}()
|
||||
}
|
||||
func vipsGetMem() float64 {
|
||||
return float64(C.vips_tracked_get_mem())
|
||||
}
|
||||
|
||||
func vipsGetMemHighwater() float64 {
|
||||
return float64(C.vips_tracked_get_mem_highwater())
|
||||
}
|
||||
|
||||
func vipsGetAllocs() float64 {
|
||||
return float64(C.vips_tracked_get_allocs())
|
||||
}
|
||||
|
||||
func vipsCleanup() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user