【问题标题】:Custom OpenMetrics Not Being Propagated to DataDog自定义 OpenMetrics 未传播到 DataDog
【发布时间】:2021-12-07 14:11:33
【问题描述】:

我正在使用 prometheus-fastapi-instrumentator 包来公开我的自定义指标,但它们似乎没有被 DataDog 拾取。

让 DataDog 抓取我的 Counter 指标时遇到了很多麻烦。此外,Histogram 存储桶似乎没有作为分布指标。

有人知道问题可能是什么吗?

这是我的 monitoring.py 文件:https://github.com/rileyhun/fastapi-ml-example/blob/main/app/core/monitoring.py

可重现的例子:

git clone https://github.com/rileyhun/fastapi-ml-example.git

docker build -t ${IMAGE_NAME}:${IMAGE_TAG} -f Dockerfile .
docker tag ${IMAGE_NAME}:${IMAGE_TAG} rhun/${IMAGE_NAME}:${IMAGE_TAG}
docker push rhun/${IMAGE_NAME}:${IMAGE_TAG}

minikube start --driver=docker --memory 4g --nodes 2
kubectl create namespace monitoring
helm install prometheus-stack prometheus-community/kube-prometheus-stack -n monitoring

kubectl apply -f deployment/wine-model-local.yaml
kubectl port-forward svc/wine-model-service 8080:80

python api_call.py

【问题讨论】:

    标签: python prometheus metrics fastapi datadog


    【解决方案1】:

    datadog-agent 是否配置为提取您的指标,或者您是否将指标推送到 dogstatsd?

    如果 datadog-agent 正在拉动,请确保按照此处的说明进行操作 https://docs.datadoghq.com/integrations/guide/prometheus-host-collection/

    上面的说明有更多的细节,但你通常做的是:

    1. 确保您的服务器在端点返回 prometheus 指标。您可能希望使用不同的内部端口来公开它。
    2. 通过将配置添加到代理来启用 openmetrics 集成,以便它知道它需要从您在上述步骤中公开的端点提取 prometheus 指标。如果您有 kubernetes 设置,则在应用程序端指定此配置,通常通过 spec.template.metadata.annotations 中的 Deployment 资源,如下所示:
            ad.datadoghq.com/{name of container declared in spec.containers.name}.check_names : '["openmetrics"]'
            ad.datadoghq.com/{name of container declared in spec.containers.name}.init_configs : '[{}]'
            ad.datadoghq.com/{name of container declared in spec.containers.name}.instances : |
              [
                {
                "prometheus_url" : "http://%%host%%:%%port_0%%/metrics",
                "namespace" : "",
                "metrics": ["*"],
                "tags": {"service": "{name of service for datadog}"},
                "send_histograms_buckets": true,
                "send_distribution_buckets": true,
                "send_distribution_counts_as_monotonic": true
                }
              ]
    
    1. 如果使用 kubernetes,请重新启动 datadog-agent 或部署

    【讨论】: