> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/tposs/6.14/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/tposs/6.14/metrics.md).

# Metrics

TPOSS exposes metrics on the `/metrics/v1/values` endpoint.

Metrics can be exported in two formats:

- JSON
- Prometheus

The metrics format depends on the value of the **Accept** header from the received request. It could be either `application/json` to export metrics in the JSON format or `text/plain` to export metrics in the Prometheus format. All the metrics described in this document are presented in the [Prometheus format](https://prometheus.io/docs/concepts/data_model).

TPOSS metrics are divided into the following groups:

- RADIUS
- Diameter
- HTTP API
- PCS sessions
- Database
- CCS Hooks
- OTP runtime
- Mnesia
- jemalloc

The following sections describe what kind of metrics are exposed for each group and what datapoints (or labels in Prometheus terms) are attached to the metrics. If there is no `datapoint` column or the datapoint value is empty this means:

- Promtheus metrics: no labels for the given metric
- JSON metrics: only default datapoint `value` is used.

To expose metrics, you can configure a ServiceMonitor using the following configuration parameters:

```
servicemonitor:
  enabled: false
  interval: '30s'
  scrapeTimeout: '30s'
  labels:
    release: prometheus-operator
  annotations: {}
  targetLabels: []
  namespaceSelector: {}
  selector:
    matchLabels:
      app: tposs
```

## RADIUS metrics

TPOSS exposes the following RADIUS server metrics:

| Metric | Type | Labels | Description |
|---|---|---|---|
| radiusServUpTime | counter | server_name,server_ip,server_port | Uptime of a RADIUS server |
| radiusServLastRequestTime | counter | server_name,server_ip,server_port | Timestamp of the last RADIUS request handled by a server |
| radiusServRtt | histogram | le,server_name,server_ip,server_port,nas_ip,nas_port | Handle time in milliseconds of RADIUS requests on a RADIUS server |
| radiusServTotalAccessRequests | counter | server_name,server_ip,server_port,nas_ip,nas_id | Total number of RADIUS Access-Request requests |
| radiusServTotalAccessAccepts | counter | server_name,server_ip,server_port,nas_ip,nas_id | Total number of RADIUS Access-Accept responses |
| radiusServTotalAccessRejects | counter | server_name,server_ip,server_port,nas_ip,nas_id,reason | Total number of RADIUS Access-Reject responses |
| radiusServTotalAccessChallenges | counter | server_name,server_ip,server_port,nas_ip,nas_id | Total number of RADIUS Access-Challenge responses |
| radiusServTotalAccountingRequests | counter | acct_type,server_name,server_ip,server_port,nas_ip,nas_id | Total number of RADIUS Accounting requests |
| radiusServTotalAccountingResponses | counter | acct_type,server_name,server_ip,server_port,nas_ip,nas_id | Total number of RADIUS Accounting responses |
| radiusServTotalDupRequests | counter | server_name,server_ip,server_port,nas_ip,nas_id | Total number of duplicated requests |
| radiusServTotalMalformedAccessRequests | counter | server_name,server_ip,server_port,nas_ip,nas_id | Total number of malformed requests received by a RADIUS server |
| radiusServTotalBadAuthenticators | counter | server_name,server_ip,server_port,nas_ip,nas_id | Total number of requests received by a RADIUS server with a secret that is not matched to the one configured for this server |
| radiusServTotalPacketsDropped | counter | server_name,server_ip,server_port,nas_ip,nas_id | Total number of packets dropped by a RADIUS server |
| radiusServTotalUnknownTypes | counter | server_name,server_ip,server_port,nas_ip,nas_id | Total number of requests of an unknown type received by a RADIUS serve |

All RADIUS metrics contain special labels which allows for accumulating metrics data for different conditions, such as total number of RADIUS Accounting requests, mean time of RADIUS requests handling, and so on.

 The following labels are present in the RADIUS metrics:

- `server_name` - the name of a RADIUS server
- `server_port` - the port used by a RADIUS server
- `server_ip` - the IP address a RADIUS server listens for incoming RADIUS requests
- `nas_ip` - the NAS IP address from which TPOSS receives RADIUS requests
- `nas_id` - the NAS identifier from which TPOSS receives RADIUS requests

The `le` label of the `radiusServRtt` metric specifies the histogram bucket for the time taken to handle incoming RADIUS requests. Since the metric is represented as a [Prometheus histogram](https://prometheus.io/docs/practices/histograms), there are two additional associated metrics:

- `radiusServRtt_sum` - total number of RADIUS requests taken into account by the histogram
- `radiusServRtt_count` - sum of round trip time periods taken into account by the histogram

The `radiusServTotalAccountingRequests` and `radiusServTotalAccountingResponses` metrics have the following additional label:

- `acct_type` - type of RADIUS Accounting request. The possible values of this label are `start`, `update`, and `stop`.

The **radiusServTotalAccessRejects** metric has the additional label `reason`. Its value represents the reason for the rejected RADIUS Access-Request. The label may have the following values:

- `not_authenticated` - The subscriber is not authenticated by TPOSS.
- `blocked_tariff` - The subscriber has the `blocked` tariff.
- `missed_mandatory_avp` - Missing mandatory AVP in the incoming RADIUS Access-Request.
- `database_issue` - The database query failed with error.
- `database_connection_issue` - The database connection was closed during the execution of a query.
- `database_busy` - TPOSS does not have free database connections in the database connection pool.
- `ip_pool_exhausted` - No more IP addresses in the IP pool.
- `ip_allocation_issue` - Allocation of IP address failed because of database or TPOSS issues.
- `duplicated_network_session` - Network session for the given IMSI already exists at TPOSS.
- `user_stat_update_issue` - TPOSS failed to update user statistics when handling RADIUS Access-Request.
- `ccs_error` - Charging handler failed to handle RADIUS Access-Request from TDF.
- `internal_error` - TPOSS handler crashed when handling the incoming RADIUS Access-Request.
- `unknown` - TPOSS rejected the RADIUS Access-Request by unknown reason.

### RADIUS client metrics

TPOSS exposes the following RADIUS client metrics:

| Metric | Type | Labels | Description |
| ---|---|---|---|
| radiusClientTotalCoARequests | counter | client_ip,client_name,server_name,server_ip,server_port | Total number of CoA requests sent by TPOSS |
| radiusClientTotalCoAAckResponses | counter | client_ip,client_name,server_name,server_ip,server_port | Total number of CoA-ACK responses received by TPOSS |
| radiusClientTotalCoANakResponses | counter | client_ip,client_name,server_name,server_ip,server_port | Total number of CoA-NAK responses received by TPOSS |
| radiusClientTotalDisconnectRequests | counter | client_ip,client_name,server_name,server_ip,server_port | Total number of Disconnect requests sent by TPOSS |
| radiusClientTotalDisconnectAckResponses | counter | client_ip,client_name,server_name,server_ip,server_port | Total number of Disconnect-ACK responses received by TPOSS |
| radiusClientTotalDisconnectNakResponses | counter | client_ip,client_name,server_name,server_ip,server_port | Total number of Disconnect-NAK responses received by TPOSS |

Each RADIUS client metric contains the following labels:

- `client_ip` - the IP address used by TPOSS RADIUS client to send RADIUS requests
- `client_name` - the name of RADIUS client used by TPOSS to send RADIUS requests
- `server_name` - the RADIUS server name where TPOSS sends RADIUS requests
- `server_ip` - the RADIUS server IP address where TPOSS sends RADIUS requests
- `server_port` - the RADIUS server port where TPOSS sends RADIUS requests

## Diameter metrics

TPOSS exposes the following Diameter metrics:

| Metric | Type | Labels | Description |
|---|---|---|---|
| diameter_requests_gx_total | counter | type | Total number of Gx requests received by TPOSS |
| diameter_requests_gy_total | counter | type | Total number of Gy requests received by TPOSS |
| diameter_requests_gx_retransmits | counter | | Total number of Gx retransmissions |
| diameter_requests_gy_retransmits | counter | | Total number of Gy retransmissions |
| diameter_requests_gx_errors_total | counter | code | Total number of Gx errors |
| diameter_requests_gy_errors_total | counter | code | Total number of Gy errors |
| diameter_requests_rar_total | counter | | Total number of RAR requests sent by TPOSS |
| diameter_rar_errors_total | counter | | Total number of failed RAR requests sent by TPOSS |
| diameter_requests_asr_total | counter | | Total number of ASR requests sent by TPOSS |
| diameter_asr_errors_total | counter | | Total number of failed ASR requests sent by TPOSS |
| diameter_requests_nasreq_total | counter | type | Total number of NASREQ requests received by TPOSS |
| diameter_nasreq_errors_total | counter | code | Total number of NASREQ errors |
| diameter_requests_rtt_milliseconds_bucket | histogram | le | The values configure the upper limits of time intervals of handling incoming Diameter requests |
| diameter_requests_gx_rejects_total | counter | | Total number of rejected Gx requests - **deprecated since 6.12.0** |
| diameter_requests_nasreq_rejects_total | counter | | Total number of NASREQ requests rejected because of no network session - **deprecated since 6.12.0** |
| diameter_requests_nasreq_unknown_session_total | counter | | Total number of NASREQ requests rejected because of an unknown SCG session - **deprecated since 6.12.0** |

The `type` label specifies the type of the Diameter requests for a given protocol. The following types exist for the Diameter `Gx` and `Gy` requests:

- `initial` - Diameter Gx and Gy initial requests
- `interim` - Diameter Gx and Gy update requests
- `stop` - Diameter Gx and Gy termination requests

The following types exist for the Diameter NASREQ requests:

- `aar` - Diameter NASREQ Authorization and Authentication requests
- `acr_start` - Diameter NASREQ Accounting-Start requests
- `acr_interim` - Diameter NASREQ Accounting-Interim-Update requests
- `acr_stop` - Diameter NASREQ Accounting-Stop
- `str`- Diameter NASREQ Session-Termination requests

The `code` label specifies the value of the Diameter `Result-Code` AVP.

The `le` label of the `diameter_requests_rtt_milliseconds_bucket` specifies the histogram bucket for the time taken to handle incoming Diameter requests. Since the metric is represented as a [Prometheus histogram](https://prometheus.io/docs/practices/histograms) there are two additional associated metrics:

- `diameter_requests_rtt_milliseconds_count` - total number of Diameter requests taken into account by the histogram
- `diameter_requests_rtt_milliseconds_sum` - sum of round trip time periods taken into account by the histogram

## HTTP API metrics

TPOSS exposes the following HTTP API-related metrics:

| Metric | Type | Label | Description |
| ---|---|---|---|
| api_requests_total | counter | | Total number of HTTP API requests received by TPOSS |
| api_requests_success | counter | | Total number of successful HTTP API requests |
| api_requests_error | counter | | Total number of failed HTTP API requests |
| api_requests_rtt | histogram | le | Requests handle time in milliseconds for the TPOSS HTTP API calls |

The `api_requests_rtt` metric contains the `le` label that specifies the [Prometheus histogram bucket](https://prometheus.io/docs/practices/histograms) for the time taken to handle incoming HTTP API requests. There are two additional metrics for the HTTP API handling time:

- `api_requests_rtt_count` - total number of observations taken into account by the histogram
- `api_requests_rtt_sum` - sum of time periods that TPOSS spent to handle HTTP API requests

## PCS sessions metrics

TPOSS exposes the following PCS sessions metrics:

| Metric | Type | Labels | Description |
| ---|---|---|---|
| sessions_GGSN | gauge | visitedNetworkMCC, visitedNetworkMNC, activeProfile | Total number of GGSN sessions |
| sessions_RUCKUS | gauge | | Total number of RUCKUS sessions |
| sessions_scgTotal | gauge | | Total number of service sessions |
| sessions_scg | gauge | nas | Total number of service sessions with the given `nas` |
| sessions_imei_change | counter | | Number of changed IMEIs during the GGSN authorization process |
| sessions_uli_used | counter | | Number of used 3GGP-User-Location-Info during the GGSN authorization process |
| sessions_mccmnc_changed | counter | | Number of changed MCCs and MNCs during the GGSN authorization process |
| sessions_charging_rules_changed | counter | | Number of changed charging rules during the service session authorization process |
| sessions_terminating_workers | gauge | | Number of processes that handle postponed termination of service sessions |
| rating_group_total | counter | rule | Total number of sessions per rating group (only for MySQL `session.backend`) |

The `sessions_GGSN` metric labels are optional and depend on the value of the **metrics.network_session_labels** configuration option. If the value of the **sessions.backend** configuration option is set to `mnesia`, the metric does not have any labels. For more information, see the [TPOSS ServiceMonitor and metrics configuration](https://docs.cennso.com/components/tposs/6.14/configuration/configuration.md#tposs-servicemonitor-and-metrics-configuration) document.

>**NOTE:** The `rating_group_total` counters are only available when `diameter.enabled = true` and `session.backend = mysql` are set.

If TPOSS is configured for the legacy setup only with RADIUS communication (`diameter.enabled = false` and `session.backend = mnesia`), the following metrics represent the number of sessions with the given `Access-Class`:

| Metric | Labels | Type | Description |
| ---|---|---|---|
| sessions_portal | | counter | Total number of sessions with Portal Access-Class |
| sessions_online | | counter | Total number of sessions with Online Access-Class |
| sessions_known | | counter | Total number of sessions with Known Access-Class |

## Database metrics

TPOSS exposes the following database metrics:

| Metric | Type | Labels | Description |
| ---|---|---|---|
| db_connections_total | gauge | | Number of database connections used by TPOSS |
| db_requests_total | counter | | Total number of requests to the database |
| db_requests_ok | counter | | Total number of successful requests to the database |
| db_requests_error | counter | | Total number of failed requests to the database |
| db_requests_rtt_bucket | histogram | le | Duration of calls to the database |
| db_requests_query_rtt_bucket | histogram | le | Duration of database queries |
| db_requests_queue_rtt_bucket | histogram | le | Duration of query queue time |
| db_requests_decode_rtt | histogram | le | Duration of time decoding the result of a query |
| db_requests_idle_rtt | histogram | le | Number of time the connection was idle before use |
| db_pool_free_connections | gauge | | Number of free connections with database pool |
| tposs_cdr_db_handler_errors | counter | | Number of failures of TPOSS CDR database controller |
| accounts_activated | counter | | Total number of activated accounts |
| accounts_total | counter | | Total number of accounts |
| balances_total | counter | | Total number of balances |
| cdrs_total | counter | | Total number of closed CDRs |
| sessions_total | counter | | Total number of charging sessions |
| carriers_total | counter | | Total number of carriers |
| carrier_groups_total | counter | | Total number of carrier groups |
| services_total | counter | | Total number of services |
| tariffs_total | counter | | Total number of tariffs |
| service_profiles_total | counter | | Total number of service profiles |
| public_users_total | counter | | Total number of public users |
| private_user_total | counter | | Total number of private users |
| credentials_total | counter | | Total number of credentials |
| subscribers_total | counter | | Total number of subscribers |
| ipPool_used | gauge | | Number of IPs used in the global IP pool or IP pool per country |
| ipPool_total | gauge | | Number of possible IPs in the global IP pool |
| ip_pool_block_used_ips_pct | gauge | | Percentage of used IPs within the block |
| ip_pool_block_total | counter | | Total number of IPs within the block |
| whitelist_imeis | counter | | Number of IMEIs in the whitelist |

All non-histogram metrics do not have any labels. The histogram metrics contain the special `le` label. The value of this label specifies the histogram bucket.

## CCS hooks metrics

TPOSS exposes the following CCS hooks-related metrics:

| Metric | Type | Description |
| ---|---|---|
| hooks_balance_threshold_resend | counter | Number of tries to resend balance threshold notifications |
| hooks_balance_threshold_success | counter | Number of successfully sent balance threshold notifications |
| hooks_balance_threshold_fail | counter | Number of failed tries to send balance threshold notifications |
| hooks_visited_country_change_resend | counter | Number of tries to resend visited country change notifications |
| hooks_visited_country_change_success | counter | Number of successfully sent visited country change notifications |
| hooks_visited_country_change_fail | counter | Number of failed tries to send visited country change notifications |
| hooks_mccmnc_change_resend | counter | Number of tries to resend Mcc/Mnc change notifications |
| hooks_mccmnc_change_success | counter | Number of successfully sent Mcc/Mnc change notifications |
| hooks_mccmnc_change_fail | counter | Number of failed tries to send Mcc/Mnc change notifications |
| hooks_charging_rules_change_resend | counter | Number of tries to resend charging rules change notifications |
| hooks_charging_rules_change_success | counter | Number of successfully sent charging rules change notifications |
| hooks_charging_rules_change_fail | counter | Number of failed tries to send charging rules change notifications |
| hooks_network_attachment_first_resend | counter | Number of tries to resend first network attachment notifications |
| hooks_network_attachment_first_success | counter | Number of successfully sent network attachment notifications |
| hooks_network_attachment_first_fail | counter | Number of failed tries to send the first network attachment notifications |

## OTP runtime metrics

TPOSS exposes the following OTP runtime metrics:

| Metric | Type | Labels | Description |
| ---|---|---|---|
| runtime_otp_release | counter | | Major version of the Erlang/OTP release |
| runtime_uptime | counter | | TPOSS uptime in milliseconds |
| runtime_start_time | counter | | TPOSS startup time |
| runtime_garbage_collection | gauge | datapoint | Erlang VM garbage collector statistics |
| runtime_ram | gauge | datapoint | Information about memory allocated by the Erlang VM |
| runtime_ports | gauge | datapoint | Number and limit of ports currently existing at the node |
| runtime_processes | gauges | datapoint | Information about processes in the Erlang VM |
| runtime_processors | gauge | datapoint | Information about processors in the system |
| runtime_io | gauge | datapoint | Total number of received and transmitted bytes over network |
| cluster_nodes | gauge | | Number of TPOSS instances connected to the instance where the metric is read (including the instance itself) |

The value of the `datapoint` label depends on the metric.

The `runtime_garbage_collection` metric may have the following datapoint values:

- `number_of_gcs` - total number of garbage collections performed by a VM
- `words_reclaimed` - total number of words reclaimed during garbage collections

The `runtime_io` metric may have the following datapoint values:

- `input` - total number of bytes received by a VM
- `output` - total number of bytes sent by a VM

The `runtime_ram` metric may have the following datapoint values:

- `total` - total number of bytes currently allocated by the underlying BEAM virtual machine
- `processes` - total number of bytes allocated for the processes
- `processes_used` - total number of bytes currently used by the processes
- `system` - total number of bytes allocated by the underlying BEAM virtual machine for system purposes
- `atom` - total number of bytes allocated by the underlying BEAM virtual machine for atoms
- `atom_used` - total number of bytes currently used for atoms
- `binary` - total number of bytes allocated by the underlying BEAM virtual machine for binaries
- `code` - total number of bytes allocated by the underlying BEAM virtual machine for code
- `ets` - total number of bytes allocated by the underlying BEAM virtual machine for ETS tables

The `runtime_ports` metric may have the following datapoint values:

- `port_count` - number of ports currently existing at the TPOSS node
- `port_limit` - maximum number of simultaneously existing ports at the TPOSS node

The `runtime_processes` metric may have the following datapoint values:

- `process_count` - number of processes launched by TPOSS
- `process_limit` - maximum number of processes that can be launched by TPOSS
- `run_queue_size` - total length of all normal and dirty CPU run queues

The `runtime_processors` metric may have the following datapoint values:

- `logical_processors` - detected number of logical processors configured in the system
- `logical_processors_available` - detected number of logical processors available to the TPOSS runtime system

## Mnesia metrics

TPOSS exposes the following Mnesia metrics:

| Metric | Type | Description |
| ---|---|---|
| runtime_mnesia_tx_commits | gauge | Number that indicates how many transactions have terminated successfully since Mnesia was started |
| runtime_mnesia_tx_failures | gauge | Number that indicates how many transactions have failed since Mnesia was started |
| runtime_mnesia_tx_restarts | gauge | Number that indicates how many transactions have been restarted since Mnesia was started |
| runtime_mnesia_tx_log_writes | gauge | Number that indicates how many write operations have been performed to the transaction log since start-up |

## jemalloc metrics

The IP pools are built on top of a library that uses [jemalloc](https://jemalloc.net/) memory allocator. TPOSS provides the following metrics to get information about the memory allocated for IP pools:

| Metric | Type | Description |
|---|---|---|
| jemalloc_active | gauge | Total number of bytes in allocated active pages |
| jemalloc_allocated | gauge | Total number of allocated bytes |
| jemalloc_mapped | gauge | Total number of bytes in active extents mapped by the allocator |
| jemalloc_metadata | gauge | Total number of bytes allocated for metadata |
| jemalloc_resident | gauge | Maximum number of bytes in physically resident data pages mapped by the allocator |
| jemalloc_retained | gauge | Total number of bytes in virtual memory mappings that were retained and not returned to the operating system |
