You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

internal/proxy: add initial set of abci metrics (#7115) This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods. An example of these metrics is included here for reference: ``` tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13 tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001 tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13 ``` These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
3 years ago
  1. package proxy
  2. import (
  3. "github.com/go-kit/kit/metrics"
  4. "github.com/go-kit/kit/metrics/discard"
  5. "github.com/go-kit/kit/metrics/prometheus"
  6. stdprometheus "github.com/prometheus/client_golang/prometheus"
  7. )
  8. const (
  9. // MetricsSubsystem is a subsystem shared by all metrics exposed by this
  10. // package.
  11. MetricsSubsystem = "abci_connection"
  12. )
  13. // Metrics contains the prometheus metrics exposed by the proxy package.
  14. type Metrics struct {
  15. MethodTiming metrics.Histogram
  16. }
  17. // PrometheusMetrics constructs a Metrics instance that collects metrics samples.
  18. // The resulting metrics will be prefixed with namespace and labeled with the
  19. // defaultLabelsAndValues. defaultLabelsAndValues must be a list of string pairs
  20. // where the first of each pair is the label and the second is the value.
  21. func PrometheusMetrics(namespace string, defaultLabelsAndValues ...string) *Metrics {
  22. defaultLabels := []string{}
  23. for i := 0; i < len(defaultLabelsAndValues); i += 2 {
  24. defaultLabels = append(defaultLabels, defaultLabelsAndValues[i])
  25. }
  26. return &Metrics{
  27. MethodTiming: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
  28. Namespace: namespace,
  29. Subsystem: MetricsSubsystem,
  30. Name: "method_timing",
  31. Help: "ABCI Method Timing",
  32. Buckets: []float64{.0001, .0004, .002, .009, .02, .1, .65, 2, 6, 25},
  33. }, append(defaultLabels, []string{"method", "type"}...)).With(defaultLabelsAndValues...),
  34. }
  35. }
  36. // NopMetrics constructs a Metrics instance that discards all samples and is suitable
  37. // for testing.
  38. func NopMetrics() *Metrics {
  39. return &Metrics{
  40. MethodTiming: discard.NewHistogram(),
  41. }
  42. }