github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/parser/metrics.go (about) 1 package parser 2 3 import ( 4 "github.com/prometheus/client_golang/prometheus" 5 6 "github.com/pyroscope-io/pyroscope/pkg/ingestion" 7 ) 8 9 var ( 10 requestsTotalCounter *prometheus.CounterVec 11 requestsBytesCounter *prometheus.CounterVec 12 ) 13 14 func init() { 15 requestsTotalCounter = prometheus.NewCounterVec( 16 prometheus.CounterOpts{ 17 Name: "pyroscope_parser_incoming_requests_total", 18 Help: "Total number of requests received by the parser", 19 }, 20 []string{"profiler"}, 21 ) 22 requestsBytesCounter = prometheus.NewCounterVec( 23 prometheus.CounterOpts{ 24 Name: "pyroscope_parser_incoming_requests_bytes", 25 Help: "Total number of bytes received by the parser", 26 }, 27 []string{"profiler"}, 28 ) 29 30 prometheus.MustRegister(requestsTotalCounter, requestsBytesCounter) 31 } 32 33 func updateMetrics(in *ingestion.IngestInput) { 34 profilerName := "unknown" 35 if in.Metadata.SpyName != "" { 36 profilerName = in.Metadata.SpyName 37 } 38 requestsTotalCounter.WithLabelValues(profilerName).Inc() 39 40 data, err := in.Profile.Bytes() 41 if err == nil { 42 requestsBytesCounter.WithLabelValues(profilerName).Add(float64(len(data))) 43 } 44 }