Metrics
Bases: BaseRoute
A class for interacting with the Outline VPN server's metrics API.
This class provides methods to retrieve and check the status of various server metrics. It allows you to determine whether metrics collection is enabled on the server.
Attributes:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
The base URL for the metrics endpoint of the Outline server, formed by appending "/metrics" to the management URL. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
management_url
|
str
|
The management URL used to communicate with the Outline server API. |
required |
ssl_verify
|
bool
|
Flag to enable or disable SSL certificate verification for API requests. Default is |
False
|
Source code in outline_vpn_api_client/client.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
change_enabled_state(state=False)
Enables or disables the sharing of metrics on the Outline VPN server.
This method allows you to enable or disable the sharing of metrics. It sends a request to the server to update
the state of metrics sharing based on the provided state parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
bool
|
A boolean indicating whether to enable ( |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Raises:
| Type | Description |
|---|---|
ResponseNotOkException
|
If the server responds with a status code indicating an error (status code >= 300). |
Source code in outline_vpn_api_client/client.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
check_enabled()
Returns whether metrics collection is enabled on the Outline VPN server.
This method sends a request to the server to check if metrics sharing is currently enabled. It parses the response to determine whether metrics are being shared and returns a boolean indicating the status.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Raises:
| Type | Description |
|---|---|
ResponseNotOkException
|
If the server responds with a status code indicating an error (status code >= 300). |
Source code in outline_vpn_api_client/client.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
get_data_transfer()
Returns the data transferred per access key on the Outline VPN server.
This method retrieves information about the amount of data transferred for each access key. It sends a request to the server to fetch the data transfer details and returns a dictionary containing the transfer data.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
BytesTransferredByUserId
|
A dictionary containing data transfer information for each access key. |
BytesTransferredByUserId
|
The returned dictionary contains the following format: |
|
BytesTransferredByUserId
|
{ "bytesTransferredByUserId": { "user_id_1": data_in_bytes, "user_id_2": data_in_bytes, ... } |
|
BytesTransferredByUserId
|
} |
|
BytesTransferredByUserId
|
Where |
|
BytesTransferredByUserId
|
the amount of data transferred by the corresponding access key in bytes. |
Raises:
| Type | Description |
|---|---|
ResponseNotOkException
|
If the server responds with a status code indicating an error (status code >= 300). |
Source code in outline_vpn_api_client/client.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
get_server_metrics(since)
Returns detailed server metrics including tunnel time, data transferred, bandwidth, locations, and per-access-key statistics.
!!! warning "Experimental endpoint"
This method uses GET /experimental/server/metrics, which is an unstable
endpoint. Its availability and response format may change or break across
different Outline server versions. Use with caution in production.
Note
This endpoint requires metrics sharing to be enabled on the server
(client.metrics.change_enabled_state(True)). It will return an error
if metrics are disabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
since
|
datetime
|
The start of the time range for which to return metrics. |
required |
Returns:
| Type | Description |
|---|---|
ServerMetrics
|
models.ServerMetrics: Detailed server and per-key metrics. |
Raises:
| Type | Description |
|---|---|
ResponseNotOkException
|
If the server responds with a status code indicating an error (status code >= 300). |
Example
from datetime import datetime, timezone, timedelta
metrics = client.metrics.get_server_metrics(
since=datetime.now(timezone.utc) - timedelta(days=30)
)
print(metrics.server.dataTransferred.bytes)
Source code in outline_vpn_api_client/client.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
Note on get_server_metrics
The get_server_metrics method uses the GET /experimental/server/metrics endpoint,
which is experimental and may be unstable or unavailable depending on your Outline
server version.
Requirements:
- Metrics sharing must be enabled:
client.metrics.change_enabled_state(True) - The endpoint behavior and response format may change without notice in future server releases