Ploi API
Ploi API

Laravel Horizon statistics

In Ploi it is possible to see your Laravel Horizon statistics directly from the Ploi panel. This article describes how you can get these statistics via the Ploi API.

How do I configure Laravel Horizon statistics

GET api/servers/{server}/sites/laravel/horizon/{type}

Parameters

Parameter Type Status Description
type string optional Available options: stats, workload, masters, failed, defaults to stats if none specified

Example request for stats:

curl -X GET "https://ploi.io/api/servers/{server}/sites/laravel/horizon" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"

Example response for stats:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "data": {
        "failedJobs": 1,
        "jobsPerMinute": 0,
        "pausedMasters": 0,
        "periods": {
            "failedJobs": 10080,
            "recentJobs": 60
        },
        "processes": 1,
        "queueWithMaxRuntime": null,
        "queueWithMaxThroughput": null,
        "recentJobs": 0,
        "status": "running",
        "wait": {
            "redis:default": 0
        }
    }
}

Example request for workload:

curl -X GET "https://ploi.io/api/servers/{server}/sites/laravel/horizon/workload" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"

Example response for workload:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "data": [
        {
            "name": "default",
            "length": 0,
            "wait": 0,
            "processes": 1
        }
    ]
}

Example request for masters:

curl -X GET "https://ploi.io/api/servers/{server}/sites/laravel/horizon/masters" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"

Example response for masters:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "data": {
        "from-macbook-pro-Ry0f": {
            "name": "from-macbook-pro-Ry0f",
            "pid": "104064",
            "status": "running",
            "supervisors": [
                {
                    "name": "from-macbook-pro-Ry0f:supervisor-1",
                    "master": "from-macbook-pro-Ry0f",
                    "pid": "104078",
                    "status": "running",
                    "processes": {
                        "redis:default": 1
                    },
                    "options": {
                        "balance": "auto",
                        "connection": "redis",
                        "queue": "default",
                        "backoff": "0",
                        "force": false,
                        "maxProcesses": "10",
                        "minProcesses": "1",
                        "maxTries": "1",
                        "maxTime": "0",
                        "maxJobs": "0",
                        "memory": "512",
                        "nice": "0",
                        "name": "from-macbook-pro-Ry0f:supervisor-1",
                        "workersName": "default",
                        "sleep": "3",
                        "timeout": "60",
                        "balanceCooldown": "3",
                        "balanceMaxShift": "1"
                    }
                }
            ]
        }
    }
}

Example request for failed:

curl -X GET "https://ploi.io/api/servers/{server}/sites/laravel/horizon/failed" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"

Example response for failed:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "data": {
        "jobs": [
            {
                "id": "67a059c9-51a4-4b94-b7c1-289d6c20ccf5",
                "connection": "redis",
                "queue": "default",
                "name": "App\\Jobs\\Fails",
                "status": "failed",
                "payload": {
                    "uuid": "67a059c9-51a4-4b94-b7c1-289d6c20ccf5",
                    "timeout": null,
                    "tags": [],
                    "id": "67a059c9-51a4-4b94-b7c1-289d6c20ccf5",
                    "backoff": null,
                    "displayName": "App\\Jobs\\Fails",
                    "maxTries": null,
                    "pushedAt": "1646636737.9199",
                    "type": "job",
                    "maxExceptions": null,
                    "retryUntil": null,
                    "data": {
                        "command": "O:14:\"App\\Jobs\\Fails\":10:{s:3:\"job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:19:\"chainCatchCallbacks\";N;s:5:\"delay\";N;s:11:\"afterCommit\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}",
                        "commandName": "App\\Jobs\\Fails"
                    },
                    "job": "Illuminate\\Queue\\CallQueuedHandler@call",
                    "attempts": 1
                },
                "exception": "ErrorException: Use of undefined constant broken - assumed 'broken'",
                "failed_at": "1646636738.6643",
                "completed_at": "1646636738.6624",
                "retried_by": [],
                "reserved_at": "1646636738.6581",
                "index": 0
            }
        ],
        "total": 1
    }
}