samp.directory
← Scripts y librerías

roseeast/PawnMetrics

Modern monitoring plugin for SA-MP/open.mp servers with Prometheus-compatible metrics.

Plugin★ 0actualizado sept 2026MITC++
Abrir en GitHub

README.md


Pawn Metrics lets Pawn gamemodes expose server, gameplay, economy, admin, and anti-cheat metrics through a lightweight HTTP endpoint. It is designed for server owners who want modern monitoring with Prometheus, Grafana, uptime dashboards, or simple HTTP scrapers.

Overview

ItemDetail
Plugin namepawn_metrics
TargetSA-MP and open.mp
Plugin typeLegacy SA-MP plugin API & Native open.mp Component
LanguageC++17
Metrics formatPrometheus text exposition format
Default endpointhttp://127.0.0.1:9100/metrics
Config file formatSimple key=value file
External runtime depsNone bundled by Pawn Metrics
Included platformsLinux x86_64, Windows i386
Pawn includepawno/include/pawn_metrics.inc

Features

FeatureNativeNotes
Start exporterMetrics_StartStarts the HTTP metrics endpoint.
Stop exporterMetrics_StopStops the endpoint cleanly.
Set gauge valueMetrics_Set, Metrics_SetIntUseful for online players, queue sizes, loaded houses, etc.
Increment counterMetrics_IncUseful for connects, commands, kills, reports, warnings.
Add numeric valueMetrics_Add, Metrics_AddIntUseful for money created/removed, item flow, query counts.
Labeled metricsMetrics_*LabeledAdds Prometheus labels such as reason="teleport" or type="report".
HistogramsMetrics_ObserveHistogramRecords bucketed observations with default Prometheus-style buckets.
SummariesMetrics_ObserveSummaryRecords _sum and _count observations.
Auth tokenMetrics_SetAuthTokenProtects /metrics with bearer token or ?token= access.
Bind addressMetrics_StartExBinds the exporter to a specific IPv4 address.
Config fileMetrics_LoadConfig, Metrics_StartFromConfigLoads bind address, port, and auth token from file.
Remove metricMetrics_RemoveDeletes one metric from the exporter.
Clear metricsMetrics_ClearResets all registered metrics.
Server helperMetrics_UpdateServerInfoStock helper for server info.
Player helperMetrics_SetPlayersOnlineStock helper for current connected players.

Release Files

Prebuilt release packages are available in release/.

FileFormatContents
release/pawn-metrics-v0.2.0-windows-x86.zipZIPWindows release archive (legacy plugin & native component).
release/pawn-metrics-v0.2.0-linux-x86_64.tar.gztar.gzLinux release archive (legacy plugin & native component).

Package layout:

pawn-metrics-v0.2.0/
  plugins/
    pawn_metrics.so
    pawn_metrics.dll
  components/
    pawn_metrics.so
    pawn_metrics.dll
  pawno/include/
    pawn_metrics.inc
  examples/
    example.pwn
    pawn_metrics.cfg
  README.md
  LICENSE
  CHANGELOG.md

Compatibility

RuntimeStatusNotes
SA-MP Windows serverSupportedUse plugins/pawn_metrics.dll. The included DLL is 32-bit for classic SA-MP Windows servers.
SA-MP Linux serverSupportedUse plugins/pawn_metrics.so. The included Linux binary is x86_64.
open.mp Windows serverSupported (Component & Plugin)Native component: components/pawn_metrics.dll. Legacy plugin: plugins/pawn_metrics.dll.
open.mp Linux serverSupported (Component & Plugin)Native component: components/pawn_metrics.so. Legacy plugin: plugins/pawn_metrics.so.
Native open.mp componentSupportedLoad via "components": ["pawn_metrics"] in config.json. See components/openmp/README.md.

Pawn Metrics does not hook RakNet, patch memory, or depend on internal SA-MP addresses. It only registers Pawn natives and runs a small HTTP listener for metrics scraping.

Installation

1. Install Files

For SA-MP (Legacy Plugin)

Copy the files from plugins/ into your server:

plugins/pawn_metrics.so        -> Linux server plugins folder
plugins/pawn_metrics.dll       -> Windows server plugins folder
pawno/include/pawn_metrics.inc -> Pawn compiler include folder
For open.mp (Native Component - Recommended)

Copy the files from components/ into your server:

components/pawn_metrics.so     -> Linux server components folder
components/pawn_metrics.dll    -> Windows server components folder
pawno/include/pawn_metrics.inc -> Pawn compiler include folder

For Qawno or custom build systems, place pawn_metrics.inc in the include path used by your compiler.

2. Load The Plugin / Component

For SA-MP server.cfg:
plugins pawn_metrics

On some older Linux setups:

plugins pawn_metrics.so
For open.mp config.json (Native Component Mode - Recommended):
{
  "components": [
    "pawn_metrics"
  ]
}
For open.mp config.json (Legacy Plugin Mode):
{
  "pawn": {
    "legacy_plugins": ["pawn_metrics"]
  }
}

3. Include In Pawn

#include <pawn_metrics>

Quick Start

#include <a_samp>
#include <pawn_metrics>

public OnGameModeInit()
{
    Metrics_SetAuthToken("change-this-token");
    Metrics_StartEx("127.0.0.1", 9100);
    Metrics_UpdateServerInfo();
    Metrics_SetInt("samp_players_online", 0);
    Metrics_SetInt("samp_connects_total", 0);
    Metrics_SetLabeledInt("samp_reports_open", "type=\"player\"", 0);

    SetTimer("Metrics_Update", 5000, true);
    return 1;
}

public OnPlayerConnect(playerid)
{
    Metrics_Inc("samp_connects_total");
    Metrics_SetPlayersOnline();
    Metrics_ObserveHistogram("samp_player_connect_seconds", 0.05);
    return 1;
}

forward Metrics_Update();
public Metrics_Update()
{
    Metrics_UpdateServerInfo();
    Metrics_SetPlayersOnline();
    Metrics_ObserveSummaryLabeled("samp_tick_work_seconds", "source=\"metrics\"", 0.001);
    return 1;
}

Then open:

http://127.0.0.1:9100/metrics?token=change-this-token

Native API

NativeSignatureReturnDescription
Metrics_Startport = 91001 or 0Starts the HTTP exporter.
Metrics_StartExconst bind_address[], port = 91001 or 0Starts the exporter on a specific IPv4 address.
Metrics_Stopnone1Stops the exporter.
Metrics_IsRunningnone1 or 0Checks whether the exporter is running.
Metrics_SetAuthTokenconst token[]1Sets the required bearer/query token for metrics access.
Metrics_LoadConfigconst path[]1 or 0Loads config without starting the exporter.
Metrics_StartFromConfigconst path[]1 or 0Loads config and starts the exporter.
Metrics_Setconst name[], Float:value1Sets a floating-point metric value.
Metrics_SetIntconst name[], value1Sets an integer metric value.
Metrics_SetLabeledconst name[], const labels[], Float:value1Sets a labeled floating-point metric.
Metrics_SetLabeledIntconst name[], const labels[], value1Sets a labeled integer metric.
Metrics_Incconst name[]1Adds 1 to a metric.
Metrics_IncLabeledconst name[], const labels[]1Adds 1 to a labeled metric.
Metrics_Addconst name[], Float:value1Adds a floating-point value.
Metrics_AddIntconst name[], value1Adds an integer value.
Metrics_AddLabeledconst name[], const labels[], Float:value1Adds a floating-point value to a labeled metric.
Metrics_AddLabeledIntconst name[], const labels[], value1Adds an integer value to a labeled metric.
Metrics_ObserveHistogramconst name[], Float:value1Records a histogram observation.
Metrics_ObserveHistogramLabeledconst name[], const labels[], Float:value1Records a labeled histogram observation.
Metrics_ObserveSummaryconst name[], Float:value1Records a summary observation.
Metrics_ObserveSummaryLabeledconst name[], const labels[], Float:value1Records a labeled summary observation.
Metrics_Removeconst name[]1Removes one metric.
Metrics_RemoveLabeledconst name[], const labels[]1Removes one labeled metric.
Metrics_Clearnone1Clears all metrics.
Metrics_SetServerInfoconst hostname[], const gamemode[], maxplayers1Updates server info metrics.

Config File

Example scriptfiles/pawn_metrics.cfg:

bind=127.0.0.1
port=9100
auth_token=change-this-token

Usage:

