# Working with metrics

You 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:

```elixir
children = [
  {Poolex, 
    worker_module: SomeWorker,
    workers_count: 5,
    pool_size_metrics: true}
]
```

You can handle them by using `:telemetry.attach/4`:

```elixir
: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](https://github.com/general-CbIC/poolex/blob/develop/examples/poolex_example/lib/poolex_example/metrics_handler.ex).

[More about using `telemetry`](https://hexdocs.pm/telemetry/readme.html).

## Integration with PromEx

There is a plugin that works with the [PromEx](https://github.com/akoutmos/prom_ex) library: [Poolex.PromEx](https://hex.pm/packages/poolex_prom_ex).

[Installation of this plugin](https://hexdocs.pm/poolex_prom_ex/readme.html#installation).
