Working with metrics
View SourceYou can quickly analyze and optimize your pool's production settings using the metrics provided by the library.
Pool size metrics
The Poolex library presents an idle/busy worker count metric. These metrics help estimate a pool load and the number of workers used.
There is also an overflow metric. It shows how long pools are forced to use additional workers.
To enable pool size metrics, you need to set the pool_size_metrics parameter to true on the pool initialization:
children = [
{Poolex,
worker_module: SomeWorker,
workers_count: 5,
pool_size_metrics: true}
]
You can handle them by using :telemetry.attach/4
:
:telemetry.attach(
"my-lovely-pool-size-metrics",
[:poolex, :metrics, :pool_size],
&MyApp.handle_event/4,
nil
)
For example, your application can write metrics to the console: PoolexExample.MetricsHandler.
Integration with PromEx
There is a plugin that works with the PromEx library: Poolex.PromEx.