PHP code example of api-insight / metrics-bundle

1. Go to this page and download the library: Download api-insight/metrics-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

api-insight / metrics-bundle example snippets


return [
    // ...
    ApiInsight\ApiInsightBundle::class => ['all' => true],
];
json
{
    "global": {
        "total_calls": 325,
        "total_errors": 12,
        "error_rate": 3.69,
        "routes_count": 8
    },
    "routes": {
        "api_users_get": {
            "total_calls": 120,
            "avg_duration": 0.056,
            "min_duration": 0.012,
            "max_duration": 0.234,
            "status_codes": {
                "200": 118,
                "404": 2
            },
            "errors": 2,
            "error_rate": 1.67
        },
        // ... autres routes
    }
}
json
{
    "period": "day",
    "metrics": {
        "2023-11-15": {
            "api_users_get": {
                "total_calls": 45,
                "errors": 2,
                "avg_duration": 0.067,
                "error_rate": 4.44
            },
            "api_products_list": {
                "total_calls": 38,
                "errors": 0,
                "avg_duration": 0.123,
                "error_rate": 0
            }
        },
        "2023-11-16": {
            // ... métriques pour ce jour
        }
    }
}
json
{
    "period": "month",
    "metrics": {
        "2023-11": {
            "api_users_get": {
                "total_calls": 1245,
                "errors": 23,
                "avg_duration": 0.062,
                "error_rate": 1.85
            },
            // ... autres routes
        },
        "2023-12": {
            // ... métriques pour ce mois
        }
    }
}