# Asterisk MES (Media Experience Score) in the FreePBX CDR: Log Call Quality per Call (Tested)

Source: https://srvscripts.com/guides/asterisk-mes-freepbx-cdr/
Updated: 2026-11-02
Publisher: srvScripts (https://srvscripts.com/)

**Short answer:** Asterisk MES (Media Experience Score, 0–100) is calculated for each RTP stream from jitter, packet loss and round-trip time, but FreePBX 17 does not store it in the CDR. A small hangup handler in `extensions_custom.conf` can copy it into the CDR `userfield`. On our lab a clean call scored 88 and a call with 30 ms ±20 ms delay and 5% loss scored 69 on average. (Reviewed October 2026.)

In short: Asterisk MES (Media Experience Score, 0–100) is calculated for each RTP stream from jitter, packet loss and round-trip time, but FreePBX 17 does not store it in the CDR. A small hangup handle…

MES is Asterisk’s own call-quality figure, added alongside the RTCP statistics. It is not a MOS from listeners, but it moves the same way: a perfect network gives about the high 80s, and loss and jitter pull it down. We stored it in the CDR on a FreePBX 17 lab and degraded the network on purpose to see the difference.

## Where MES comes from

The [Asterisk MES announcement](https://www.asterisk.org/asterisk-media-experience-score) describes a 0–100 score from round-trip time, jitter and lost packets, with about 85 as the best you can expect. On Asterisk 22.11 you can read it in three places:

- `${CHANNEL(rtcp,txmes)}` and `${CHANNEL(rtcp,rxmes)}`: the current score. The naming is confusing: `txmes` is Asterisk’s analysis of the audio it receives, `rxmes` is based on RTCP reports from the far end.

- `${CHANNEL(rtcp,all_mes)}`: minimum, maximum, average and standard deviation.

- `${RTPAUDIOQOSMES}`: the same summary, set when the channel hangs up.

Our FreePBX 17 `cdr` table (cdr module 17.0.11.3) has no MES column, so the value has to go into an existing field. `userfield` is a `varchar(255)` that FreePBX does not fill by default.

## The dialplan

Back up `/etc/asterisk/extensions_custom.conf` first, then add the lines below to it. The handler cuts the minimum and average out of `RTPAUDIOQOSMES` and appends them to the userfield, after anything another module or your own dialplan already put there; a call without audio statistics is left alone. The predial hook attaches it to every outbound trunk call:

```
cp -p /etc/asterisk/extensions_custom.conf /etc/asterisk/extensions_custom.conf.bak-mes
```

The lines to add:

```
; Store the call quality (Asterisk MES, 0-100) of the calling channel in the CDR userfield.
; Keeps anything already in the userfield and appends the MES values after it.
[srvs-mes-to-cdr]
exten => s,1,GotoIf($["${RTPAUDIOQOSMES}" = ""]?done)
 same => n,Set(F_AVG=${CUT(RTPAUDIOQOSMES,\;,3)})
 same => n,Set(F_MIN=${CUT(RTPAUDIOQOSMES,\;,1)})
 same => n,Set(MES=mes_avg=${CUT(F_AVG,=,2)} mes_min=${CUT(F_MIN,=,2)})
 same => n,GotoIf($["${CDR(userfield)}" = ""]?empty)
 same => n,Set(CDR(userfield)=${CDR(userfield)} ${MES})
 same => n,Goto(done)
 same => n(empty),Set(CDR(userfield)=${MES})
 same => n(done),Return()
; Outbound calls through a trunk
[macro-dialout-trunk-predial-hook]
exten => s,1,Set(CHANNEL(hangup_handler_push)=srvs-mes-to-cdr,s,1)
 same => n,Return()
```

```
asterisk -rx "dialplan reload"
asterisk -rx "dialplan show s@macro-dialout-trunk-predial-hook"
```

Two details we hit: a semicolon starts a comment in Asterisk config files, so it must be written `\;` inside `CUT()`, otherwise the line is silently cut short; and `CUT()` takes a variable name, so nesting `CUT(CUT(...))` does not work. FreePBX ships an empty `macro-dialout-trunk-predial-hook` in `extensions.conf`; the version in `extensions_custom.conf` replaced it on our server (check with the `dialplan show` command above). If you already use the predial hook for something else, add the `Set` line to it instead. Note that `userfield` holds at most 255 characters, so keep what you append short. To undo, put the backup back and reload the dialplan:

```
cp -p /etc/asterisk/extensions_custom.conf.bak-mes /etc/asterisk/extensions_custom.conf
asterisk -rx "dialplan reload"
```

Calls already written to the CDR keep their userfield.

## Results

| Test call (45 seconds, G.711) | CDR userfield |
| --- | --- |
| Echo test, clean network | mes_avg=088.087887 mes_min=088.087887 |
| Echo test, 30 ms ±20 ms delay and 5% loss (tc netem) | mes_avg=069.269883 mes_min=062.981553 |
| Outbound trunk call, clean network (predial hook) | mes_avg=088.087887 mes_min=088.087887 |
| Echo test, userfield already set to acct=42 by the dialplan | acct=42 mes_avg=088.087887 mes_min=088.087887 |
| Call without audio, userfield set to acct=7 | acct=7 (unchanged) |

```
mysql -N asteriskcdrdb -e "SELECT calldate, src, dst, billsec, userfield FROM cdr
  WHERE userfield LIKE 'mes_avg=%' OR userfield LIKE '% mes_avg=%'
  ORDER BY calldate DESC LIMIT 20"
```

Our test endpoint (SIPp) sent RTP but no RTCP, so the far-end score `rxmes` stayed at 0 and the figures above are Asterisk’s view of the audio it received. With real phones and trunks that send RTCP, the far-end side fills in too. To turn the numbers into averages per trunk or per day, export the CDR and use our [ASR and ACD calculator](https://srvscripts.com/tools/asr-and-acd-calculator/) alongside; for a MOS-style estimate from jitter and loss, see the [VoIP MOS calculator](https://srvscripts.com/tools/voip-mos-calculator/).

## How we tested

- FreePBX 17.0.33.2, Asterisk 22.11.0, Debian 12, 20–21 October 2026.

- Calls from a SIPp test phone sending G.711 RTP: to an echo test extension with the same handler, and out through the lab’s SIPp “carrier” trunk via the predial hook. Network impairment with `tc qdisc add dev lo root netem delay 30ms 20ms loss 5%` on the loopback interface for one call, removed straight afterwards.

- 21 October 2026: the appending version above re-tested with an empty userfield, a userfield already set, and a call without audio.

- Not tested: inbound calls (they need their own hook), calls with real phones and RTCP, and the CDR reports screen in the GUI (the userfield is in the database; whether the report shows it depends on the module version).

## FAQ

### What is a good Asterisk MES?

Asterisk’s announcement describes about 85 as the best to expect on a real network. Our clean lab call scored 88 because it ran over the loopback interface with no real network delay; with 5% loss and 20 ms jitter added it dropped to about 69. Compare calls with each other on your own system rather than against a fixed number.

### Is MES the same as MOS?

No. MOS comes from listeners or models of them; MES is calculated by Asterisk from jitter, loss and round-trip time. Both fall as the network gets worse.

### Does FreePBX show MES in CDR reports?

Our FreePBX 17 lab’s cdr table has no MES column, so the handler above stores it in the userfield. We verified the value in the database; we did not check whether the CDR reports screen displays it.
