Open Swoole Dashboard

openswoole grafana

What is Open Swoole Dashboard

Open Swoole Dashboard is a stack constructed with Open Swoole Metrics, Grafana and Prometheus and compatible with OpenMetrics. It is supported since Open Swoole v4.9.0.

Moving forward to support the Cloud Native ecosystem, OpenSwoole v4.9.0 started to support metrics in JSON and OpenMetrics formats along with the PHP array format.

As a PHP framework author or PHP application developer, you can build your metrics by adding more application layer metrics to the output of $server->stats(). You can find more API details at Open Swoole Metrics API page.

Open Swoole Dashboard Docker Compose

You can find an example docker-compose project at https://github.com/openswoole/dashboard including Grafana and Prometheus.

You can run the stack at the same host of your Swoole server or update it depending on your hosting environment:

git clone [email protected]:openswoole/dashboard.git
cd dashboard
docker-compose up

Import Open Swoole Dashboard at Grafana

You can import Open Swoole Dashboard at your Grafana dashboard with ID 15418. You can find more at https://grafana.com/grafana/dashboards/15418.

openswoole grafana

Open Swoole Metrics for Prometheus

Open Swoole Dashboard uses Prometheus format (OpenMetrics format) output from Open Swoole server, scraping with Prometheus and virtualised with Grafana.

The sample output looks like this:

# TYPE openswoole_info gauge
openswoole_info{version="OpenSwoole-4.9.0"} 1
# TYPE openswoole_up gauge
openswoole_up 1
# TYPE openswoole_reactor_num gauge
openswoole_reactor_threads_num 4
# TYPE openswoole_requests counter
openswoole_requests_total 0
# TYPE openswoole_start_time gauge
openswoole_start_time 1639922085
# TYPE openswoole_max_conn gauge
openswoole_max_conn 256
# TYPE openswoole_coroutine_num gauge
openswoole_coroutine_num 1
# TYPE openswoole_start_seconds gauge
openswoole_start_seconds 2
# TYPE openswoole_workers_total gauge
openswoole_workers_total 4
# TYPE openswoole_workers_idle gauge
openswoole_workers_idle 3
# TYPE openswoole_task_workers_total gauge
openswoole_task_workers_total 4
# TYPE openswoole_task_workers_idle gauge
openswoole_task_workers_idle 4
# TYPE openswoole_user_workers_total gauge
openswoole_user_workers_total 1
# TYPE openswoole_dispatch_total gauge
openswoole_dispatch_total 1
# TYPE openswoole_connections_accepted gauge
openswoole_connections_accepted 2
# TYPE openswoole_connections_active gauge
openswoole_connections_active 2
# TYPE openswoole_connections_closed gauge
openswoole_connections_closed 0
# TYPE openswoole_reload_count gauge
openswoole_reload_count 0
# TYPE openswoole_reload_last_time gauge
openswoole_reload_last_time 1639922085
# TYPE openswoole_worker_vm_object_num gauge
openswoole_worker_vm_object_num 13
# TYPE openswoole_worker_vm_resource_num gauge
openswoole_worker_vm_resource_num 3
# TYPE openswoole_worker_memory_usage gauge
openswoole_worker_memory_usage 2097152
# TYPE openswoole_event_workers_start_time gauge
openswoole_event_workers_start_time{worker_id="0"} 1639922085
openswoole_event_workers_start_time{worker_id="1"} 1639922085
openswoole_event_workers_start_time{worker_id="2"} 1639922085
openswoole_event_workers_start_time{worker_id="3"} 1639922085
# TYPE openswoole_event_workers_start_seconds gauge
openswoole_event_workers_start_seconds{worker_id="0"} 2
openswoole_event_workers_start_seconds{worker_id="1"} 2
openswoole_event_workers_start_seconds{worker_id="2"} 2
openswoole_event_workers_start_seconds{worker_id="3"} 2
# TYPE openswoole_event_workers_dispatch_count gauge
openswoole_event_workers_dispatch_count{worker_id="0"} 0
openswoole_event_workers_dispatch_count{worker_id="1"} 0
openswoole_event_workers_dispatch_count{worker_id="2"} 1
openswoole_event_workers_dispatch_count{worker_id="3"} 0
# TYPE openswoole_event_workers_request_count gauge
openswoole_event_workers_request_count{worker_id="0"} 0
openswoole_event_workers_request_count{worker_id="1"} 0
openswoole_event_workers_request_count{worker_id="2"} 0
openswoole_event_workers_request_count{worker_id="3"} 0
# TYPE openswoole_task_workers_start_time gauge
openswoole_task_workers_start_time{worker_id="4"} 1639922085
openswoole_task_workers_start_time{worker_id="5"} 1639922085
openswoole_task_workers_start_time{worker_id="6"} 1639922085
openswoole_task_workers_start_time{worker_id="7"} 1639922085
# TYPE openswoole_task_workers_start_seconds gauge
openswoole_task_workers_start_seconds{worker_id="4"} 2
openswoole_task_workers_start_seconds{worker_id="5"} 2
openswoole_task_workers_start_seconds{worker_id="6"} 2
openswoole_task_workers_start_seconds{worker_id="7"} 2
# TYPE openswoole_user_workers_start_time gauge
openswoole_user_workers_start_time{worker_id="8"} 1639922085
# TYPE openswoole_user_workers_start_seconds gauge
openswoole_user_workers_start_seconds{worker_id="8"} 2
# EOF

Create your Open Swoole dashboard

Open Swoole Dashboard is a stack with open source infrastructure software, you can update and redesign your dashboard based on the example. Feedbacks to include more metrics are welcome.