Skip to content

Commit

Permalink
feat: New player_info metric
Browse files Browse the repository at this point in the history
closes #11
  • Loading branch information
armsnyder committed Jul 1, 2024
1 parent 0f76d26 commit 53af24d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ Metrics names are prefixed with a namespace (default `a2s_`).
Name | Help | Labels
--- | --- | ---
player_count | Total number of connected players. | server_name
player_duration | Time (in seconds) player has been connected to the server. | server_name player_name player_index
player_score | Player's score (usually \"frags\" or \"kills\"). | server_name player_name player_index
player_the_ship_deaths | Player's deaths in a The Ship server. | server_name player_name player_index
player_the_ship_money | Player's money in a The Ship server. | server_name player_name player_index
player_duration | Time (in seconds) player has been connected to the server. | server_name,player_name,player_index
player_info | Non-numerical player info, including player_name and player_index. The value is 1, and the info is in the labels. | server_name,player_name,player_index
player_score | Player's score (usually \"frags\" or \"kills\"). | server_name,player_name,player_index
player_the_ship_deaths | Player's deaths in a The Ship server. | server_name,player_name,player_index
player_the_ship_money | Player's money in a The Ship server. | server_name,player_name,player_index
player_up | Was the last player info query successful. |
server_bots | Number of bots on the server. | server_name
server_info | Non-numerical server info, including server_steam_id and version. The value is 1, and info is in the labels. | server_name map folder game server_type server_os version server_id keywords server_game_id server_steam_id the_ship_mode source_tv_name
server_info | Non-numerical server info, including server_steam_id and version. The value is 1, and info is in the labels. | server_name,map,folder,game,server_type,server_os,version,server_id,keywords,server_game_id,server_steam_id,the_ship_mode,source_t
v_name
server_max_players | Maximum number of players the server reports it can hold. | server_name
server_players | Number of players on the server. | server_name
server_port | The server's game port number. | server_name
Expand Down
2 changes: 2 additions & 0 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func New(namespace, addr string, excludePlayerMetrics bool, clientOptions ...fun
basicDesc("server_the_ship_duration", "Time (in seconds) before a player is arrested while being witnessed in a The Ship server.")

basicDesc("player_count", "Total number of connected players.")
playerDesc("player_info", "Non-numerical player info, including player_name and player_index. The value is 1, and the info is in the labels.")
playerDesc("player_duration", "Time (in seconds) player has been connected to the server.")
playerDesc("player_score", `Player's score (usually "frags" or "kills").`)
playerDesc("player_the_ship_deaths", "Player's deaths in a The Ship server.")
Expand Down Expand Up @@ -221,6 +222,7 @@ func (c *Collector) collectPlayerInfo(playerInfo *a2s.PlayerInfo, add adder) {
for _, player := range c.uniquePlayers(playerInfo.Players) {
labelValues := []string{player.Name, fmt.Sprintf("%d", player.Index)}

add("player_info", 1, labelValues...)
add("player_duration", float64(player.Duration), labelValues...)
add("player_score", float64(player.Score), labelValues...)

Expand Down
4 changes: 4 additions & 0 deletions internal/collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func TestCollector(t *testing.T) {
expectGauge{value: 32, labels: map[string]string{"server_name": "foo", "player_index": "0", "player_name": "jon"}},
expectGauge{value: 64, labels: map[string]string{"server_name": "foo", "player_index": "0", "player_name": "alice"}},
)
testAssertGauge(t, metrics, "player_info",
expectGauge{value: 1, labels: map[string]string{"server_name": "foo", "player_index": "0", "player_name": "jon"}},
expectGauge{value: 1, labels: map[string]string{"server_name": "foo", "player_index": "0", "player_name": "alice"}},
)
}

func TestCollector_ExcludePlayerMetrics(t *testing.T) {
Expand Down

0 comments on commit 53af24d

Please sign in to comment.