load-average
Load Average
This is to get the server load average via API.
Required Headers
| Field | Description | Example |
| X-API-USER | The API username | eenos_api |
| X-API-PASSWORD | The APIĀ user password | eenos123 |
Request URL
PostĀ URL = /load-average/
Full URL = https://your-host-name:5555/api/load-average/
Example CURL Command
curl -X POST \
-H "X-API-USER: eenos_api" \
-H "X-API-PASSWORD: eenos123" \
https://your-host-name:5555/api/load-average/
Output
{'data': {'load_average': '0.23 0.41 0.37'},
'info': 'Current server load',
'status': 200}
Python Code
#!/usr/bin/python3
import requests
from pprint import pprint
# ---------------------------------------------------------------------
# API VERSION RULES
# ---------------------------------------------------------------------
# Default API (stable):
# https://your-host-name:5555/api/
#
# Versioned API (recommended for future compatibility):
# https://your-host-name:5555/api/v1/
#
# Use versioned API when endpoints may change in future releases.
# ---------------------------------------------------------------------
# API URL (default version)
api_url = "https://your-host-name:5555/api/load-average/"
# If using versioned API, uncomment below:
# api_url = "https://your-host-name:5555/api/v1/load-average/"
# Authentication headers (new API format)
headers = {
"X-API-USER": "eenos_api",
"X-API-PASSWORD": "eenos123",
}
try:
response = requests.post(api_url, headers=headers)
response.raise_for_status()
pprint(response.json())
except Exception as e:
pprint(str(e))
PHP Code
<?php
/*
|--------------------------------------------------------------------------
| API VERSION RULES
|--------------------------------------------------------------------------
| Default API (stable):
| https://your-host-name:5555/api/
|
| Versioned API (recommended for future compatibility):
| https://your-host-name:5555/api/v1/
|
| Use versioned API when endpoints may change in future releases.
|--------------------------------------------------------------------------
*/
// API request URL
$request_url = '/load-average/';
/*
|--------------------------------------------------------------------------
| BASE URL SELECTION
|--------------------------------------------------------------------------
*/
// Default API base URL
$base_url = 'https://your-host-name:5555/api';
// Version specific API base URL (uncomment if needed)
// $base_url = 'https://your-host-name:5555/api/v1';
// Full API URL
$api_url = $base_url . $request_url;
// Initialize cURL
$ch = curl_init($api_url);
// No POST payload required for load-average (auth is header-based)
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Authentication headers (new API format)
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-USER: eenos_api',
'X-API-PASSWORD: eenos123'
]);
// Execute request
$result = curl_exec($ch);
// Error handling
if (curl_errno($ch)) {
echo 'cURL Error: ' . curl_error($ch);
} else {
echo json_encode(json_decode($result), JSON_PRETTY_PRINT);
}
// Close connection
curl_close($ch);
?>