Skip to content

Menu

← Blog

Monitoring Asterisk with Prometheus

Since Asterisk 17, metrics come out in Prometheus format: what they are and how to scrape them, with a small Docker project to try.

VoIP4 min read
In this article
  1. Setup: Asterisk and Prometheus in Docker
  2. Docker Compose
  3. Configuring Asterisk
  4. Configuring Prometheus
  5. Checking the result

Asterisk has exported metrics in Prometheus format since version 17.0.0. In this post we take a quick look at which metrics it exports and how to set up a Prometheus job to scrape them.

Setup: Asterisk and Prometheus in Docker

Let's set up a minimal project:

asterisk-prometheus/
asterisk-prometheus/├── compose.yaml├── asterisk/│ ├── http.conf│ └── prometheus.conf└── prometheus/ └── prometheus.yml

Docker Compose

Asterisk has no official Docker image. For our demo we use the excellent andrius/asterisk, which publishes Asterisk builds on several distributions. Not every tag includes res_prometheus, so we use the 22.11.0_debian-trixie tag (Asterisk 22 LTS on Debian 13).

compose.yamlYAML
services:  asterisk:    image: andrius/asterisk:22.11.0_debian-trixie    volumes:      - ./asterisk/http.conf:/etc/asterisk/http.conf:ro      - ./asterisk/prometheus.conf:/etc/asterisk/prometheus.conf:ro    ports:      - "8088:8088"  prometheus:    image: prom/prometheus:v3.13.4    volumes:      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro    ports:      - "9090:9090"    depends_on:      - asterisk

Configuring Asterisk

Asterisk exposes its metrics through its built-in HTTP server, which is disabled by default. To turn it on, change a few lines in http.conf:

asterisk/http.confCONF
[general]enabled = yesbindaddr = 0.0.0.0bindport = 8088

To turn on the Asterisk exporter, edit prometheus.conf instead:

asterisk/prometheus.confCONF
[general]enabled = yesuri = metrics; core_metrics_enabled = yes

uri is the path the metrics are served on, in our case http://<host>:8088/metrics. With core_metrics_enabled you also get some metrics about the process itself: uptime, time since the last reload…

Configuring Prometheus

The Prometheus config needs a job that points at the container:

prometheus/prometheus.ymlYAML
global:  scrape_interval: 15sscrape_configs:  - job_name: asterisk    static_configs:      - targets: ["asterisk:8088"]

Checking the result

To start the stack:

asterisk-prometheus
$ docker compose up -d

To read the metrics live:

asterisk-prometheus
$ curl -s localhost:8088/metricsasterisk_channels_count{eid="82:57:d5:8c:07:a7"} 0asterisk_calls_sum{eid="82:57:d5:8c:07:a7"} 0asterisk_calls_count{eid="82:57:d5:8c:07:a7"} 0asterisk_endpoints_count{eid="82:57:d5:8c:07:a7"} 0asterisk_bridges_count{eid="82:57:d5:8c:07:a7"} 0asterisk_core_properties{eid="82:57:d5:8c:07:a7",version="22.11.0",...} 1asterisk_core_uptime_seconds{eid="82:57:d5:8c:07:a7"} 2asterisk_core_last_reload_seconds{eid="82:57:d5:8c:07:a7"} 2asterisk_core_scrape_time_ms{eid="82:57:d5:8c:07:a7"} 0...

At http://localhost:9090/targets the asterisk job should show as UP.

VoIP

Want to know more?

Write to us or give us a call: we'll tell you how we work and what we could do for your company.

Our VoIP serviceContact us

More articles

  • VoIP

    RFC 8599 in practice: SIP push notifications with OpenSIPS and Gorush

    How we ring an app that has been closed: OpenSIPS holds the INVITE, Gorush sends the push notification and the call goes through once the phone registers again.

    · 6 min
  • Development

    A smarter office, right at your fingertips

    With Home Assistant we control the office's lights, air conditioning, cameras and other devices from one place, phone included.

    · 3 min
  • Helpdesk

    A management system for hardware call-outs across Italy

    The management system we built for hardware support: field engineers, devices, contacts and tickets.

    · 3 min

All articles