Files
akvorado/common/reporter/metrics.go
Vincent Bernat c769bb5234 inlet/bmp: initial support for BMP protocol
At first, there was a tentative to use BMP collector implementation
from bio-rd. However, this current implementation is using GoBGP
instead:

- BMP is very simple from a protocol point of view. The hard work is
  mostly around decoding. Both bio-rd and GoBGP can decode, but for
  testing, GoBGP is able to generate messages as well (this is its
  primary purpose, I suppose parsing was done for testing purpose).
  Using only one library is always better. An alternative would be
  GoBMP, but it also only do parsing.
- Logging and metrics can be customized easily (but the work was done
  for bio-rd, so not a real argument).
- bio-rd is an application and there is no API stability (and I did
  that too)
- GoBGP supports FlowSpec, which may be useful in the future for the
  DDoS part. Again, one library for everything is better (but
  honestly, GoBGP as a lib is not the best part of it, maybe
  github.com/jwhited/corebgp would be a better fit while keeping GoBGP
  for decoding/encoding).

There was a huge effort around having a RIB which is efficient
memory-wise (data are interned to save memory), performant during
reads, while being decent during insertions. We rely on a patched
version of Kentik's Patricia trees to be able to apply mutations to
the tree.

There was several tentatives to implement some kind of graceful
restart, but ultimetaly, the design is kept simple: when a BMP
connection goes down, routes will be removed after a configurable
time. If the connection comes back up, then it is just considered new.
It would have been ideal to rely on EoR markers, but the RFC is
unclear about them, and they are likely to be per peer, making it
difficult to know what to do if one peer is back, but not the other.

Remaining tasks:

- [ ] Confirm support for LocRIB
- [ ] Import data in ClickHouse
- [ ] Make data available in the frontend

Fix #52
2022-09-27 00:34:41 +02:00

128 lines
4.2 KiB
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
// Metrics façade for reporter.
//
// It supports all methods from a factory (except UntypedFunc). See
// https://pkg.go.dev/github.com/prometheus/client_golang/prometheus/promauto#Factory.
// Unlike promauto, it will accepts duplicate registration.
package reporter
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
)
// Register some aliases to avoid importing prometheus package.
type (
// CounterOpts defines options for counters
CounterOpts = prometheus.CounterOpts
// GaugeOpts defines options for gauges
GaugeOpts = prometheus.GaugeOpts
// HistogramOpts defines options for histograms
HistogramOpts = prometheus.HistogramOpts
// SummaryOpts defines options for summaries
SummaryOpts = prometheus.SummaryOpts
// UntypedOpts defines options for untypeds
UntypedOpts = prometheus.UntypedOpts
// Counter defines counters
Counter = prometheus.Counter
// CounterFunc defines counter functions
CounterFunc = prometheus.CounterFunc
// CounterVec defines counter vectors
CounterVec = prometheus.CounterVec
// Gauge defines gauges
Gauge = prometheus.Gauge
// GaugeFunc defines gauge functions
GaugeFunc = prometheus.GaugeFunc
// GaugeVec defines gauge vectors
GaugeVec = prometheus.GaugeVec
// Histogram defines histograms
Histogram = prometheus.Histogram
// HistogramVec defines histogram vectors
HistogramVec = prometheus.HistogramVec
// Summary defines summarys
Summary = prometheus.Summary
// SummaryVec defines summary vectors
SummaryVec = prometheus.SummaryVec
// UntypedFunc defines untyped functions
UntypedFunc = prometheus.UntypedFunc
// MetricDesc defines a metric description
MetricDesc = prometheus.Desc
)
// Counter mimics NewCounter from promauto package.
func (r *Reporter) Counter(opts CounterOpts) Counter {
return r.metrics.Factory(1).NewCounter(opts)
}
// CounterFunc mimics NewCounterFunc from promauto package.
func (r *Reporter) CounterFunc(opts CounterOpts, function func() float64) CounterFunc {
return r.metrics.Factory(1).NewCounterFunc(opts, function)
}
// CounterVec mimics NewCounterVec from promauto package.
func (r *Reporter) CounterVec(opts CounterOpts, labelNames []string) *CounterVec {
return r.metrics.Factory(1).NewCounterVec(opts, labelNames)
}
// Gauge mimics NewGauge from promauto package.
func (r *Reporter) Gauge(opts GaugeOpts) Gauge {
return r.metrics.Factory(1).NewGauge(opts)
}
// GaugeFunc mimics NewGaugeFunc from promauto package.
func (r *Reporter) GaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc {
return r.metrics.Factory(1).NewGaugeFunc(opts, function)
}
// GaugeVec mimics NewGaugeVec from promauto package.
func (r *Reporter) GaugeVec(opts GaugeOpts, labelNames []string) *GaugeVec {
return r.metrics.Factory(1).NewGaugeVec(opts, labelNames)
}
// Histogram mimics NewHistogram from promauto package.
func (r *Reporter) Histogram(opts HistogramOpts) Histogram {
return r.metrics.Factory(1).NewHistogram(opts)
}
// HistogramVec mimics NewHistogramVec from promauto package.
func (r *Reporter) HistogramVec(opts HistogramOpts, labelNames []string) *HistogramVec {
return r.metrics.Factory(1).NewHistogramVec(opts, labelNames)
}
// Summary mimics NewSummary from promauto package.
func (r *Reporter) Summary(opts SummaryOpts) Summary {
return r.metrics.Factory(1).NewSummary(opts)
}
// SummaryVec mimics NewSummaryVec from promauto package.
func (r *Reporter) SummaryVec(opts SummaryOpts, labelNames []string) *SummaryVec {
return r.metrics.Factory(1).NewSummaryVec(opts, labelNames)
}
// MetricsHTTPHandler returns the HTTP handler to get metrics.
func (r *Reporter) MetricsHTTPHandler() http.Handler {
return r.metrics.HTTPHandler()
}
// MetricCollector register a custom collector.
func (r *Reporter) MetricCollector(c prometheus.Collector) {
r.metrics.Collector(c)
}
// MetricCollectorForCurrentModule register a custom collector prefixed by the current module name.
func (r *Reporter) MetricCollectorForCurrentModule(c prometheus.Collector) {
r.metrics.CollectorForCurrentModule(1, c)
}
// MetricDesc defines a new metric description.
func (r *Reporter) MetricDesc(name, help string, variableLabels []string) *MetricDesc {
return r.metrics.Desc(1, name, help, variableLabels)
}