metrics.go 4.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// 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 pushsync

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

type metrics struct {
	// all metrics fields must be exported
	// to be able to return them by Metrics()
	// using reflection

17 18 19 20 21 22 23 24 25 26 27 28 29
	TotalChunksStoredInDB      prometheus.Counter
	ChunksSentCounter          prometheus.Counter
	ChunksReceivedCounter      prometheus.Counter
	SendChunkErrorCounter      prometheus.Counter
	ReceivedChunkErrorCounter  prometheus.Counter
	ReceiptsReceivedCounter    prometheus.Counter
	ReceiptsSentCounter        prometheus.Counter
	SendReceiptErrorCounter    prometheus.Counter
	ReceiveReceiptErrorCounter prometheus.Counter
	RetriesExhaustedCounter    prometheus.Counter
	InvalidReceiptReceived     prometheus.Counter
	SendChunkTimer             prometheus.Histogram
	ReceiptRTT                 prometheus.Histogram
30 31 32 33 34 35
}

func newMetrics() metrics {
	subsystem := "pushsync"

	return metrics{
36 37 38 39
		TotalChunksStoredInDB: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "total_chunk_stored_in_DB",
40
			Help:      "Total chunks stored successfully in local store.",
41 42 43 44 45 46 47 48
		}),
		ChunksSentCounter: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "sent_chunk",
			Help:      "Total chunks sent.",
		}),
		ChunksReceivedCounter: prometheus.NewCounter(prometheus.CounterOpts{
49 50
			Namespace: m.Namespace,
			Subsystem: subsystem,
51 52
			Name:      "received_chunk",
			Help:      "Total chunks received.",
53 54 55 56 57 58 59
		}),
		SendChunkErrorCounter: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "send_chunk_error",
			Help:      "Total no of time error received while sending chunk.",
		}),
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
		ReceivedChunkErrorCounter: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "received_chunk_error",
			Help:      "Total no of time error received while receiving chunk.",
		}),
		ReceiptsReceivedCounter: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "received_receipts",
			Help:      "Total no of times receipts received.",
		}),
		ReceiptsSentCounter: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "sent_receipts",
			Help:      "Total no of times receipts are sent.",
		}),
		SendReceiptErrorCounter: prometheus.NewCounter(prometheus.CounterOpts{
79 80
			Namespace: m.Namespace,
			Subsystem: subsystem,
81 82 83 84 85 86 87 88
			Name:      "sent_receipts_error",
			Help:      "Total no of times receipts were sent and error was encountered.",
		}),
		ReceiveReceiptErrorCounter: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "receive_receipt_error",
			Help:      "Total no of time error received while receiving receipt.",
89
		}),
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
		RetriesExhaustedCounter: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "chunk_retries_exhausted",
			Help:      "CHunk retries exhausted.",
		}),
		InvalidReceiptReceived: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "invalid_receipt_receipt",
			Help:      "Invalid receipt received from peer.",
		}),
		SendChunkTimer: prometheus.NewHistogram(prometheus.HistogramOpts{
			Namespace: m.Namespace,
			Subsystem: subsystem,
			Name:      "send_chunk_time_histogram",
			Help:      "Histogram for Time taken to send a chunk.",
			Buckets:   []float64{0.1, 0.25, 0.5, 1, 2.5, 5, 10, 60},
		}),
		ReceiptRTT: prometheus.NewHistogram(prometheus.HistogramOpts{
110 111
			Namespace: m.Namespace,
			Subsystem: subsystem,
112 113 114
			Name:      "receipt_rtt_histogram",
			Help:      "Histogram of RTT for receiving receipt for a pushed chunk.",
			Buckets:   []float64{0.1, 0.25, 0.5, 1, 2.5, 5, 10, 60},
115 116 117 118 119 120 121
		}),
	}
}

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