mirror of
				https://github.com/imgproxy/imgproxy.git
				synced 2025-10-30 23:08:02 +02:00 
			
		
		
		
	Collect vips memory metrics
This commit is contained in:
		
							
								
								
									
										15
									
								
								process.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								process.go
									
									
									
									
									
								
							| @@ -13,6 +13,7 @@ import ( | ||||
| 	"math" | ||||
| 	"os" | ||||
| 	"runtime" | ||||
| 	"time" | ||||
| 	"unsafe" | ||||
|  | ||||
| 	"golang.org/x/sync/errgroup" | ||||
| @@ -112,6 +113,8 @@ func initVips() { | ||||
| 	if err := vipsPrepareWatermark(); err != nil { | ||||
| 		logFatal(err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	collectVipsMetrics() | ||||
| } | ||||
|  | ||||
| func shutdownVips() { | ||||
| @@ -119,6 +122,18 @@ func shutdownVips() { | ||||
| 	C.vips_shutdown() | ||||
| } | ||||
|  | ||||
| func collectVipsMetrics() { | ||||
| 	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 cachedCString(str string) *C.char { | ||||
| 	if cstr, ok := cstrings[str]; ok { | ||||
| 		return cstr | ||||
|   | ||||
| @@ -19,6 +19,9 @@ var ( | ||||
| 	prometheusBufferSize         *prometheus.HistogramVec | ||||
| 	prometheusBufferDefaultSize  *prometheus.GaugeVec | ||||
| 	prometheusBufferMaxSize      *prometheus.GaugeVec | ||||
| 	prometheusVipsMemory         prometheus.Gauge | ||||
| 	prometheusVipsMaxMemory      prometheus.Gauge | ||||
| 	prometheusVipsAllocs         prometheus.Gauge | ||||
| ) | ||||
|  | ||||
| func initPrometheus() { | ||||
| @@ -66,6 +69,21 @@ func initPrometheus() { | ||||
| 		Help: "A gauge of the buffer max size in bytes.", | ||||
| 	}, []string{"type"}) | ||||
|  | ||||
| 	prometheusVipsMemory = prometheus.NewGauge(prometheus.GaugeOpts{ | ||||
| 		Name: "vips_memory_bytes", | ||||
| 		Help: "A gauge of the vips tracked memory usage in bytes.", | ||||
| 	}) | ||||
|  | ||||
| 	prometheusVipsMaxMemory = prometheus.NewGauge(prometheus.GaugeOpts{ | ||||
| 		Name: "vips_max_memory_bytes", | ||||
| 		Help: "A gauge of the max vips tracked memory usage in bytes.", | ||||
| 	}) | ||||
|  | ||||
| 	prometheusVipsAllocs = prometheus.NewGauge(prometheus.GaugeOpts{ | ||||
| 		Name: "vips_allocs", | ||||
| 		Help: "A gauge of the number of active vips allocations.", | ||||
| 	}) | ||||
|  | ||||
| 	prometheus.MustRegister( | ||||
| 		prometheusRequestsTotal, | ||||
| 		prometheusErrorsTotal, | ||||
| @@ -75,6 +93,9 @@ func initPrometheus() { | ||||
| 		prometheusBufferSize, | ||||
| 		prometheusBufferDefaultSize, | ||||
| 		prometheusBufferMaxSize, | ||||
| 		prometheusVipsMemory, | ||||
| 		prometheusVipsMaxMemory, | ||||
| 		prometheusVipsAllocs, | ||||
| 	) | ||||
|  | ||||
| 	prometheusEnabled = true | ||||
|   | ||||
		Reference in New Issue
	
	Block a user