Skip to content

Commit

Permalink
add metrics namespace + cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
j-bro committed Oct 30, 2023
1 parent 99639f0 commit c106b47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
10 changes: 0 additions & 10 deletions lib/svrquery/protocol/prom/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (q *queryer) makeQuery() (*QueryResponse, error) {
}

resp := &QueryResponse{}
// TODO: lookup by key (metric name)
for _, v := range metrics {
switch *v.Name {
case currentPlayersMetricName:
Expand Down Expand Up @@ -78,14 +77,5 @@ func (q *queryer) makeQuery() (*QueryResponse, error) {
}
}

// ServerInfo.BuildID
// ServerInfo.Port

// serverRules?
// query.PlayerInfo.Players
// query.TeamInfo.Teams

// query.Metrics

return resp, nil
}
8 changes: 4 additions & 4 deletions lib/svrquery/protocol/prom/types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package prom

const (
currentPlayersMetricName = "current_players"
maxPlayersMetricName = "max_players"
serverInfoMetricName = "server_info"
metricNamespace = "gameserver_"
currentPlayersMetricName = metricNamespace + "current_players"
maxPlayersMetricName = metricNamespace + "max_players"
serverInfoMetricName = metricNamespace + "server_info"
)

// QueryResponse is the combined response to a query request
Expand All @@ -14,7 +15,6 @@ type QueryResponse struct {
GameType string `json:"game_type"`
MapName string `json:"map"`
Port int64 `json:"port"`
//BuildID string `json:"build_id"`
}

// MaxClients implements protocol.Responser, returns the maximum number of clients.
Expand Down
10 changes: 7 additions & 3 deletions lib/svrsample/protocol/prom/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (

var _ prometheus.Collector = (*metrics)(nil)

const (
metricNamespace = "gameserver"
)

// metrics holds the current prometheus metrics data for the server
type metrics struct {
currentPlayers prometheus.Gauge
Expand All @@ -18,19 +22,19 @@ type metrics struct {
func newMetrics(reg prometheus.Registerer) *metrics {
m := &metrics{
currentPlayers: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "",
Namespace: metricNamespace,
Subsystem: "",
Name: "current_players",
Help: "Number of players currently connected to the server.",
}),
maxPlayers: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "",
Namespace: metricNamespace,
Subsystem: "",
Name: "max_players",
Help: "Maximum number of players that can connect to the server.",
}),
serverInfo: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "",
Namespace: metricNamespace,
Subsystem: "",
Name: "server_info",
Help: "Server status info.",
Expand Down

0 comments on commit c106b47

Please sign in to comment.