【问题标题】:Add prometheus ready application to the Prometheus将 prometheus 就绪应用程序添加到 Prometheus
【发布时间】:2021-01-15 15:05:49
【问题描述】:

我在 Kubernetes 服务的 default 命名空间上安装了一个 python 应用程序。它使用starlette_exporter 并将/metrics 端点暴露给Prometheus。当我访问1.2.3.4/metrics 端点时,我看到:

...
process_open_fds 21.0
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 1.048576e+06
# HELP starlette_request_duration_seconds HTTP request duration, in seconds
# TYPE starlette_request_duration_seconds histogram  
starlette_request_duration_seconds_bucket{app_name="starlette",le="0.005",method="GET",path="/sitemap.xml",status_code="404"} 1.0
starlette_request_duration_seconds_bucket{app_name="starlette",le="0.01",method="GET",path="/sitemap.xml",status_code="404"} 1.0
starlette_request_duration_seconds_bucket{app_name="starlette",le="0.025",method="GET",path="/sitemap.xml",status_code="404"} 1.0
...

我还在该 Kubernetes 服务的 monitor 命名空间上安装了 kube-prometheus-stack。它没有自定义,我使用此命令进行安装:

helm install prometheus-stack prometheus-community/kube-prometheus-stack -n monitor

将我的应用程序指标添加到我可以在 Grafana 仪表板上跟踪的 Prometheus 堆栈的必要步骤是什么?据我了解,我应该编写一个自定义配置,并可能通过发出某种kubectl 命令以某种方式将其包含在 Prometheus 中。请具体。

【问题讨论】:

    标签: prometheus grafana


    【解决方案1】:

    “导航到 prometheus 目录中的 prometheus.yml 文件,并将 IP 添加到目标字段。See their docs 和下面的示例

    global:
      scrape_interval:     15s # By default, scrape targets every 15 seconds.
    
    ...
        static_configs:
          - targets: ['1.2.3.4:9090']
    

    targets 示例默认使用端口 9090,但将其替换为您个人拥有的任何端口,以便向 prometheus 公开指标。 下一步是将 grafana 安装在与 prometheus 文件夹的根目录相同的根目录中。安装它并使用“admin”的用户名/密码在端口 3000 上启动它。至此,我recommend just following their documentation step by step.您可以手动添加自己的grafana面板,只需输入所需的指标名称,图表就会自动出现。

    【讨论】:

      【解决方案2】:

      您需要在应用程序命名空间中的命名空间中为您的应用程序创建服务监视器,以便 prometheus 可以读取它并配置抓取作业。可以参考下面的sn-p。

      apiVersion: monitoring.coreos.com/v1
      kind: ServiceMonitor
      metadata:
        annotations:
        labels:
          release: prometheus-operator
        name: keycloak
        namespace: keycloak
      spec:
        endpoints:
        - interval: 60s
          path: /auth/realms/master/metrics
          port: http
          scrapeTimeout: 30s
        selector:
          matchLabels:
            app.kubernetes.io/instance: keycloak
            app.kubernetes.io/name: keycloak
            service: http
      

      您可以参考this的文章。

      【讨论】:

        猜你喜欢
        • 2020-02-24
        • 1970-01-01
        • 1970-01-01
        • 2021-10-27
        • 2021-01-19
        • 2020-11-09
        • 1970-01-01
        • 2015-05-22
        • 2018-01-07
        相关资源
        最近更新 更多