github.com/influxdata/influxdb/v2@v2.7.6/replications/metrics/replications_metrics.go (about)

     1  package metrics
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/influxdata/influxdb/v2/kit/platform"
     7  	"github.com/prometheus/client_golang/prometheus"
     8  )
     9  
    10  type ReplicationsMetrics struct {
    11  	TotalPointsQueued       *prometheus.CounterVec
    12  	TotalBytesQueued        *prometheus.CounterVec
    13  	CurrentBytesQueued      *prometheus.GaugeVec
    14  	RemoteWriteErrors       *prometheus.CounterVec
    15  	RemoteWriteBytesSent    *prometheus.CounterVec
    16  	RemoteWriteBytesDropped *prometheus.CounterVec
    17  	PointsFailedToQueue     *prometheus.CounterVec
    18  	BytesFailedToQueue      *prometheus.CounterVec
    19  }
    20  
    21  func NewReplicationsMetrics() *ReplicationsMetrics {
    22  	const namespace = "replications"
    23  	const subsystem = "queue"
    24  
    25  	return &ReplicationsMetrics{
    26  		TotalPointsQueued: prometheus.NewCounterVec(prometheus.CounterOpts{
    27  			Namespace: namespace,
    28  			Subsystem: subsystem,
    29  			Name:      "total_points_queued",
    30  			Help:      "Sum of all points that have been successfully added to the replication stream queue",
    31  		}, []string{"replicationID"}),
    32  		TotalBytesQueued: prometheus.NewCounterVec(prometheus.CounterOpts{
    33  			Namespace: namespace,
    34  			Subsystem: subsystem,
    35  			Name:      "total_bytes_queued",
    36  			Help:      "Sum of all bytes that have been successfully added to the replication stream queue",
    37  		}, []string{"replicationID"}),
    38  		CurrentBytesQueued: prometheus.NewGaugeVec(prometheus.GaugeOpts{
    39  			Namespace: namespace,
    40  			Subsystem: subsystem,
    41  			Name:      "current_bytes_queued",
    42  			Help:      "Current number of bytes in the replication stream queue remaining to be processed",
    43  		}, []string{"replicationID"}),
    44  		RemoteWriteErrors: prometheus.NewCounterVec(prometheus.CounterOpts{
    45  			Namespace: namespace,
    46  			Subsystem: subsystem,
    47  			Name:      "remote_write_errors",
    48  			Help:      "Error codes returned from attempted remote writes",
    49  		}, []string{"replicationID", "code"}),
    50  		RemoteWriteBytesSent: prometheus.NewCounterVec(prometheus.CounterOpts{
    51  			Namespace: namespace,
    52  			Subsystem: subsystem,
    53  			Name:      "remote_write_bytes_sent",
    54  			Help:      "Bytes of data successfully sent to the remote by the replication stream",
    55  		}, []string{"replicationID"}),
    56  		RemoteWriteBytesDropped: prometheus.NewCounterVec(prometheus.CounterOpts{
    57  			Namespace: namespace,
    58  			Subsystem: subsystem,
    59  			Name:      "remote_write_bytes_dropped",
    60  			Help:      "Bytes of data dropped due to remote write failures",
    61  		}, []string{"replicationID"}),
    62  		PointsFailedToQueue: prometheus.NewCounterVec(prometheus.CounterOpts{
    63  			Namespace: namespace,
    64  			Subsystem: subsystem,
    65  			Name:      "points_failed_to_queue",
    66  			Help:      "Sum of all points that could not be added to the local replication queue",
    67  		}, []string{"replicationID"}),
    68  		BytesFailedToQueue: prometheus.NewCounterVec(prometheus.CounterOpts{
    69  			Namespace: namespace,
    70  			Subsystem: subsystem,
    71  			Name:      "bytes_failed_to_queue",
    72  			Help:      "Sum of all bytes that could not be added to the local replication queue",
    73  		}, []string{"replicationID"}),
    74  	}
    75  }
    76  
    77  // PrometheusCollectors satisfies the prom.PrometheusCollector interface.
    78  func (rm *ReplicationsMetrics) PrometheusCollectors() []prometheus.Collector {
    79  	return []prometheus.Collector{
    80  		rm.TotalPointsQueued,
    81  		rm.TotalBytesQueued,
    82  		rm.CurrentBytesQueued,
    83  		rm.RemoteWriteErrors,
    84  		rm.RemoteWriteBytesSent,
    85  		rm.RemoteWriteBytesDropped,
    86  		rm.PointsFailedToQueue,
    87  		rm.BytesFailedToQueue,
    88  	}
    89  }
    90  
    91  // EnqueueData updates the metrics when adding new data to a replication queue.
    92  func (rm *ReplicationsMetrics) EnqueueData(replicationID platform.ID, numBytes, numPoints int, queueSize int64) {
    93  	rm.TotalPointsQueued.WithLabelValues(replicationID.String()).Add(float64(numPoints))
    94  	rm.TotalBytesQueued.WithLabelValues(replicationID.String()).Add(float64(numBytes))
    95  	rm.CurrentBytesQueued.WithLabelValues(replicationID.String()).Set(float64(queueSize))
    96  }
    97  
    98  // Dequeue updates the metrics when data has been removed from the queue.
    99  func (rm *ReplicationsMetrics) Dequeue(replicationID platform.ID, queueSize int64) {
   100  	rm.CurrentBytesQueued.WithLabelValues(replicationID.String()).Set(float64(queueSize))
   101  }
   102  
   103  // EnqueueError updates the metrics when data fails to be added to the replication queue.
   104  func (rm *ReplicationsMetrics) EnqueueError(replicationID platform.ID, numBytes, numPoints int) {
   105  	rm.PointsFailedToQueue.WithLabelValues(replicationID.String()).Add(float64(numPoints))
   106  	rm.BytesFailedToQueue.WithLabelValues(replicationID.String()).Add(float64(numBytes))
   107  }
   108  
   109  // RemoteWriteError increments the error code counter for the replication.
   110  func (rm *ReplicationsMetrics) RemoteWriteError(replicationID platform.ID, errorCode int) {
   111  	rm.RemoteWriteErrors.WithLabelValues(replicationID.String(), strconv.Itoa(errorCode)).Inc()
   112  }
   113  
   114  // RemoteWriteSent increases the total count of bytes sent following a successful remote write
   115  func (rm *ReplicationsMetrics) RemoteWriteSent(replicationID platform.ID, bytes int) {
   116  	rm.RemoteWriteBytesSent.WithLabelValues(replicationID.String()).Add(float64(bytes))
   117  }
   118  
   119  // RemoteWriteDropped increases the total count of bytes dropped when data is dropped
   120  func (rm *ReplicationsMetrics) RemoteWriteDropped(replicationID platform.ID, bytes int) {
   121  	rm.RemoteWriteBytesDropped.WithLabelValues(replicationID.String()).Add(float64(bytes))
   122  }