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

Make prometheus monitoring optional #29

Merged
merged 3 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ 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))
} else {
logger.Log.Info("prometheus is disabled, the metrics reporter will not be enabled")
}

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"))
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (c *Config) fillDefaultValues() {
"pitaya.metrics.statsd.prefix": "pitaya.",
"pitaya.metrics.statsd.rate": 1,
"pitaya.metrics.prometheus.port": 9090,
"pitaya.metrics.prometheus.enabled": false,
"pitaya.metrics.tags": map[string]string{},
}

Expand Down
14 changes: 14 additions & 0 deletions metrics/constants.go
Original file line number Diff line number Diff line change
@@ -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"
)
12 changes: 1 addition & 11 deletions metrics/prometheus_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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",
Expand Down