prometheusmetric

package
v0.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: LGPL-2.1, LGPL-2.1-or-later Imports: 4 Imported by: 0

README

Prometheus Metrics Recorder Example

This folder contains a sample implementation of the metrics.Recorder interface that exports counters and histograms to Prometheus. You can copy recorder.go into your own codebase or import it directly if you prefer.

Usage

  1. Install Prometheus client:

    go get github.com/prometheus/client_golang/prometheus
    go get github.com/prometheus/client_golang/prometheus/promhttp
    
  2. Create a recorder and register it:

    import (
        "net/http"
        prom "github.com/handcoding-labs/redis-stream-client-go/examples/prometheus"
        "github.com/prometheus/client_golang/prometheus"
        "github.com/prometheus/client_golang/prometheus/promhttp"
    )
    
    func main() {
        rec := prom.NewPrometheusRecorder(prometheus.DefaultRegisterer)
        client, _ := impl.NewRedisStreamClient(redisClient, "my-service", impl.WithMetricsRecorder(rec))
    
        // start HTTP endpoint for scraping
        http.Handle("/metrics", promhttp.Handler())
        go http.ListenAndServe(":2112", nil)
    
        // ...rest of application...
    }
    
  3. Scrape the /metrics endpoint with your Prometheus server. See docs/METRICS.md for a complete description of each metric and suggested alerting queries.

Notes

  • The example tracks stream processing duration by recording the start time and computing the elapsed time in RecordStreamProcessingEnd.
  • When modifying the interface in the future, update this file to match the new method signatures.

Documentation

Overview

Package prometheus provides a reference MetricsRecorder implementation using Prometheus. Copy this file into your own codebase and adjust as needed.

**Important:** this example must be updated whenever the `metrics.Recorder` interface changes. The method names used here match the interface defined in `metrics/recorder.go`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PrometheusRecorder

type PrometheusRecorder struct {
	// contains filtered or unexported fields
}

PrometheusRecorder is a MetricsRecorder implementation using Prometheus.

func NewPrometheusRecorder

func NewPrometheusRecorder(reg prometheus.Registerer) *PrometheusRecorder

NewPrometheusRecorder creates a new PrometheusRecorder and registers all metrics with the provided Prometheus registerer.

func (*PrometheusRecorder) RecordClaimAttempt

func (p *PrometheusRecorder) RecordClaimAttempt(streamName string, success bool, duration time.Duration)

func (*PrometheusRecorder) RecordKspNotification

func (p *PrometheusRecorder) RecordKspNotification(streamName string)

func (*PrometheusRecorder) RecordKspNotificationDropped

func (p *PrometheusRecorder) RecordKspNotificationDropped()

func (*PrometheusRecorder) RecordLockAcquisitionAttempt

func (p *PrometheusRecorder) RecordLockAcquisitionAttempt(streamName string, success bool, duration time.Duration)

func (*PrometheusRecorder) RecordLockExtensionAttempt

func (p *PrometheusRecorder) RecordLockExtensionAttempt(streamName string, success bool)

func (*PrometheusRecorder) RecordLockReleaseAttempt

func (p *PrometheusRecorder) RecordLockReleaseAttempt(streamName string, success bool)

func (*PrometheusRecorder) RecordStartupRecovery

func (p *PrometheusRecorder) RecordStartupRecovery(success bool, unackedCount int, duration time.Duration)

RecordStartupRecovery implements the interface method for startup recovery.

func (*PrometheusRecorder) RecordStreamProcessingEnd

func (p *PrometheusRecorder) RecordStreamProcessingEnd(streamName string, end time.Time)

func (*PrometheusRecorder) RecordStreamProcessingStart

func (p *PrometheusRecorder) RecordStreamProcessingStart(streamName string, start time.Time)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL