首页 > 解决方案 > 如何在 prometheus 配置文件中指定完整的 URL?

问题描述

我想监控一个使用 apache-tomact 8 部署的应用程序,例如 url 是 hostip:port/login.jsp 但在 prometheus 配置文件中我们只能提到 hostip:port ,我可以在哪里指定额外的登录。 jsp 路径,以便它监视该特定应用程序。

我已经尝试更改 mertic_path ,但遇到了一些无效的有效令牌错误。

配置文件:

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

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

rule_files:
  - 'promrules.yml'


scrape_configs:
  - job_name: 'prometheus'

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

    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'bank'
    #metrics_path: /login.jsp
    static_configs:
    - targets: ['<hostip>:<port>']

标签: prometheus

解决方案


使用的最小示例配置metrics_path如下所示:

- job_name: my-service
  metrics_path: "/custom-metrics-endpoint"
  static_configs:
    - targets:
      - localhost:9090

如果遇到 yaml 解析错误,请在路径周围使用引号。


推荐阅读