metrics.go 2.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package pusher

import (
	m "github.com/ethersphere/bee/pkg/metrics"
	"github.com/prometheus/client_golang/prometheus"
)

type metrics struct {
13 14 15 16 17 18
	TotalToPush      prometheus.Counter
	TotalSynced      prometheus.Counter
	TotalErrors      prometheus.Counter
	MarkAndSweepTime prometheus.Histogram
	SyncTime         prometheus.Histogram
	ErrorTime        prometheus.Histogram
19

20 21
	ReceiptDepth        *prometheus.CounterVec
	ShallowReceiptDepth *prometheus.CounterVec
22 23 24
}

func newMetrics() metrics {
25
	subsystem := "pusher"
26 27

	return metrics{
28
		TotalToPush: prometheus.NewCounter(prometheus.CounterOpts{
29 30
			Namespace: m.Namespace,
			Subsystem: subsystem,
31 32
			Name:      "total_to_push",
			Help:      "Total chunks to push (chunks may be repeated).",
33
		}),
34
		TotalSynced: prometheus.NewCounter(prometheus.CounterOpts{
35 36
			Namespace: m.Namespace,
			Subsystem: subsystem,
37
			Name:      "total_synced",
38 39
			Help:      "Total chunks synced successfully with valid receipts.",
		}),
40
		TotalErrors: prometheus.NewCounter(prometheus.CounterOpts{
41 42
			Namespace: m.Namespace,
			Subsystem: subsystem,
43 44
			Name:      "total_errors",
			Help:      "Total errors encountered.",
45
		}),
46
		MarkAndSweepTime: prometheus.NewHistogram(prometheus.HistogramOpts{
47 48
			Namespace: m.Namespace,
			Subsystem: subsystem,
49
			Name:      "mark_and_sweep_time",
50 51 52
			Help:      "Histogram of time spent in mark and sweep.",
			Buckets:   []float64{0.1, 0.25, 0.5, 1, 2.5, 5, 10, 60},
		}),
53 54 55 56 57 58 59 60 61 62 63 64 65 66
		SyncTime: prometheus.NewHistogram(prometheus.HistogramOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "sync_time",
			Help:      "Histogram of time spent to sync a chunk.",
			Buckets:   []float64{0.1, 0.25, 0.5, 1, 2.5, 5, 10, 60},
		}),
		ErrorTime: prometheus.NewHistogram(prometheus.HistogramOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "error_time",
			Help:      "Histogram of time spent before giving up on syncing a chunk.",
			Buckets:   []float64{0.1, 0.25, 0.5, 1, 2.5, 5, 10, 60},
		}),
67 68 69 70 71 72 73 74 75
		ReceiptDepth: prometheus.NewCounterVec(
			prometheus.CounterOpts{
				Namespace: m.Namespace,
				Subsystem: subsystem,
				Name:      "receipt_depth",
				Help:      "Counter of receipts received at different depths.",
			},
			[]string{"depth"},
		),
76 77 78 79 80 81 82 83 84
		ShallowReceiptDepth: prometheus.NewCounterVec(
			prometheus.CounterOpts{
				Namespace: m.Namespace,
				Subsystem: subsystem,
				Name:      "shallow_receipt_depth",
				Help:      "Counter of shallow receipts received at different depths.",
			},
			[]string{"depth"},
		),
85 86 87 88 89 90
	}
}

func (s *Service) Metrics() []prometheus.Collector {
	return m.PrometheusCollectorsFromFields(s.metrics)
}