npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

traffic-monitor-mqtt

v0.1.10

Published

Zentrales Traffic Monitoring via MQTT für Node.js Anwendungen

Readme

traffic-monitor-mqtt

MQTT-basiertes Traffic-Monitoring für Node.js Anwendungen.

Installation

npm install traffic-monitor-mqtt

Verwendung

Basis-Setup

const { TrafficMonitor } = require('traffic-monitor-mqtt');

// Debug-Logs aktivieren (optional aber empfohlen)
process.env.DEBUG = 'traffic-monitor:*';

const monitor = new TrafficMonitor({
  mqtt: {
    host: 'your.mqtt.host',
    port: 1883,
    ssl: false,  // Optional: true für SSL/TLS
    auth: {      // Optional: Authentifizierung
      username: 'your-username',
      password: 'your-password'
    },
    tls: {       // Optional: TLS Konfiguration
      ca: 'path/to/ca.pem',
      cert: 'path/to/cert.pem',
      key: 'path/to/key.pem',
      rejectUnauthorized: true
    }
  },
  client: {
    applicationName: 'my-service',    // Name der Anwendung
    environment: 'production',        // Umgebung (production, staging, development)
    hostname: 'srv-01'               // Host-Identifier
  },
  // Optional:
  debug: true,              // Aktiviert Debug-Logging
  batchSize: 10,           // Anzahl der Events pro Batch (Standard: 10)
  batchIntervalMs: 1000    // Sendeintervall in Millisekunden (Standard: 1000)
});

// Verbindung herstellen (wichtig!)
await monitor.connect();

MongoDB Integration

// MongoDB Client wrappen
const wrappedClient = monitor.wrapMongoClient(mongoClient);

// Ab jetzt werden alle Operationen automatisch überwacht:
const db = wrappedClient.db('mydb');
const collection = db.collection('mycollection');

// Beispiel-Operationen:
await collection.insertOne({ ... });
await collection.find({ ... }).toArray();
await collection.updateMany({ ... }, { ... });

Überwachte MongoDB-Operationen:

  • find und alle Cursor-Operationen (toArray, next, forEach, etc.)
  • aggregate und Pipeline-Operationen
  • insertOne, insertMany
  • updateOne, updateMany
  • deleteOne, deleteMany
  • bulkWrite
  • watch (Changestreams)
  • und viele mehr...

Express Integration

app.use(monitor.expressMiddleware());

Custom Events

Mit Custom Events können Sie beliebige Ereignisse in Ihrer Anwendung überwachen:

// Event registrieren
monitor.registerCustomEvent({
  name: 'http-request',           // Eindeutiger Name des Events
  category: 'api',                // Kategorie für Gruppierung
  description: 'API Request',     // Optionale Beschreibung
  targetSystem: 'external-api',   // Optionales Zielsystem
  tags: {                        // Optionale Tags
    method: 'POST',
    endpoint: '/users'
  }
});

// Event auslösen
await monitor.triggerCustomEvent(
  'http-request',                // Name des registrierten Events
  {                             // Optionale Event-Daten
    statusCode: 200,
    responseTime: 150,
    payload: { /* ... */ }
  },
  150                           // Optionale Ausführungszeit in ms
);

// Event entfernen
monitor.unregisterCustomEvent('http-request');

// Alle registrierten Events abrufen
const events = monitor.getRegisteredCustomEvents();

Custom Events werden automatisch:

  • Mit Timestamp versehen
  • Mit Client-Informationen angereichert
  • Mit Performance-Metriken versehen
  • Über MQTT an den konfigurierten Broker gesendet

Features

MongoDB Monitoring

  • ✅ Vollständige Unterstützung für alle MongoDB-Operationen
  • ✅ Intelligente Erkennung von Cursor- und ChangeStream-Objekten
  • ✅ Korrekte Behandlung von synchronen und asynchronen Methoden
  • ✅ Detailliertes Tracking von Pipeline-Stages
  • ✅ Umfassende Bulk-Operation-Analyse
  • ✅ Changestream-Event-Tracking

Custom Event Monitoring

  • ✅ Flexible Event-Konfiguration
  • ✅ Automatische Performance-Messung
  • ✅ Benutzerdefinierte Tags und Metadaten
  • ✅ Gruppierung nach Kategorien
  • ✅ Zielsystem-Tracking

Performance

  • ✅ Optimierte Event-Batching
  • ✅ Effiziente Payload-Größenberechnung
  • ✅ Methoden-Caching
  • ✅ Minimaler Overhead
  • ✅ Non-blocking Event-Verarbeitung

Robustheit

  • ✅ Automatische Wiederverbindung
  • ✅ Fehlertolerantes Event-Batching
  • ✅ Typsichere Implementierung
  • ✅ Umfassende Testabdeckung

Konfigurationsoptionen

MQTT Optionen (mqtt)

  • host: MQTT Broker Hostname
  • port: MQTT Broker Port
  • ssl: SSL/TLS aktivieren (Boolean, optional)
  • auth: Authentifizierung (optional)
    • username: MQTT Benutzername
    • password: MQTT Passwort
  • tls: SSL/TLS Optionen (optional)
    • ca: CA Zertifikat
    • cert: Client Zertifikat
    • key: Client Key
    • rejectUnauthorized: Nicht vertrauenswürdige Zertifikate ablehnen

Client Optionen (client)

  • applicationName: Name der Anwendung
  • environment: Umgebung ('production', 'staging', 'development')
  • hostname: Host-Identifier

Event-Batching Optionen

  • batchSize: Anzahl der Events pro Batch (Standard: 10)
  • batchIntervalMs: Sendeintervall in Millisekunden (Standard: 1000)

Event-Format

Jedes Event enthält:

  • Timestamp (ISO 8601)
  • Client-Informationen (Name, Environment, Hostname)
  • Operationstyp (z.B. 'db:find', 'custom:api')
  • Zielsystem (z.B. 'mongodb:mydb', 'external-api')
  • Performance-Metriken (Ausführungszeit, Payload-Größe)
  • Operationsspezifische Details

Debug-Logging

Aktivieren Sie Debug-Logs mit:

export DEBUG=traffic-monitor:*

Verfügbare Debug-Namespaces:

  • traffic-monitor:mqtt: MQTT-Verbindung und Events
  • traffic-monitor:mongodb: MongoDB-Operationen
  • traffic-monitor:event-batcher: Event-Batching
  • traffic-monitor:custom-event: Custom Events

Tests

npm test

Lizenz

MIT