How prometheus/mysqld_exporter works
This project is an open‐source Prometheus exporter written in Go that collects MySQL server metrics. The main purpose of the tool is to scrape various metrics (such as global status, heartbeat, performance schema metrics, and more) from MySQL/MariaDB instances and expose them via an HTTP endpoint so Prometheus can scrape them.
Main Components
• Exporter Service (Main Application): Represents the core binary (mysqld_exporter.go) that initializes and orchestrates all operations.
• Collector Modules: Located within the “collector” directory, these modules are each responsible for gathering specific sets of metrics (e.g., binlog, heartbeat, info_schema details, performance_schema, etc.). Display these as separate, labeled blocks showing individual responsibilities.
• Configuration Module: Found in the “config” directory along with test data. This manages MySQL credential loading and settings, including reading from a .my.cnf file.
• Web Server & Metrics Endpoint: Embedded in the application, this component listens on the specified "web.listen-address" (e.g., localhost:9104) and provides the /metrics endpoint (and the /probe endpoint for multi-target support) for Prometheus.
• mysqld-mixin: This folder contains additional dashboards, alerting rules, and mixin libraries that integrate with Prometheus for visualization and alerting. Represent it as a supporting component linked to the Prometheus ecosystem.
Relationships and Data Flow
• Inside the exporter, illustrate data flow from the HTTP Server to the various Collector Modules.
• From each collector, show connections (or queries) to the MySQL Server(s), indicating that they pull data directly based on the configured credentials.
• If incorporating the multi-target functionality, represent an additional flow where an HTTP request with parameters (target and auth_module) causes the exporter to connect to alternate MySQL targets.
Architectural Patterns and Design Principles
• Separation of Concerns: Distinguish between components handling configuration, network I/O (web server), and business logic (collectors querying MySQL).
• Extensibility: Note that collectors can be enabled/disabled via flags and configuration, so highlight that the system is designed with flexibility in mind.
• Loose Coupling: Convey that the Exporter acts as a coordinator where changes in one collector do not necessarily affect others.
Relevant Technologies, Frameworks, and Libraries
• Prometheus: Emphasize that the exporter is built to integrate with Prometheus through its text exposition format.
• Docker: As Docker deployment is supported (via Dockerfile and related instructions), include this as a deployment option.