From eefee92f833791ae002afde89e1ee14de308a7d3 Mon Sep 17 00:00:00 2001 From: Andre Hahn Date: Thu, 19 Jul 2018 00:07:25 -0300 Subject: [PATCH] Making prometheus monitoring optional --- agent/agent.go | 2 +- app.go | 5 ++++- config/config.go | 1 + metrics/constants.go | 14 ++++++++++++++ metrics/prometheus_reporter.go | 12 +----------- 5 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 metrics/constants.go diff --git a/agent/agent.go b/agent/agent.go index 6198b6b1..9f132373 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -121,7 +121,7 @@ func NewAgent( metricsReporters: metricsReporters, } - // bindng session + // binding session s := session.New(a, true) metrics.ReportNumberOfConnectedClients(metricsReporters, session.SessionCount) a.Session = s diff --git a/app.go b/app.go index e95d75e5..3ca01908 100644 --- a/app.go +++ b/app.go @@ -140,7 +140,10 @@ func Configure( app.metricsReporters = make([]metrics.Reporter, 0) defaultTags := app.config.GetStringMapString("pitaya.metrics.tags") - AddMetricsReporter(metrics.GetPrometheusReporter(serverType, app.config.GetString("pitaya.game"), app.config.GetInt("pitaya.metrics.prometheus.port"), defaultTags)) + if app.config.GetBool("pitaya.metrics.prometheus.enabled") { + logger.Log.Infof("prometheus is enabled, configuring the metrics reporter on port %d", app.config.GetInt("pitaya.metrics.prometheus.port")) + AddMetricsReporter(metrics.GetPrometheusReporter(serverType, app.config.GetString("pitaya.game"), app.config.GetInt("pitaya.metrics.prometheus.port"), defaultTags)) + } if app.config.GetBool("pitaya.metrics.statsd.enabled") { logger.Log.Infof("statsd is enabled, configuring the metrics reporter with host: %s", app.config.Get("pitaya.metrics.statsd.host")) diff --git a/config/config.go b/config/config.go index 2b6f948a..3e5a6d14 100644 --- a/config/config.go +++ b/config/config.go @@ -89,6 +89,7 @@ func (c *Config) fillDefaultValues() { "pitaya.metrics.statsd.rate": 1, "pitaya.metrics.prometheus.port": 9090, "pitaya.metrics.tags": map[string]string{}, + "pitaya.metrics.prometheus.enabled": true, } for param := range defaultsMap { diff --git a/metrics/constants.go b/metrics/constants.go new file mode 100644 index 00000000..ca6cf536 --- /dev/null +++ b/metrics/constants.go @@ -0,0 +1,14 @@ +package metrics + +var ( + // ResponseTime reports the response time of handlers and rpc + ResponseTime = "response_time_ns" + // ConnectedClients represents the number of current connected clients in frontend servers + ConnectedClients = "connected_clients" + // CountServers counts the number of servers of different types + CountServers = "count_servers" + // ChannelCapacity represents the capacity of a channel (available slots) + ChannelCapacity = "channel_capacity" + // DroppedMessages reports the number of dropped messages in rpc server (messages that will not be handled) + DroppedMessages = "dropped_messages" +) diff --git a/metrics/prometheus_reporter.go b/metrics/prometheus_reporter.go index 7366e0a7..3519300e 100644 --- a/metrics/prometheus_reporter.go +++ b/metrics/prometheus_reporter.go @@ -31,16 +31,6 @@ import ( ) var ( - // ResponseTime reports the response time of handlers and rpc - ResponseTime = "response_time_ns" - // ConnectedClients represents the number of current connected clients in frontend servers - ConnectedClients = "connected_clients" - // CountServers counts the number of servers of different types - CountServers = "count_servers" - // ChannelCapacity represents the capacity of a channel (available slots) - ChannelCapacity = "channel_capacity" - // DroppedMessages reports the number of dropped messages in rpc server (messages that will not be handled) - DroppedMessages = "dropped_messages" prometheusReporter *PrometheusReporter once sync.Once ) @@ -58,7 +48,7 @@ func (p *PrometheusReporter) registerMetrics(constLabels map[string]string) { constLabels["game"] = p.game constLabels["serverType"] = p.serverType - // HanadlerResponseTimeMs summaary + // HandlerResponseTimeMs summary p.summaryReportersMap[ResponseTime] = prometheus.NewSummaryVec( prometheus.SummaryOpts{ Namespace: "pitaya",