Skip to content

Commit 93cbde3

Browse files
Migrate to prom-ex metrics (#1198)
* Update grafana dashboard * feat: add prom_ex dependency and update required dependencies had to update plug and finch to update telemetry_poller for prom_ex * feat: add prom ex module to gather metrics from beam * feat: add basic prom ex code and plugin * replicate telemetry module events using prom ex * remove duplicate bot registry * remove telemetry module * restore vm metrics event they are already being generated by telemetry_poller, and we were registering them before so I'll keep these so as not to break pre-existing grafana panels * use pre-existing metrics_endpoint_port * remove deleted module from application * fix: use underscore for big numbers * run formatter * Fix typo Co-authored-by: Nicolás Sanchez <[email protected]> * add missing bots count metric --------- Co-authored-by: Nicolas Sanchez <[email protected]>
1 parent c4ee6db commit 93cbde3

File tree

8 files changed

+172
-169
lines changed

8 files changed

+172
-169
lines changed

apps/arena/lib/arena/application.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ defmodule Arena.Application do
2424
Arena.Authentication.GatewaySigner,
2525
Arena.Bots.BotSupervisor,
2626
Arena.Bots.PathfindingGrid,
27+
Arena.PromEx,
2728
# Start a worker by calling: Arena.Worker.start_link(arg)
2829
# {Arena.Worker, arg},
2930
# Start to serve requests, typically the last entry
30-
ArenaWeb.Telemetry,
3131
ArenaWeb.Endpoint
3232
]
3333

apps/arena/lib/arena/prom_ex.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule Arena.PromEx do
2+
@moduledoc """
3+
This module integrates the PromEx library. It sets up PromEx plugins and pre-built dashboards for the node.
4+
"""
5+
use PromEx, otp_app: :arena
6+
7+
@impl true
8+
def plugins() do
9+
[
10+
PromEx.Plugins.Beam,
11+
Arena.PromExPlugin
12+
]
13+
end
14+
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
defmodule Arena.PromExPlugin do
2+
@moduledoc """
3+
This module defines our custom PromEx plugin.
4+
It contains all our custom metrics that are displayed on the grafana dashboard.
5+
"""
6+
7+
use PromEx.Plugin
8+
9+
@impl true
10+
def event_metrics(_opts) do
11+
[
12+
Event.build(:game_metrics, [
13+
sum("arena.game.count", description: "Number of games in progress"),
14+
## TODO: this metric is an attempt to gather data to properly set the buckets for the distribution metric below
15+
last_value("arena.game.tick.duration_measure",
16+
description: "Last game tick duration",
17+
unit: {:native, :nanosecond}
18+
),
19+
## TODO: Buckets probably need to be redefined, currently they all fall under the first bucket
20+
distribution("arena.game.tick.duration",
21+
description: "Time spent on running a game tick",
22+
unit: {:native, :nanosecond},
23+
reporter_options: [buckets: [7_500_000.0, 15_000_000.0, 22_500_000.0]]
24+
),
25+
sum("arena.clients.count", description: "Number of clients (websockets) connected"),
26+
sum([:bots, :count], description: "Amount of active bots")
27+
]),
28+
Event.build(:vm_metrics, [
29+
last_value("vm.memory.total", unit: {:byte, :kilobyte}),
30+
last_value("vm.total_run_queue_lengths.total", description: "Total run queue length of CPU and IO schedulers"),
31+
last_value("vm.total_run_queue_lengths.cpu", description: "Run queue length of CPU scheduler"),
32+
last_value("vm.total_run_queue_lengths.io", description: "Run queue length of IO scheduler")
33+
])
34+
]
35+
end
36+
37+
@impl true
38+
def polling_metrics(_opts) do
39+
poll_rate = 10_000
40+
41+
[
42+
Polling.build(:periodic_measurements, poll_rate, {Arena.Utils, :message_queue_lengths, []}, [
43+
# All BEAM processes message queues
44+
last_value([:vm, :message_queue, :length], tags: [:process]),
45+
# Bots
46+
distribution([:bots, :message_queue, :length],
47+
reporter_options: [buckets: [0, 10, 100, 1_000, 10_000, 100_000]]
48+
),
49+
# GameUpdater
50+
distribution([:game_updater, :message_queue, :length],
51+
reporter_options: [buckets: [0, 10, 100, 1_000, 10_000, 100_000]]
52+
)
53+
])
54+
]
55+
end
56+
end

apps/arena/lib/arena_web/telemetry.ex

Lines changed: 0 additions & 70 deletions
This file was deleted.

apps/arena/mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ defmodule Arena.MixProject do
5555
{:plug_cowboy, "~> 2.5"},
5656
{:toxiproxy_ex, "~> 1.1.1"},
5757
{:joken, "~> 2.6"},
58-
{:new_relic_agent, "~> 1.0", only: [:prod]}
58+
{:new_relic_agent, "~> 1.0", only: [:prod]},
59+
{:prom_ex, "~> 1.11.0"}
5960
]
6061
end
6162

config/runtime.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ metrics_endpoint_port =
5858
config :arena, :gateway_url, System.get_env("GATEWAY_URL") || "http://localhost:4001"
5959
config :arena, :metrics_endpoint_port, metrics_endpoint_port
6060

61+
config :arena, Arena.PromEx,
62+
metrics_server: [
63+
port: metrics_endpoint_port,
64+
auth_strategy: :none
65+
]
66+
6167
if System.get_env("PHX_SERVER") do
6268
config :arena, ArenaWeb.Endpoint, server: true
6369
end

0 commit comments

Comments
 (0)