Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
iimos committed Sep 11, 2020
1 parent 7ddfc50 commit ae04ce6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# saramaprom
This is a prometheus metrics reporter for the sarama library.
It is based on is based on https://github.com/deathowl/go-metrics-prometheus library.
[![GoDoc](https://godoc.org/github.com/iimos/saramaprom?status.png)](http://godoc.org/github.com/iimos/saramaprom)
[![Go Report](https://goreportcard.com/badge/github.com/iimos/saramaprom)](https://goreportcard.com/report/github.com/iimos/saramaprom)

Usage:
This is a prometheus metrics reporter for the [sarama](https://github.com/Shopify/sarama) library.
It is based on https://github.com/deathowl/go-metrics-prometheus library.

## Installation
```console
go get github.com/iimos/saramaprom
```

## Usage

```go
import (
Expand Down Expand Up @@ -39,4 +47,8 @@ type Options struct {
// Debug turns on debug logging.
Debug bool
}
```
```

## Requirements

Go 1.13 or above.
5 changes: 4 additions & 1 deletion saramaprom.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

// Options holds optional params for ExportMetrics.
type Options struct {
// PrometheusRegistry is prometheus registry. Default prometheus.DefaultRegisterer.
PrometheusRegistry prometheus.Registerer
Expand All @@ -31,7 +32,7 @@ type Options struct {
Debug bool
}

// ExportMetric exports metrics from metricsRegistry to prometheus registry.
// ExportMetrics exports metrics from go-metrics to prometheus.
func ExportMetrics(ctx context.Context, metricsRegistry MetricsRegistry, opt Options) error {
if opt.PrometheusRegistry == nil {
opt.PrometheusRegistry = prometheus.DefaultRegisterer
Expand Down Expand Up @@ -84,6 +85,8 @@ func ExportMetrics(ctx context.Context, metricsRegistry MetricsRegistry, opt Opt
return nil
}

// MetricsRegistry is an interface for 'github.com/rcrowley/go-metrics'.Registry
// which is used for metrics in sarama.
type MetricsRegistry interface {
Each(func(name string, i interface{}))
}

0 comments on commit ae04ce6

Please sign in to comment.