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 1 commit
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
5 changes: 4 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking of changing this default value to false and logging that monitoring is disabled... this would make development easier IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it enabled by default to avoid breaking existing applications, but I agree that leaving it disabled by default would avoid some pain when running locally

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we just need to ensure to add the env var to turn it on on the current production applications and then it will be safe to turn it off by default :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled it by default now

}

for param := range defaultsMap {
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