Sentinel Logo

Developer Deep Dive

Technical Architecture

A detailed look at Sentinel's core components, autopilot algorithms, and internal API structure.

Core Components

Sentinel Drone (Agent)

The agent is built with Python and Flask, utilizing SQLAlchemy for state management. It runs as a systemd service (`sentinel.service`) and manages background tasks via APScheduler.

MySQLAnalyzer

A custom module that parses the MySQL slow query log, normalizes queries, and executes `EXPLAIN` plans to identify missing indexes, filesort issues, and full table scans.

Autopilot Algorithms

Index Suggestion Logic

Sentinel uses a weighted scoring system to prioritize index candidates:

score = (query_frequency * avg_latency) / rows_examined
if rows_examined > 10000 and 'Using filesort' in explain_plan:
    suggest_index(columns, priority='HIGH')

Security State Sync

The Security Autopilot periodically scans for active listening ports and ensures corresponding Fail2Ban jails are active:

active_services = get_listening_ports()
for service in active_services:
    if not f2b_manager.has_jail(service):
        f2b_manager.create_jail(service)
        f2b_manager.reload()

Internal API Reference

EndpointMethodDescription
/api/v1/statusGETReturns global system health and counters.
/api/v1/optimizationsGETLists pending and applied index suggestions.
/api/v1/queen/syncPOSTSyncs anonymized reports with Queen backend.

Deployment Guide

Sentinel is typically deployed via Gunicorn behind a Caddy reverse proxy. The installation script handles the creation of the `sentinel` user and the necessary systemd units.

sentinel.service

[Unit]
Description=Sentinel AI Drone
After=network.target mysql.service

[Service]
User=sentinel
WorkingDirectory=/opt/sentinel
ExecStart=/opt/sentinel/venv/bin/gunicorn -w 4 -b 127.0.0.1:5000 app:app