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