Errors Tab
Relevant source files
The following files were used as context for generating this wiki page:
The Errors Tab is a specialized diagnostic module within the LogUtil terminal interface designed to analyze HTTP error patterns in Nginx logs. Its primary purpose is to categorize, count, and visualize failed requests, specifically targeting 4xx (Client Error) and 5xx (Server Error) status codes to help administrators identify misconfigured clients or failing backend services.
Sources: src/tabs/errors.rs:43-57, README.md:214-219
Component Architecture and Logic
The ErrorsTab is implemented as a stateful component that integrates with the application's central memory database and the Terminal User Interface (TUI) manager. It adheres to the Tab trait defined in src/tabs/base.rs, allowing it to be managed dynamically by the App instance.
Data Acquisition and Processing
The tab retrieves real-time data from the GLOBAL_DB to populate its interface. The logic involves three primary data points:
- Summary Statistics: Calls
db.get_error_stats()to retrieve counts of unique error codes, error-producing URLs, and unique IPs associated with errors. - Top Errors: Calls
db.get_top_status_codes(10)to identify the most frequent error codes. - Categorization: It applies logic to classify status codes:
- 400-499: Classified as "Client Error".
- 500-599: Classified as "Server Error".
- Others: Classified as "Other Error".
Sources: src/tabs/errors.rs:26-30, src/tabs/errors.rs:45-51
Interface Structure
The UI is divided into two vertical sections:
- Error Analysis Header: A
Paragraphwidget showing high-level counts. - Top Error Codes Table: A
Tablewidget listing specific status codes, their derived types, occurrence counts, and descriptions.
Sources: src/tabs/errors.rs:32-41, src/tabs/errors.rs:90-112
Data Flow Diagram
The following diagram illustrates how error data moves from the log source to the Errors Tab display.
Sources: src/tabs/errors.rs:26-28, src/main.rs:293-310
Component Definition
| Element | Type | Description |
|---|---|---|
ErrorsTab | struct | Main structure containing TableState for list navigation. |
draw_errors_tab | fn | Internal method responsible for layout splitting and widget rendering. |
handle_input | fn | Implementation of Tab trait to handle Up and Down arrow keys for table navigation. |
table_state | TableState | Maintains the current selection index for the error code list. |
Sources: src/tabs/errors.rs:10-12, src/tabs/errors.rs:125-151
Interaction and State Management
The ErrorsTab maintains interactive state through keyboard events. Navigation is restricted to the vertical axis within the "Top Error Codes" table.
Sources: src/tabs/errors.rs:126-146
Configuration and Activation
The Errors Tab is optional and must be enabled via CLI arguments or the interactive settings screen. It is governed by the AppConfig struct and the enable_errors flag.
CLI Configuration
| Flag | Type | Default | Description |
|---|---|---|---|
--enable-errors | bool | false | Enables the Errors Tab in the TUI navigation. |
Sources: src/main.rs:124, src/app.rs:30
Initialization Logic
In src/app.rs, the tab is conditionally added to the application's tab list during startup:
if config.enable_errors {
tab_names.push("Errors".to_string());
tabs.push(Box::new(ErrorsTab::new()));
}
Sources: src/app.rs:77-80
Visual Styles and Theming
The tab uses specific color coding to differentiate error severity and data types:
- Border/Header: Magenta (
Color::Rgb(255, 0, 255)) to signify error context. - Status Codes: Yellow and Bold (
Color::Rgb(255, 255, 0)) for high visibility. - Error Types: Cyan (
Color::Rgb(0, 255, 255)). - Counts: Pink (
Color::Rgb(255, 182, 193)). - Descriptions: Light Green (
Color::Rgb(144, 238, 144)).
Sources: src/tabs/errors.rs:40, src/tabs/errors.rs:55-61
The Errors Tab serves as a critical monitoring component for operational health, providing immediate visibility into Nginx response failures and their distribution across unique URLs and IPs.