prometheus / mysqld_exporter

Exporter for MySQL server metrics
http://prometheus.io/
Apache License 2.0
2.15k stars 752 forks source link

docker compose start error #750

Closed blankhang closed 1 year ago

blankhang commented 1 year ago

Host operating system: output of uname -a

Linux vm-ubuntu-11 5.19.0-45-generic #46~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 7 15:06:04 UTC 20 x86_64 x86_64 x86_64 GNU/Linux

mysqld_exporter version: output of mysqld_exporter --version

0.15.0 on docker

MySQL server version

8.0.32 on docker

mysqld_exporter command line flags

version: '3.9'
services:

  mysql-exporter:
      image: prom/mysqld-exporter
      container_name: mysql-exporter
      restart: unless-stopped
      deploy:
        placement:
          constraints:
            - 'node.hostname == vm-ubuntu-11'
      environment:
        - DATA_SOURCE_NAME="mysql_monitor:passwd@(192.168.50.11:3306)/"
      ports:
        - 9104:9104
      networks:
        - monitoring

  prometheus:
    image: prom/prometheus
    container_name: prometheus
    restart: unless-stopped
    user: "0"
    deploy:
      placement:
        constraints:
          - 'node.hostname == vm-ubuntu-11'
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--log.level=error'
      - '--storage.tsdb.path=/prometheus'
      - '--storage.tsdb.retention.time=7d'
      - '--web.console.libraries=/usr/share/prometheus/console_libraries'
      - '--web.console.templates=/usr/share/prometheus/consoles'
      - '--web.external-url=http://localhost:9090'
    volumes:
      - /docker/stack/monitor-stack/configs/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
      - /docker/stack/monitor-stack/prometheus-data:/prometheus
    depends_on:
      - alertmanager
    ports:
      - 9090:9090
    networks:
      - monitoring
networks:
  monitoring:
    driver: overlay

prometheus.yml

global:
  scrape_interval: 60s # Set the scrape interval to every 5 seconds. Default is every 1 minute.
  evaluation_interval: 60s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).  
  external_labels:
    namespace: local

rule_files:
  - /etc/prometheus/recording-rules.yml
  - /etc/prometheus/alerting-rules.yml

alerting:
  alertmanagers:
    - scheme: http
      static_configs:
        - targets: ['alertmanager:9093']

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: [ 'localhost:9090' ]
        labels:
          container: 'prometheus'

  - job_name: 'docker'
    static_configs:
      - targets: ['192.168.50.11:9323']

  - job_name: mysql-exporter
    static_configs: 
      - targets: [ '192.168.50.11:9104' ] 
        # labels: 
        #   instance: 'mysql-exporter'

What did you do that produced an error?

ts=2023-06-30T12:56:35.827Z caller=mysqld_exporter.go:220 level=info msg="Starting mysqld_exporter" version="(version=0.15.0, branch=HEAD, revision=6ca2a42f97f3403c7788ff4f374430aa267a6b6b)"
ts=2023-06-30T12:56:35.827Z caller=mysqld_exporter.go:221 level=info msg="Build context" build_context="(go=go1.20.5, platform=linux/amd64, user=root@c4fca471a5b1, date=20230624-04:09:04, tags=netgo)"
ts=2023-06-30T12:56:35.827Z caller=config.go:150 level=error msg="failed to validate config" section=client err="no user specified in section or parent"
ts=2023-06-30T12:56:35.827Z caller=mysqld_exporter.go:225 level=info msg="Error parsing host config" file=.my.cnf err="no configuration found"

What did you expect to see?

start without error

What did you see instead?

can not start

SuperQ commented 1 year ago

For questions/help/support please use our community channels. There are more people available to potentially respond to your request and the whole community can benefit from the answers provided.

neodon commented 10 months ago

Here's the solution in case anyone else runs into this and doesn't want to figure out which of the 7 different possible community channels has it.

Apparently the DATA_SOURCE_NAME environment variable is now silently ignored, even though the documentation for the prom/mysqld-exporter docker image still prominently shows it as the way to configure credentials.

You'll need to use command-line arguments:

mysqld-exporter:
    image: quay.io/prometheus/mysqld-exporter
    container_name: mysqld-exporter
    restart: unless-stopped
    command:
     - "--mysqld.username=user:password"
     - "--mysqld.address=host:port"
    networks:
      - mynet

Source: https://discuss.prometheus.io/t/docker-compose-mysql-exporter-start-error/1734/2

This issue isn't actually related to #763 other than DATA_SOURCE_NAME being ignored.

Also, I have to wonder why the username argument holds both the username and password, and the address argument holds both the host and port. 🤷‍♀️

caburet commented 4 months ago

Here's the solution in case anyone else runs into this and doesn't want to figure out which of the 7 different possible community channels has it.

Apparently the DATA_SOURCE_NAME environment variable is now silently ignored, even though the documentation for the prom/mysqld-exporter docker image still prominently shows it as the way to configure credentials.

You'll need to use command-line arguments:

mysqld-exporter:
    image: quay.io/prometheus/mysqld-exporter
    container_name: mysqld-exporter
    restart: unless-stopped
    command:
     - "--mysqld.username=user:password"
     - "--mysqld.address=host:port"
    networks:
      - mynet

Source: https://discuss.prometheus.io/t/docker-compose-mysql-exporter-start-error/1734/2

This issue isn't actually related to #763 other than DATA_SOURCE_NAME being ignored.

Also, I have to wonder why the username argument holds both the username and password, and the address argument holds both the host and port. 🤷‍♀️

this solves the problem! thank you!