如何为多个目标(远程和本地)正确配置 Helm 部署的 Prometheus MySQL 导出器?

问题描述 投票:0回答:1

几天来我一直在尝试设置一个在 k8s 集群内使用 Helm 部署的多目标 MySQL 导出器 (MSE)。我使用的图表是 https://artifacthub.io/packages/helm/prometheus-community/prometheus-mysql-exporter/2.2.0(截至今天最新)。 当我尝试直接连接到主数据库而不使用

values.yaml/serviceMonitor
中的多目标配置时,它可以工作:我可以在我的grafana中看到数据。

我在文档中看到,我可以为 MSE 指定多个目标,并相应地填写了

values.yaml
(请参阅下面的
values.yaml
)。我已启用多目标并指定两个目标的密码不相同。 我的目标都是 MariaDB 数据库:一个是集群外部的(可通过 IPv4 访问),另一个是集群内部 Helm 部署的 MariaDB。

一些注意点:

  • 导出者用户同时存在于主数据库和副本数据库中,具有从任何地方进行访问的权限 (%) 以用于测试目的。
  • my.cnf
    作为集群中的秘密部署,并由
    /etc/cnf/my.cnf
    中的 mysql-exporter pod 成功恢复(参见下面的文件)

当我执行

helm upgrade
时,我从我的 Pod 日志中得到的内容如下:
caller=exporter.go:152 level=error msg="Error pinging mysqld" err="dial tcp [::1]:3306: connect: connection refused"

问题:

  • 这是一个稳定的功能吗?

  • 文档中说不使用 [client] 而是使用 [client.name] 是否准确?

  • 两个数据库其中一个连接不成功还可以吗?

  • 如何让它发挥作用?

my.cnf

[client]
user=NOT_USED
password=NOT_USED
[client.mariadb-staging]
user=exporter
password=XXXXXXXXX
[client.replica-1]
user=exporter
password=XXXXXXXXXX

values.yaml

## Default values for prometheus-mysql-exporter.
## This is a YAML-formatted file.
## Declare variables to be passed into your templates.

## namespaceOverride overrides the namespace which the resources will be deployed in
namespaceOverride: ""

## override release name
fullnameOverride: ""

replicaCount: 1

image:
  registry: quay.io
  repository: prometheus/mysqld-exporter
  ## if not set charts appVersion var is used
  tag: ""
  pullPolicy: "IfNotPresent"

# imagePullSecrets:
# - name: secret-name
imagePullSecrets: []

service:
  labels: {}
  annotations: {}
  name: mysql-exporter
  type: ClusterIP
  externalPort: 9104
  internalPort: 9104

serviceMonitor:
  # enabled should be set to true to enable prometheus-operator discovery of this service
  enabled: true
  # interval is the interval at which metrics should be scraped
  interval: 30s
  # scrapeTimeout is the timeout after which the scrape is ended
  scrapeTimeout: 10s
  namespace: monitoring
  # additionalLabels is the set of additional labels to add to the ServiceMonitor
  additionalLabels: {}
  jobLabel: ""
  targetLabels: []
  podTargetLabels: []
  metricRelabelings: []
  # Set relabel_configs as per https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
  relabelings: []
  # Enable multi target scraping.
      # target connection information with name (required), endpoint (required) and port (optionnal)
      # if sharedSecret is not enabled the name must match an entry client.{{ name }} existing in the secret
  multipleTarget:
    enabled: true
    targets:
      - name: mariadb-staging
        endpoint: xx.xxx.xxx.32
        port: 3306
      - name: replica-1
        endpoint: metabase-mariadb.database.svc.cluster.local
        port: 3306
    # Enable shared credentials for all targets
    sharedSecret:
      enabled: false
      name: ""

serviceAccount:
  # Specifies whether a ServiceAccount should be created
  create: false
  # The name of the ServiceAccount to use.
  # If not set and create is true, a name is generated using the fullname template
  name:
  annotations: {}

resources: {}
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
  #limits:
  # cpu: 100m
  # memory: 128Mi
  #requests:
  # cpu: 100m
  # memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

podLabels: {}

# Extra Volume Mounts for the mysql exporter container
extraVolumeMounts: []
# - name: example
#   mountPath: /example

# Extra Volumes for the pod
extraVolumes: []
# - name: example
#   configMap:
#     name: example

podSecurityContext: {}
  # fsGroup: 65534

securityContext: {}
  # capabilities:
  #   drop:
  #   - ALL
  # readOnlyRootFilesystem: true
  # runAsNonRoot: true
  # runAsUser: 65534

annotations:
  prometheus.io/scrape: "true"
  prometheus.io/path: "/metrics"
  prometheus.io/port: "9104"

config: {}
  # Allow to set specifc options on the exporter
  # logLevel: info
  # logFormat: "logger:stderr"

collectors:
  # auto_increment.columns: false
  # binlog_size: false
  engine_innodb_status: true
  # engine_tokudb_status: false
  # global_status: true
  # global_variables: true
  # info_schema.clientstats: false
  # info_schema.innodb_metrics: false
  # info_schema.innodb_tablespaces: false
  # info_schema.innodb_cmp: false
  # info_schema.innodb_cmpmem: false
  # info_schema.processlist: false
  # info_schema.processlist.min_time: 0
  # info_schema.query_response_time: false
  # info_schema.tables: true
  # info_schema.tables.databases: '*'
  # info_schema.tablestats: false
  # info_schema.schemastats: false
  # info_schema.userstats: false
  # perf_schema.eventsstatements: false
  # perf_schema.eventsstatements.digest_text_limit: 120
  # perf_schema.eventsstatements.limit: false
  # perf_schema.eventsstatements.timelimit: 86400
  # perf_schema.eventswaits: false
  # perf_schema.file_events: false
  # perf_schema.file_instances: false
  # perf_schema.indexiowaits: false
  # perf_schema.tableiowaits: false
  # perf_schema.tablelocks: false
  # perf_schema.replication_group_member_stats: false
  slave_status: true
  # slave_hosts: false
  # heartbeat: false
  # heartbeat.database: heartbeat
  # heartbeat.table: heartbeat

# mysql connection params which build the my.cnf config
mysql:
  db: ""
  host: ""
  ## config my.cnf https://dev.mysql.com/doc/c-api/8.0/en/mysql-options.html
  additionalConfig:
    - connect-timeout=5
    - debug
  pass: ""
  port: ""
  protocol: ""
  user: ""
  # secret with full config my.cnf
  existingConfigSecret:
    name: "config-mysql-exporter"
    key: "my.cnf"
  # secret only containing the password
  #existingSecret: "connection-string-mariadb"
  #existingPasswordSecret:
  #  name: ""
  #  key: "" 
prometheus kubernetes-helm monitoring
1个回答
0
投票

我也遇到了和你一样的问题。 根据以下文档,使用多目标方法时收集指标的路径有所不同。请参考以下链接。 https://github.com/prometheus/mysqld_exporter/blob/main/README.md#multi-target-support

因此,如果您访问以下格式的地址,您将看到指标。 http://[导出器 pod ip]:9104/probe?target=metabase-mariadb.database.svc.cluster.local:3306 而不是 http://[exporter pod ip]:9104/metrics

我不确定为什么会发生这种情况,但即使您为远程数据库设置了多目标,它似乎仍不断尝试访问本地数据库。这就是为什么连接拒绝错误不断发生的原因。

© www.soinside.com 2019 - 2024. All rights reserved.