Skip to content

andrewauc/influxdb-monitor

Repository files navigation

InfluxDB Monitor

A simple Node.js application that monitors InfluxDB data recency and sends Telegram alerts when data becomes stale.

Features

  • ✅ Monitors multiple InfluxDB buckets for data recency
  • 📱 Sends Telegram alerts when data is stale or missing
  • 📊 Comprehensive logging with Winston
  • 🐳 Docker support with multi-arch builds
  • 🚀 GitHub Actions CI/CD pipeline
  • ⚡ Modern ES modules and latest Node.js features

Quick Start

Prerequisites

  • Node.js 18+
  • InfluxDB instance
  • Telegram bot token and chat ID

Installation

  1. Clone the repository:
git clone <your-repo-url>
cd influxdb-monitor
  1. Install dependencies:
npm install
  1. Configure environment variables:
cp .env.example .env
# Edit .env with your configuration
  1. Start the application:
npm start

Configuration

Environment Variables

Variable Description Required Default
INFLUXDB_URL InfluxDB server URL -
INFLUXDB_TOKEN InfluxDB access token -
INFLUXDB_ORG InfluxDB organization -
BUCKETS_TO_MONITOR Comma-separated list of buckets -
TOLERANCE Maximum age before alerting (e.g., "30s", "5m", "1h") 30s
TELEGRAM_BOT_TOKEN Telegram bot token -
TELEGRAM_CHAT_ID Telegram chat ID for alerts -
CHECK_INTERVAL_MINUTES How often to check (minutes) 5
LOG_LEVEL Logging level (debug, info, warn, error) info

Getting Telegram Credentials

  1. Create a bot by messaging @BotFather on Telegram
  2. Get your chat ID by messaging @userinfobot
  3. Add the bot to your chat/channel and make it an admin (if using a channel)

Docker Usage

Build and Run

# Build the image
docker build -t influxdb-monitor .

# Run with environment file
docker run -d --name influxdb-monitor --env-file .env influxdb-monitor

# Or run with individual environment variables
docker run -d --name influxdb-monitor \
  -e INFLUXDB_URL=https://your-influxdb.com \
  -e INFLUXDB_TOKEN=your-token \
  -e INFLUXDB_ORG=your-org \
  -e BUCKETS_TO_MONITOR=bucket1,bucket2 \
  -e TOLERANCE=30s \
  -e TELEGRAM_BOT_TOKEN=your-bot-token \
  -e TELEGRAM_CHAT_ID=your-chat-id \
  influxdb-monitor

Docker Compose

version: '3.8'

services:
  influxdb-monitor:
    build: .
    env_file: .env
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "node", "-e", "console.log('Health check passed')"]
      interval: 30s
      timeout: 3s
      retries: 3

Development

Scripts

npm start          # Start the application
npm run dev        # Start with file watching
npm test           # Run tests
npm run lint       # Run ESLint
npm run format     # Format code with Prettier

Project Structure

src/
├── index.js              # Main application entry point
├── influxdb-client.js    # InfluxDB connection and queries
├── telegram-client.js    # Telegram bot integration
├── logger.js             # Winston logging configuration
└── utils.js              # Utility functions

GitHub Actions

The project includes a complete CI/CD pipeline:

  • Test: Runs on Node.js 18 and 20
  • Security: Performs npm audit
  • Build: Creates multi-arch Docker images
  • Deploy: Placeholder for deployment logic

Images are automatically pushed to GitHub Container Registry (ghcr.io).

Monitoring and Alerts

Alert Types

  • 🚨 Stale Data: When data is older than the tolerance threshold
  • ⚠️ No Data: When no data is found in a bucket
  • Error: When there's an error checking a bucket

Log Levels

  • debug: Detailed query information
  • info: General status updates
  • warn: Stale data warnings
  • error: Connection and query errors

Troubleshooting

Common Issues

  1. InfluxDB Connection Errors

    • Verify URL, token, and organization
    • Check network connectivity
    • Ensure token has read permissions
  2. Telegram Not Working

    • Verify bot token and chat ID
    • Ensure bot is added to the chat/channel
    • Check bot permissions
  3. No Data Found

    • Verify bucket names are correct
    • Check if data exists in the specified time range
    • Review InfluxDB query logs

Debugging

Enable debug logging:

LOG_LEVEL=debug npm start

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages