How gaoyuan98/dameng_exporter works
Main Components
• Exporter Core: The central application (main file dameng_exporter.go) that initializes the service, loads configurations, sets up the HTTP endpoint, and serves the scraped metrics.
• Collector Module: Located in the “collector” directory. Each Go file (for example, db_monitor_info_collector.go, db_instance_running_info_collector.go, etc.) implements a specific metric collection logic by executing queries against the Dameng database.
• Configuration Module: Found in the “config” directory and further supported by external configuration files like dameng_exporter.config and custom_metrics.toml. This module manages database connection details, SQL queries, timeouts, logging and other runtime parameters.
• Database Connection Utility: Code in both the “db” directory and parts of “config” handles the interaction with the Dameng DB. It abstracts connection pooling, query execution, and error handling.
• Logging Utility: The “logger” module is in its separate directory to handle the logging needs with configurable log rotation and size parameters.
• Docker/Deployment Setup: The Dockerfile and associated scripts (build_all_versions.bat) indicate that the module is containerized for easy deployment across different platforms (Linux AMD64, ARM64 and Windows).
Relationships & Data Flow
• At start-up, the core executable loads configuration (from dameng_exporter.config and possibly custom_metrics.toml for custom SQL queries).
• The configuration module sets up database connection parameters using the utility functions.
• The Collector Module runs scheduled queries (from various collector_xxx.go files), each focusing on a specific area such as instance logs, sessions, slow SQL, tablespace information, and custom metrics.
• Once data is collected, the data is formatted into Prometheus metric standards, including metric names, help texts, types, and label annotations.
• The metrics are then exposed via an HTTP endpoint (default on port 9200), from which Prometheus scrapes the data.
• The external environment (Prometheus/Grafana) will interact with the exporter for monitoring, whereas internal modules interact using standard Go function calls.
Architectural Patterns & Key Technologies
• Modularity: Each metric category is encapsulated into its own Go file within the collector directory.
• Separation of Concerns: Distinct layers manage configuration, collection, database interaction, logging, and HTTP serving.
• Extensibility: Custom metrics can be added through an external TOML file. New collectors can be integrated by creating additional modules within the “collector” directory.
• Containerization: A Dockerfile is provided to enable a consistent deployment environment.
• Prometheus Integration: The design follows Prometheus exporter standards (exposing an HTTP metrics endpoint for scraping).
Elements
• Clearly labeled components:
• Exporter Core Application
• Collector Modules (individual metric collectors)
• Configuration Module (including external config files)
• Database Connection Module with connection pool and query engine
• Logging Service
• HTTP Server / Metrics Endpoint (e.g., “/metrics”)
• External Systems: Prometheus (scraping mechanism) and Grafana (dashboard visualization)
• Startup configuration loading → Database connection initialization
• Database connection → Query execution (by each collector)
• Collector modules → Metric aggregation and formatting
• Metric exposure endpoint → Prometheus scrape
• Prometheus → Grafana dashboard visualization (data flow)