Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mysql metrics exporter and registrar integration
Browse files Browse the repository at this point in the history
- Add mysqld_exporter build stage and binary
- Create dedicated exporter MySQL user with restricted privileges
- Configure MySQL exporter with environment-specific service naming
- Add metrics registrar for metrics collection and proxy
- Update Docker build stages to include new components
pcfreak30 committed Dec 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 57ba87b commit be7f2cb
Showing 4 changed files with 34 additions and 4 deletions.
17 changes: 14 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
ARG MYSQL_VERSION=8
ARG METRICS_EXPORTER_VERSION=develop
ARG MYSQL_MANAGER_VERSION=develop
ARG METRICS_REGISTRAR_VERSION=develop
ARG ETCD_VERSION=3.5
ARG GO_VERSION=1.21

# Disable Percona Telemetry
ARG PERCONA_TELEMETRY_DISABLE=1

# Use metrics exporter as builder stage
# Use metrics exporter and registrar as builder stages
FROM ghcr.io/lumeweb/akash-metrics-exporter:${METRICS_EXPORTER_VERSION} AS metrics-exporter
FROM ghcr.io/lumeweb/akash-metrics-registrar:${METRICS_REGISTRAR_VERSION} AS metrics-registrar

# Build mysqld_exporter
FROM golang:${GO_VERSION} AS mysqld-builder
RUN go install github.com/prometheus/mysqld_exporter@latest

FROM docker.io/bitnami/etcd:${ETCD_VERSION} as etcd

FROM percona:${MYSQL_VERSION}
@@ -41,7 +48,11 @@ COPY --chown=mysql:mysql paths.sh /paths.sh
COPY --chown=mysql:mysql lib/ /usr/local/lib/
COPY --chown=mysql:mysql bin/mysql-backup-* /usr/local/bin/
RUN chmod 755 /usr/local/bin/mysql-backup-*

# Copy binaries from builder stages
COPY --from=metrics-exporter /usr/bin/metrics-exporter /usr/bin/akash-metrics-exporter
COPY --from=metrics-registrar /usr/bin/metrics-registrar /usr/bin/akash-metrics-registrar
COPY --from=mysqld-builder /go/bin/mysqld_exporter /usr/bin/mysqld_exporter
COPY --from=etcd /opt/bitnami/etcd/bin/etcdctl /usr/bin/etcdctl
COPY ./docker-entrypoint-initdb.d /docker-entrypoint-initdb.d

@@ -57,4 +68,4 @@ USER root
VOLUME ["/var/lib/data"]

ENTRYPOINT ["/entrypoint.sh"]
CMD ["mysqld"]
CMD ["mysqld"]
2 changes: 2 additions & 0 deletions docker-entrypoint-initdb.d/04-create-exporter-user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE USER IF NOT EXISTS 'exporter'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
18 changes: 17 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -75,8 +75,24 @@ start_services() {
start_cron
fi

# Start akash-metrics-exporter
# Set exporter password same as root
export MYSQL_EXPORTER_PASSWORD="${MYSQL_ROOT_PASSWORD}"

# Start MySQL exporter (internal only)
mysqld_exporter \
--web.listen-address=":9104" \
--config.my-cnf=/etc/my.cnf.d/exporter.cnf &

# Start Akash metrics exporter (env vars already set)
akash-metrics-exporter &
# Start Akash metrics registrar
akash-metrics-registrar \
--target-host="localhost" \
--target-port=9104 \
--target-path="/metrics" \
--proxy-port=9090 \
--exporter-type="mysql" \
--metrics-password="${METRICS_PASSWORD}" &
}

# Stop services before exit
1 change: 1 addition & 0 deletions lib/mysql-config.sh
Original file line number Diff line number Diff line change
@@ -382,6 +382,7 @@ EOF

# Configure backup streaming
configure_backup_streaming

return 0
}

0 comments on commit be7f2cb

Please sign in to comment.