Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sarama metrics #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ This image is configurable using different flags
| web.telemetry-path | /metrics | Path under which to expose metrics |
| log.level | info | Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal] |
| log.enable-sarama | false | Turn on Sarama logging |
| metric.disable-sarama | true | Whether to disable sarama monitoring metrics or not | |

### Notes

Expand Down
11 changes: 1 addition & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,15 @@ go 1.16
require (
github.com/Shopify/sarama v1.28.0
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/deathowl/go-metrics-prometheus v0.0.0-20200518174047-74482eab5bfb
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/krallistic/kazoo-go v0.0.0-20170526135507-a15279744f4e
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/profile v1.2.1 // indirect
github.com/prometheus/client_golang v1.10.0
github.com/prometheus/common v0.25.0
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/promu v0.12.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)
344 changes: 21 additions & 323 deletions go.sum

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions kafka_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/Shopify/sarama"
prometheusmetrics "github.com/deathowl/go-metrics-prometheus"
"github.com/krallistic/kazoo-go"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -78,6 +79,7 @@ type kafkaOpts struct {
uriZookeeper []string
labels string
metadataRefreshInterval string
disableMetrics bool
}

// CanReadCertAndKey returns true if the certificate and key files already exists,
Expand Down Expand Up @@ -526,6 +528,7 @@ func main() {
kingpin.Flag("zookeeper.server", "Address (hosts) of zookeeper server.").Default("localhost:2181").StringsVar(&opts.uriZookeeper)
kingpin.Flag("kafka.labels", "Kafka cluster name").Default("").StringVar(&opts.labels)
kingpin.Flag("refresh.metadata", "Metadata refresh interval").Default("30s").StringVar(&opts.metadataRefreshInterval)
kingpin.Flag("metric.disable-sarama", "Whether to disable sarama monitoring metrics or not").Default("true").BoolVar(&opts.disableMetrics)

plog.AddFlags(kingpin.CommandLine)
kingpin.Version(version.Print("kafka_exporter"))
Expand Down Expand Up @@ -655,6 +658,12 @@ func setup(
plog.Fatalln(err)
}
defer exporter.client.Close()
if !opts.disableMetrics {
metrics.UseNilMetrics = false
prometheusClient := prometheusmetrics.NewPrometheusProvider(exporter.client.Config().MetricRegistry, "sarama", "kafka", prometheus.DefaultRegisterer, 1*time.Second)
go prometheusClient.UpdatePrometheusMetrics()
// prometheusClient.UpdatePrometheusMetricsOnce()
}
prometheus.MustRegister(exporter)

http.Handle(metricsPath, promhttp.Handler())
Expand Down
11 changes: 11 additions & 0 deletions vendor/github.com/deathowl/go-metrics-prometheus/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 201 additions & 0 deletions vendor/github.com/deathowl/go-metrics-prometheus/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/deathowl/go-metrics-prometheus/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/deathowl/go-metrics-prometheus/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading