json_formatter
JSON-based worker information formatter for Merlin.
This module provides a JSON formatter for displaying worker information in a structured, machine-readable format. It is primarily intended for programmatic consumption by downstream tools, scripts, or external systems that need to parse and analyze worker data rather than display it in a human-friendly format.
The formatter includes:
- Detailed records of logical workers and their associated queues
- Physical worker details such as ID, host, PID, status, restart counts,
and timestamps
- Relationships between logical and physical workers
- Applied filters and generation timestamp metadata
- Summary statistics for logical and physical workers
JSONWorkerFormatter
Bases: WorkerFormatter
JSON formatter for programmatic worker information consumption.
This formatter generates structured JSON output representing logical and physical worker entities. The output includes worker details, relationships between logical and physical workers, and comprehensive statistics. Designed for use cases where downstream tools or scripts need to parse worker information in a machine-readable format.
Attributes:
| Name | Type | Description |
|---|---|---|
console |
Console
|
A Rich Console object used for displaying output to the terminal. |
Methods:
| Name | Description |
|---|---|
format_and_display |
Format and print worker information as structured JSON, including details for logical and physical workers, filters, timestamp, and summary statistics. |
get_worker_statistics |
Compute worker statistics, including counts of logical and physical workers by status, for inclusion in JSON output. |
Source code in merlin/workers/formatters/json_formatter.py
format_and_display(logical_workers, filters, merlin_db)
Format and display worker information as JSON.
This method produces JSON output containing:
- A record of applied filters
- A timestamp of when the report was generated
- Detailed logical worker entries (name, queues, associated physical workers)
- Detailed physical worker entries (ID, host, PID, status, restart count, timestamps)
- A summary of worker statistics
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logical_workers
|
List[LogicalWorkerEntity]
|
A list of logical worker entities to format. |
required |
filters
|
Dict
|
A dictionary of filters applied to the query. |
required |
merlin_db
|
MerlinDatabase
|
Database interface for retrieving physical worker details. |
required |