Skip to content

Commit

Permalink
Merge pull request #282 from rmoscosows/main
Browse files Browse the repository at this point in the history
Add histogram custom metrics registration
  • Loading branch information
adilsonwild authored Aug 15, 2022
2 parents 188f504 + e321309 commit 5e3cd54
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
16 changes: 13 additions & 3 deletions metrics/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ type Summary struct {
Labels []string
}

// Histogram defines a histogram metric
type Histogram struct {
Subsystem string
Name string
Help string
Buckets []float64
Labels []string
}

// Gauge defines a gauge metric
type Gauge struct {
Subsystem string
Expand All @@ -27,7 +36,8 @@ type Counter struct {

// CustomMetricsSpec has all metrics specs
type CustomMetricsSpec struct {
Summaries []*Summary
Gauges []*Gauge
Counters []*Counter
Summaries []*Summary
Histograms []*Histogram
Gauges []*Gauge
Counters []*Counter
}
14 changes: 14 additions & 0 deletions metrics/prometheus_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ func (p *PrometheusReporter) registerCustomMetrics(
)
}

for _, histogram := range spec.Histograms {
p.histogramReportersMap[histogram.Name] = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "pitaya",
Subsystem: histogram.Subsystem,
Name: histogram.Name,
Help: histogram.Help,
Buckets: histogram.Buckets,
ConstLabels: constLabels,
},
append(additionalLabelsKeys, histogram.Labels...),
)
}

for _, gauge := range spec.Gauges {
p.gaugeReportersMap[gauge.Name] = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down

0 comments on commit 5e3cd54

Please sign in to comment.