public OnGameModeInit()
{
    if (!Metrics_StartFromConfig("scriptfiles/pawn_metrics.cfg"))
    {
        print("[pawn-metrics] failed to start from config");
    }

    return 1;
}

Authentication

If auth_token is empty, the endpoint is public. If a token is configured, requests must use one of these forms:

Authorization: Bearer change-this-token
http://127.0.0.1:9100/metrics?token=change-this-token

For production servers, bind to 127.0.0.1 or firewall the metrics port unless Prometheus runs on a trusted remote host.

Stock Helpers

The include provides convenience stocks:

Metrics_UpdateServerInfo();
Metrics_SetPlayersOnline();

Metrics_SetPlayersOnline loops over GetMaxPlayers() and writes:

samp_players_online

Metric Naming

Metric names must be Prometheus-safe:

[a-zA-Z_:][a-zA-Z0-9_:]*

Good examples:

samp_players_online
samp_connects_total
samp_disconnects_total
samp_commands_total
samp_reports_total
samp_anticheat_flags_total
samp_money_created_total
samp_money_removed_total
samp_mysql_queries_total
samp_loaded_vehicles
samp_loaded_houses

Invalid names are ignored by the plugin.

Prometheus

Example prometheus.yml:

scrape_configs:
  - job_name: samp
    scrape_interval: 5s
    static_configs:
      - targets: ["127.0.0.1:9100"]

Example output:

# HELP pawn_metrics_info Pawn metrics plugin scrape info
# TYPE pawn_metrics_info gauge
pawn_metrics_info 1
# TYPE samp_connects_total gauge
samp_connects_total 18
# TYPE samp_players_online gauge
samp_players_online 7

Grafana Ideas

PanelMetric
Online playerssamp_players_online
Connects per minuterate(samp_connects_total[1m])
Disconnects per minuterate(samp_disconnects_total[1m])
Commands per minuterate(samp_commands_total[1m])
Anti-cheat flagsrate(samp_anticheat_flags_total[5m])
Money createdrate(samp_money_created_total[5m])
Money removedrate(samp_money_removed_total[5m])

Build From Source

This repository uses CMake (version 3.20+).

Requirements

TargetRequirement
Linux .soCMake 3.20+, C++17 compiler (g++ / clang++)
Windows .dllCMake 3.20+, MinGW toolchain (i686-w64-mingw32-g++) or MSVC

Linux

cmake -B build -S .
cmake --build build

Output:

  • build/plugins/pawn_metrics.so (Legacy SA-MP plugin)
  • build/components/pawn_metrics.so (Native open.mp component)

Windows (Cross-compile with MinGW)

cmake -B build-win -S . -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++
cmake --build build-win

Output:

  • build-win/plugins/pawn_metrics.dll (Legacy SA-MP plugin)
  • build-win/components/pawn_metrics.dll (Native open.mp component)

The default Windows target is 32-bit because classic SA-MP Windows servers are 32-bit.

GitHub Actions

The workflow in .github/workflows/build.yml fetches the SA-MP plugin SDK and builds release artifacts for Linux and Windows.

Troubleshooting

ProblemFix
Failed (plugins/pawn_metrics.so: cannot open shared object file)Check that the file is inside plugins/ and the plugin name matches your config.
undefined symbol: Metrics_Start while compiling PawnMake sure pawn_metrics.inc is in your compiler include path.
/metrics does not openConfirm Metrics_Start(port) returned 1, the port is not already used, and firewall rules allow local scraping.
Prometheus cannot scrapeUse the server's reachable IP and port, not always 127.0.0.1, when Prometheus runs on another machine.
Windows server cannot load DLLUse the 32-bit DLL for classic SA-MP Windows server.

Security Notes

The metrics endpoint supports a simple bearer/query token. Bind or firewall it so only Prometheus, Grafana, or trusted monitoring hosts can access it.

Do not expose sensitive data such as passwords, auth tokens, private IPs, or player personal information as metric names or values.

License

Pawn Metrics is released under the MIT License.

openmppawnpawn-librarypluginssa-mpsa-mp-librarysa-mp-plugin

Esta página se genera con lo que GitHub publica sobre el repositorio. samp.directory no aloja el código. Informar de un problema con esta ficha

roseeast/PawnMetrics: Plugin de SA-MP | samp.directory