【问题标题】:Configure basic_auth for Prometheus Target为 Prometheus Target 配置 basic_auth
【发布时间】:2020-09-23 15:17:54
【问题描述】:

我的 prometheus.yml 配置文件中static_configs 中的一个目标通过基本身份验证进行保护。因此,Prometheus 目标页面中始终针对该目标显示描述“连接被拒绝”的错误。

我研究了如何设置 prometheus 以在尝试抓取特定目标但找不到任何解决方案时提供安全凭据。我发现如何在文档的scrape_config 部分进行设置。这对我不起作用,因为我还有其他不受basic_auth 保护的目标。 请帮我解决这个挑战。

关于我的挑战,这是我的.yml 配置的一部分。

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s
    scrape_timeout: 5s

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      
      - targets: ['localhost:5000']
        labels: 
          service: 'Auth'
      - targets: ['localhost:5090']
        labels:
          service: 'Approval'
      - targets: ['localhost:6211']
        labels:
          service: 'Credit Assessment'
      - targets: ['localhost:6090']
        labels:
          service: 'Sweep'
      - targets: ['localhost:6500']
        labels:

【问题讨论】:

    标签: monitoring prometheus


    【解决方案1】:

    我想在@PatientZro 答案中添加更多详细信息。

    在我的情况下,我需要创建另一个作业(如指定),但 basic_auth 需要与作业名称处于同一缩进级别。见example here

    同样,我的 basic_auth 案例需要路径,因为它们不会显示在我的域的根目录中。

    这是一个指定 API 端点的示例:

      - job_name: 'myapp_health_checks'
        scrape_interval: 5m
        scrape_timeout: 30s
        static_configs:
            - targets: ['mywebsite.org']
        metrics_path: "/api/health"
        basic_auth:
          username: 'email@username.me'
          password: 'cfgqvzjbhnwcomplicatedpasswordwjnqmd'
    

    最好的,

    【讨论】:

    • 也可以指定password_file: valid_password_file而不是硬编码密码以供参考。
    • 你好,贾斯汀,我建议你看看这个链接:github.com/prometheus/prometheus/issues/… 似乎可以从 Prometheus 2.27 开始替换环境变量。我没有测试它。最佳
    【解决方案2】:

    为需要身份验证的人创建另一个工作。
    所以就在你发布的内容下,再做一个

      - job_name: 'prometheus-basic_auth'
        scrape_interval: 5s
        scrape_timeout: 5s
        static_configs:
          
          - targets: ['localhost:5000']
            labels: 
              service: 'Auth'
            basic_auth:
              username: foo
              password: bar
    

    【讨论】:

    • 我认为这是无效的。 Prometheus 无法解析这样的配置并失败并显示以下错误消息:level=error err="Error loading config couldn't load configuration (--config.file=/etc/prometheus/prometheus.yml): parsing YAML file /etc/prometheus/prometheus.yml: unknown fields in static_config: basic_auth"
    • 我认为 basic_auth 部分应该在 job_name 部分下,而不是目标
    猜你喜欢
    • 1970-01-01
    • 2021-07-13
    • 2018-04-17
    • 2020-10-05
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 2020-01-30
    • 1970-01-01
    相关资源
    最近更新 更多