Monitoring API Reference

API Server

Monitoring API Server

Provides a RESTful API for the LogEverything dashboard and external monitoring tools to access real-time monitoring data.

class logeverything.monitoring.api_server.MonitoringAPIServer(port=8999, storage=None, metrics_collector=None, logger=None)[source]

Bases: object

Lightweight API server for monitoring data access.

Provides endpoints for: - Real-time system metrics - Operation history and statistics - Health checks - Data export

is_running()[source]

Check if the API server is running.

Return type:

bool

start()[source]

Start the API server in a background thread.

Return type:

None

stop()[source]

Stop the API server.

Return type:

None

class logeverything.monitoring.api_server.SimpleAPIServer(port=8999, storage=None, metrics_collector=None, logger=None)[source]

Bases: object

Fallback simple HTTP server when FastAPI is not available.

is_running()[source]

Check if running.

Return type:

bool

start()[source]

Start simple HTTP server.

Return type:

None

stop()[source]

Stop the server.

Return type:

None

Storage

Data Storage for LogEverything Monitoring

Handles persistent storage of logs, metrics, and operational data in an organized, queryable format.

class logeverything.monitoring.storage.MonitoringStorage(base_dir)[source]

Bases: object

Efficient storage system for monitoring data.

Features: - SQLite for structured data (metrics, operations) - JSON Lines for logs (human readable, streamable) - Automatic data rotation and cleanup - Thread-safe operations - Fast querying and aggregation

cleanup_old_data(days=30)[source]

Clean up old data from database.

Return type:

None

cleanup_old_logs(max_files)[source]

Clean up old log files to prevent disk space issues.

Return type:

None

close_session()[source]

Mark the current session as ended.

Return type:

None

export_data(output_file, format='json')[source]

Export monitoring data to file.

Return type:

Path

get_logs(limit=100, level='', correlation_id='', source='')[source]

Query the logs table with optional filters.

Parameters:
  • limit (int) – Maximum number of records to return.

  • level (str) – Filter by log level (e.g. "ERROR").

  • correlation_id (str) – Filter by correlation / request ID.

  • source (str) – Filter by source identifier.

Return type:

List[Dict[str, Any]]

Returns:

List of log record dicts, most recent first.

get_logs_by_correlation(correlation_id)[source]

Return all log entries for a correlation ID, ordered by time.

Return type:

List[Dict[str, Any]]

get_operation_summary(hours=24)[source]

Get operation summary statistics.

Return type:

Dict[str, Any]

get_recent_metrics(limit=100)[source]

Get recent system metrics.

Return type:

List[Dict[str, Any]]

get_recent_operations(limit=100)[source]

Get recent operation metrics.

Return type:

List[Dict[str, Any]]

Get system metrics trends.

Return type:

Dict[str, Any]

store_log(log_entry)[source]

Store a single log record into the logs table.

Return type:

None

store_logs_batch(logs, source='')[source]

Store a batch of log records into the logs table.

Parameters:
  • logs (List[Dict[str, Any]]) – List of log record dicts.

  • source (str) – Default source identifier if not present in each entry.

Return type:

int

Returns:

Number of records stored.

store_metrics(metrics)[source]

Store system metrics to database.

Return type:

None

store_operation_metrics(metrics)[source]

Store operation metrics to database.

Return type:

None

Monitoring Logger

Structured Logging for LogEverything Monitoring

Provides structured, JSON-formatted logging with automatic correlation IDs, performance tracking, and integration with the monitoring system.

class logeverything.monitoring.logger.OperationTracker(logger, operation_name, **kwargs)[source]

Bases: object

Context manager for tracking operations.

class logeverything.monitoring.logger.StructuredLogger(name, storage=None, max_files=100, max_size_mb=50)[source]

Bases: object

High-performance structured logger with JSON output format.

Features: - Structured JSON logging - Automatic correlation IDs - Performance tracking - Thread-safe operations - Automatic log rotation

critical(message, extra=None, exc_info=None)[source]

Log a critical message.

Return type:

None

debug(message, extra=None)[source]

Log a debug message.

Return type:

None

error(message, extra=None, exc_info=None)[source]

Log an error message.

Return type:

None

info(message, extra=None)[source]

Log an info message.

Return type:

None

operation_end(operation_id, success=True, **kwargs)[source]

End tracking an operation.

Return type:

None

operation_start(operation_name, **kwargs)[source]

Start tracking an operation.

Return type:

str

warning(message, extra=None)[source]

Log a warning message.

Return type:

None

logeverything.monitoring.logger.set_correlation_context(corr_id, context=None)[source]

Set correlation ID and context for current thread.

Return type:

None

Metrics

System Metrics Collection for LogEverything Monitoring

Collects comprehensive system and application metrics including: - CPU usage, memory, disk I/O, network I/O - Process-specific metrics - Custom application metrics - Performance counters

class logeverything.monitoring.metrics.MetricsCollector(storage=None, collection_interval=5.0)[source]

Bases: object

High-performance metrics collector with minimal overhead.

Collects system metrics at regular intervals and provides operation-level performance tracking.

collect_system_metrics()[source]

Collect comprehensive system metrics.

Return type:

SystemMetrics

get_recent_operations(limit=100)[source]

Get recent operation metrics.

Return type:

List[OperationMetrics]

get_system_summary()[source]

Get a summary of current system state.

Return type:

Dict[str, Any]

record_operation(operation_id, operation_name, duration_seconds, success=True, error_message=None, custom_metrics=None, cpu_time=None, memory_delta=None)[source]

Record metrics for a completed operation.

Return type:

None

class logeverything.monitoring.metrics.OperationMetrics(timestamp, operation_id, operation_name, duration_seconds, cpu_time, memory_delta, success, error_message, custom_metrics)[source]

Bases: object

Metrics for a specific operation or function call.

cpu_time: float | None
custom_metrics: Dict[str, Any] | None
duration_seconds: float
error_message: str | None
memory_delta: int | None
operation_id: str
operation_name: str
success: bool
timestamp: str
class logeverything.monitoring.metrics.PerformanceTracker(metrics_collector, operation_name, operation_id=None, custom_metrics=None)[source]

Bases: object

Context manager for tracking operation performance.

start_cpu_time: float | None
start_memory: int | None
start_time: float | None
class logeverything.monitoring.metrics.SystemMetrics(timestamp, cpu_percent, cpu_count, cpu_freq_current, load_average, memory_total, memory_available, memory_used, memory_percent, swap_total, swap_used, swap_percent, disk_total, disk_used, disk_free, disk_percent, disk_read_bytes, disk_write_bytes, disk_read_count, disk_write_count, network_bytes_sent, network_bytes_recv, network_packets_sent, network_packets_recv, process_cpu_percent, process_memory_rss, process_memory_vms, process_memory_percent, process_num_threads, process_num_fds, boot_time, uptime_seconds)[source]

Bases: object

Comprehensive system metrics snapshot.

boot_time: float
cpu_count: int
cpu_freq_current: float | None
cpu_percent: float
disk_free: int
disk_percent: float
disk_read_bytes: int
disk_read_count: int
disk_total: int
disk_used: int
disk_write_bytes: int
disk_write_count: int
load_average: List[float] | None
memory_available: int
memory_percent: float
memory_total: int
memory_used: int
network_bytes_recv: int
network_bytes_sent: int
network_packets_recv: int
network_packets_sent: int
process_cpu_percent: float
process_memory_percent: float
process_memory_rss: int
process_memory_vms: int
process_num_fds: int | None
process_num_threads: int
swap_percent: float
swap_total: int
swap_used: int
timestamp: str
uptime_seconds: float

Core Monitoring

LogEverything Monitoring Core - Clean Implementation

class logeverything.monitoring.core.MonitoringSystem(output_dir='./monitoring_data', enable_api=True, api_port=8999, metrics_interval=5.0)[source]

Bases: object

Simple, clean monitoring system for LogEverything.

__enter__()[source]

Context manager entry.

Return type:

MonitoringSystem

__exit__(exc_type, exc_val, exc_tb)[source]

Context manager exit.

Return type:

None

get_status()[source]

Get current monitoring status.

Return type:

Dict[str, Any]

start()[source]

Start the monitoring system.

Return type:

None

stop()[source]

Stop the monitoring system.

Return type:

None

logeverything.monitoring.core.get_monitoring_system()[source]

Get the current global monitoring system.

Return type:

Optional[MonitoringSystem]

logeverything.monitoring.core.start_monitoring(output_dir='./monitoring_data', enable_api=True, api_port=8999, metrics_interval=5.0)[source]

Start the global monitoring system.

Return type:

MonitoringSystem

logeverything.monitoring.core.stop_monitoring()[source]

Stop the global monitoring system.

Return type:

None