Skip to content

Commit 1ce466e

Browse files
authored
Attach pool_size metrics in poolex_example app (#82)
1 parent b408d15 commit 1ce466e

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

examples/poolex_example/lib/poolex_example/application.ex

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ defmodule PoolexExample.Application do
99
pool_id: :worker_pool,
1010
worker_module: PoolexExample.Worker,
1111
workers_count: 5,
12-
max_overflow: 2}
12+
max_overflow: 2,
13+
pool_size_metrics: true}
1314
]
1415

16+
:telemetry.attach(
17+
"poolex_metrics",
18+
[:poolex, :metrics, :pool_size],
19+
&PoolexExample.MetricsHandler.handle_event/4,
20+
nil
21+
)
22+
1523
Supervisor.start_link(children, strategy: :one_for_one)
1624
end
1725
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule PoolexExample.MetricsHandler do
2+
def handle_event([:poolex, :metrics, :pool_size], measurements, metadata, _config) do
3+
IO.puts("""
4+
[Pool: #{metadata.pool_id}]:
5+
- Idle workers: #{measurements.idle_workers_count}
6+
- Busy workers: #{measurements.busy_workers_count}
7+
- Overflowed: #{measurements.overflowed}
8+
""")
9+
end
10+
end

examples/poolex_example/mix.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ defmodule PoolexExample.MixProject do
2121
# Run "mix help deps" to learn about dependencies.
2222
defp deps do
2323
[
24+
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
2425
{:poolex, path: "../.."},
25-
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false}
26+
{:telemetry, "~> 1.0"}
2627
]
2728
end
2829
end

examples/poolex_example/mix.lock

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
%{
2-
"dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"},
2+
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
33
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
44
"poolex": {:hex, :poolex, "0.4.0", "cc3c5eb921a2ea5886953a2ea3beb0e36148d7d91dd9b628df74c3abb5ea7981", [:mix], [], "hexpm", "0441bf433f8fca4127b68c5985354cb772bba049057bca842f6e73df4f631c17"},
5+
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
6+
"telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"},
57
}

0 commit comments

Comments
 (0)