diff --git a/README.md b/README.md index e4e5be1f..31aa84ee 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ Alternatively a Dockerfile is supplied: docker run -p 9150:9150 quay.io/prometheus/memcached-exporter:latest ``` +## mcrouter + +In order to use the memcached_exporter with [mcrouter](https://github.com/facebook/mcrouter) the "STATS SETTINGS" collection needs to be disabled. + +```sh +./memcached_exporter --no.memcached.stats.settings +``` + ## Collectors The exporter collects a number of statistics from the server: diff --git a/cmd/memcached_exporter/main.go b/cmd/memcached_exporter/main.go index 798b18a9..05549c36 100644 --- a/cmd/memcached_exporter/main.go +++ b/cmd/memcached_exporter/main.go @@ -36,6 +36,7 @@ func main() { address = kingpin.Flag("memcached.address", "Memcached server address.").Default("localhost:11211").String() timeout = kingpin.Flag("memcached.timeout", "memcached connect timeout.").Default("1s").Duration() pidFile = kingpin.Flag("memcached.pid-file", "Optional path to a file containing the memcached PID for additional metrics.").Default("").String() + getSettings = kingpin.Flag("memcached.stats.settings", "Enable collection of STATS SETTINGS.").Default("true").Bool() webConfig = webflag.AddFlags(kingpin.CommandLine) listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9150").String() metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() @@ -51,7 +52,7 @@ func main() { level.Info(logger).Log("msg", "Build context", "context", version.BuildContext()) prometheus.MustRegister(version.NewCollector("memcached_exporter")) - prometheus.MustRegister(exporter.New(*address, *timeout, logger)) + prometheus.MustRegister(exporter.New(*address, *timeout, *getSettings, logger)) if *pidFile != "" { procExporter := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{ diff --git a/pkg/exporter/exporter.go b/pkg/exporter/exporter.go index 3421dcca..7fb5c706 100644 --- a/pkg/exporter/exporter.go +++ b/pkg/exporter/exporter.go @@ -40,6 +40,8 @@ type Exporter struct { timeout time.Duration logger log.Logger + getSettings bool + up *prometheus.Desc uptime *prometheus.Desc time *prometheus.Desc @@ -109,11 +111,12 @@ type Exporter struct { } // New returns an initialized exporter. -func New(server string, timeout time.Duration, logger log.Logger) *Exporter { +func New(server string, timeout time.Duration, getSettings bool, logger log.Logger) *Exporter { return &Exporter{ - address: server, - timeout: timeout, - logger: logger, + address: server, + timeout: timeout, + logger: logger, + getSettings: getSettings, up: prometheus.NewDesc( prometheus.BuildFQName(Namespace, "", "up"), "Could the memcached server be reached.", @@ -602,17 +605,20 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { level.Error(e.logger).Log("msg", "Failed to collect stats from memcached", "err", err) up = 0 } - statsSettings, err := c.StatsSettings() - if err != nil { - level.Error(e.logger).Log("msg", "Could not query stats settings", "err", err) - up = 0 - } if err := e.parseStats(ch, stats); err != nil { up = 0 } - if err := e.parseStatsSettings(ch, statsSettings); err != nil { - up = 0 + + if e.getSettings { + statsSettings, err := c.StatsSettings() + if err != nil { + level.Error(e.logger).Log("msg", "Could not query stats settings", "err", err) + up = 0 + } + if err := e.parseStatsSettings(ch, statsSettings); err != nil { + up = 0 + } } ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, up)