All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ecwid.apiclient.v3.metric.ResponseSizeMetric.kt Maven / Gradle / Ivy

There is a newer version: 0.347.0
Show newest version
package com.ecwid.apiclient.v3.metric

import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.httptransport.HttpResponse
import com.ecwid.apiclient.v3.impl.RequestInfo
import io.prometheus.metrics.core.metrics.Histogram
import io.prometheus.metrics.model.snapshots.Unit

object ResponseSizeMetric {
	private val metric = Histogram.builder()
		.name("ecwid_api_client_response_size_bytes")
		.help("Ecwid API client response size in bytes")
		.classicOnly()
		.classicUpperBounds(
			100.0,
			500.0,
			1_000.0,
			5_000.0,
			10_000.0,
			50_000.0,
			100_000.0,
			500_000.0,
			1_000_000.0,
			5_000_000.0,
			10_000_000.0,
			25_000_000.0,
			50_000_000.0,
			100_000_000.0,
		)
		.labelNames("request_type", "path", "method", "status")
		.unit(Unit.BYTES)
		.register()

	fun observeResponse(
		apiRequest: ApiRequest,
		requestInfo: RequestInfo,
		httpResponse: HttpResponse,
	) {
		metric
			.labelValues(
				apiRequest.javaClass.simpleName,
				requestInfo.getFirstPathSegment(),
				requestInfo.method.name,
				extractStatusFromHttpResponse(httpResponse),
			)
			.observe(httpResponse.responseBytes.size.toDouble())
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy