Skip to content

RubenMartinezSiso/WatchdogMiddleware

Repository files navigation

Watchdog Middleware 🐶

By Rubén Martínez


🧠 Overview

Watchdog Middleware is a lightweight, pluggable .NET middleware component designed to intercept, monitor, and store API traffic with minimal configuration.

It captures request and response details, stores the data in InfluxDB, and offers real-time visualization and monitoring through Grafana. It's ideal for projects that require observability, error analysis, and performance tracking without intrusive instrumentation.

Inspired by both the electronic watchdog timer and the loyal API guardian, this middleware ensures your APIs are always under control. 🛡️


⚙️ Features

  • 📡 Intercepts all API requests/responses
  • 🗃️ Saves data in InfluxDB using customizable fields and tags
  • 📊 Integrated with Grafana for real-time dashboards
  • 🔐 Optional sensitive route exclusion and body encryption
  • 🐳 Fully Docker-ready stack for local or cloud deployments
  • 📍 IP Geolocation support out of the box

🚀 Quick Start

🐳 1. Clone and Launch via Docker

git clone https://github.com/RubenMartinezSiso/WatchdogMiddleware.git
cd WatchdogMiddleware/WatchdogMiddleware
docker compose up -d

Make sure Docker is installed and running.


🧱 2. Add Middleware to Your ASP.NET Core App

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseWatchdogMiddleware(options =>
    {
        options.ApiName = "MyAwesomeAPI";
        options.ActivateLogs = true;
        // Add more config if needed
    });

    app.UseRouting();
    app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}

📈 3. Access Grafana Dashboard

Grafana is preconfigured and accessible via:

http://localhost:3000

Use default credentials (admin / admin) unless customized.


🧪 4. Run the Integration Tests

Navigate to the test project folder and run:

dotnet test

Tests cover:

  • InfluxDB & Grafana connectivity
  • API logging functionality
  • Sensitive route exclusion
  • Checkpoint system
  • Data deletion verification

📂 Project Structure

📦 WatchdogMiddleware
 ┣ 📁 Docker         # Infrastructure (InfluxDB, Grafana, Prometheus...)
 ┣ 📁 Models         # C# classes for intercepted data
 ┣ 📁 Tests          # xUnit-based integration tests
 ┣ 🐶 WatchdogMiddleware.cs # Core middleware logic
 ┣ 📄 .env           # Environment configuration
 ┗ 📄 docker-compose.yml

🤝 Contact

If you find this useful or want to contribute, feel free to reach out or fork the project!

Rubén Martínez - LinkedIn | GitHub


About

University of Lleida | Master’s Final Project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published