[RADIATOR] Prometheus statistics output

Jani Lahti jani at radiatorsoftware.com
Tue May 27 13:20:49 UTC 2025


Resurrecting an old thread about native Prometheus metrics directly from
Radiator. I noticed the old community solution by Tarko Tikan is not
working as expected with current Radiator versions. Here's an updated
version of the PageNotFoundHook script:

# Prometheus metrics from Radiator, updated
#
# Usage:
#
# Add PageNotFoundHook to Radiator config and save this script
# as /etc/radiator/metrics.pl
#
# To access metrics without login, disable authentication in
# ServerHTTP and add DefaultPrivilegeLevel 1 (for https enable
# TLS in ServerHTTP):
#
# curl http://127.0.0.1:9048/metrics
#
# If web authentication is enabled, first call login url to
# fetch a session key cookie:
#
# curl -c /tmp/cookies -d "username=mikem&password=fred"
http://127.0.0.1:9048/login
# curl -b /tmp/cookies http://127.0.0.1:9048/metrics
#
# Example snippet for /etc/radiator/radiator.conf:
#
# <ServerHTTP>
#   DefaultPrivilegeLevel 1
#   PageNotFoundHook file:"%D/metrics.pl"
# </ServerHTTP>
#
# Notes:
# Radiator 4.21 internal change: ServerConfig => StatslogGeneric

use strict;
use warnings;

sub {
  my $uri = $_[0];

  if ($uri !~ m%^/metrics/?$%) {
    return;
  }

  my %headers = ( "Content-Type"=>"text/plain; version=0.0.4" );
  my $stats;
  foreach (sort keys %Radius::StatsLogGeneric::statistic_names) {
    my $name = "radiator_$_";
    my $value = $main::config->{Statistics}{$_};
    my $help = $Radius::StatsLogGeneric::statistic_names{$_};
    $stats .= sprintf "# HELP %s %s\n", $name, $help;
    $stats .= sprintf "%s %f\n", $name, $value;
  }
  return (200, $stats, %headers);
}

The output of the script is not utilising the full power of OpenMetrics
1.0.0 spec, so Content-Type is set accordingly. It should be easy to update
output to application/openmetrics-text, though. This script can also be
used as a starting point for exporting Radiator statistics data to other
systems.

You should check the documentation for full configuration of ServerHTTP
block and for any security implications of enabling ServerHTTP.

//jani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.open.com.au/pipermail/radiator/attachments/20250527/7df8cdfc/attachment.html>


More information about the radiator mailing list