graylog-labs / graylog-plugin-metrics-reporter

Graylog Metrics Reporter Plugins
https://www.graylog.org/
GNU General Public License v3.0
80 stars 18 forks source link

New config flag to disable prometheus pushgateway #17

Closed gianrubio closed 7 years ago

gianrubio commented 7 years ago

The current prometheus plugin always initialise pushing metrics to a prometheus server. I prefer to scrape/pull my prometheus endpoints rather than pushing. Besides that, if the pushgateway is not configured, this plugin make the logs polluted.

To avoid this behaviour, I made this PR to pass a flag to disable the pushgateway.

Flag

metrics_prometheus_pushgateway_disabled: true

Polluted logs

[graylog-master-2794354343-pjl6t] 2017-02-23 15:49:22,568 ERROR: org.graylog.plugins.metrics.prometheus.PushGatewayPeriodical - Error while sending metrics to Prometheus Pushgateway
[graylog-master-2794354343-pjl6t] java.net.ConnectException: Connection refused (Connection refused)
[graylog-master-2794354343-pjl6t] at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.NetworkClient.doConnect(NetworkClient.java:175) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.www.http.HttpClient.openServer(HttpClient.java:432) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.www.http.HttpClient.openServer(HttpClient.java:527) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.www.http.HttpClient.<init>(HttpClient.java:211) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.www.http.HttpClient.New(HttpClient.java:308) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.www.http.HttpClient.New(HttpClient.java:326) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1202) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:966) ~[?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at io.prometheus.client.exporter.PushGateway.doRequest(PushGateway.java:253) ~[metrics-reporter-prometheus-1.4.0.jar:?]
[graylog-master-2794354343-pjl6t] at io.prometheus.client.exporter.PushGateway.push(PushGateway.java:96) ~[metrics-reporter-prometheus-1.4.0.jar:?]
[graylog-master-2794354343-pjl6t] at org.graylog.plugins.metrics.prometheus.PushGatewayPeriodical.doRun(PushGatewayPeriodical.java:50) [metrics-reporter-prometheus-1.4.0.jar:?]
[graylog-master-2794354343-pjl6t] at org.graylog2.plugin.periodical.Periodical.run(Periodical.java:77) [graylog.jar:?]
[graylog-master-2794354343-pjl6t] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_111]
[graylog-master-2794354343-pjl6t] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
CLAassistant commented 7 years ago

CLA assistant check
All committers have signed the CLA.

joschi commented 7 years ago

@gianrubio This PR basically just duplicates the functionality which the metrics_prometheus_enabled setting already has.

Simply set metrics_prometheus_enabled = false in the configuration file to disable pushing metrics to a Prometheus Pushgateway. The HTTP resource at /api/plugins/org.graylog.plugins.metrics.prometheus/metrics will be registered nonetheless.