Skip to content
Snippets Groups Projects
Select Git revision
  • c715ad8d8123ca244f8eaa92f7456c9e99101fb4
  • master default protected
  • feature/PRXS-3383-CollectionsRankSortAPI
  • feature/PRXS-3383-CollectionsSort
  • feature/3109-SerializeFeature
  • release/0.33
  • feature/3109-RecoverySchema
  • feature/3109-feature
  • fix/PRXS-3369-ValidateFields
  • refactor/PRXS-3306-MovePkgGroup1
  • refactor/6-pkg-refactor-expr
  • fix/PRXS-3360-TemplateBuilderPatch
  • feature/3293-MongoV2
  • feature/3272-GoVersionUp
  • feature/PRXS-3218-HideTemplateActions
  • feature/PRXS-3234-PruneIdents
  • feature/3146-UpdateItemStorageInterface
  • feature/3274-ObjectIndexesFixes
  • feature/PRXS-3143-3235-ReferenceOptions
  • feature/PRXS-3143-3237-ExecuteOptions
  • feature/3149-LocaleCodeAsID-Implementation
  • v0.33.1
  • v0.32.0
  • v0.31.1
  • v0.31.0
  • v0.30.0
  • v0.29.0
  • v0.28.0
  • v0.27.0-alpha.1+16
  • v0.27.0-alpha.1+15
  • v0.27.0-alpha.1+14
  • v0.27.0-alpha.1+13
  • v0.27.0-alpha.1+12
  • v0.27.0-alpha.1+11
  • v0.27.0-alpha.1+10
  • v0.27.0-alpha.1+9
  • v0.27.0-alpha.1+8
  • v0.27.0-alpha.1+7
  • v0.27.0-alpha.1+6
  • v0.27.0-alpha.1+5
  • v0.27.0-alpha.1+4
41 results

request.go

Blame
  • request.go 2.02 KiB
    package metrics
    
    import (
    	"github.com/prometheus/client_golang/prometheus"
    )
    
    type RequestMetrics struct {
    	Total           *prometheus.CounterVec
    	FailedTotal     *prometheus.CounterVec
    	DurationSeconds *prometheus.HistogramVec
    }
    
    // NewRequestMetrics возвращает метрики для подсчета количества удачных/неудачных запросов, а так же длительности ответов.
    //
    // subsystem указывает подсистему, к которой принадлежат метрики.
    // Значение должно быть уникальным, совпадение разрешено только при совпадении ключей labels. Пустое значение допустимо.
    //
    // labels - список меток, где каждый элемент метки соответствует парам ключ-значение. Отсутствие допустимо.
    // Значения меток должны быть уникальными в рамках одной subsystem.
    //
    // Метрики записываются в prometheus.DefaultRegisterer
    func NewRequestMetrics(subsystem string, durationBuckets []float64, labels ...string) *RequestMetrics {
    	if len(durationBuckets) == 0 {
    		durationBuckets = prometheus.DefBuckets
    	}
    	metrics := &RequestMetrics{
    		Total: prometheus.NewCounterVec(prometheus.CounterOpts{
    			Subsystem: subsystem,
    			Name:      "service_requests_total",
    		}, []string{"method"}),
    		FailedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
    			Subsystem: subsystem,
    			Name:      "service_requests_failed_total",
    		}, []string{"method"}),
    		DurationSeconds: prometheus.NewHistogramVec(prometheus.HistogramOpts{
    			Subsystem: subsystem,
    			Name:      "service_request_duration_seconds",
    			Buckets:   durationBuckets,
    		}, []string{"method"}),
    	}
    	prometheus.WrapRegistererWith(GetLabelsFromKV(labels), prometheus.DefaultRegisterer).MustRegister(
    		metrics.Total,
    		metrics.FailedTotal,
    		metrics.DurationSeconds,
    	)
    	return metrics
    }