Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[DataDog] How does DataDog collect metrics from the Prometheus exporter endpoint

Posted on April 5, 2023July 10, 2023 By nim No Comments on [DataDog] How does DataDog collect metrics from the Prometheus exporter endpoint

Contents

Toggle
  • 1) Introduce the design architecture
  • 2) Configure the monitoring components.
    • 2.1) Install the Cloudwatch exporter.
    • 2.2) Configure DataDog to collect metrics from prometheus-cloudwatch-exporter
  • Solve ISsues.
    • Read timed out.

1) Introduce the design architecture

Mô hình bạn có thể thấy như hình bên dưới.

Thì mình dùng datadog agent trên k8s để collect metrics của cloudwatch
Nhưng mà datadog agent không để đọc trực tiếp vào Cloudwatch nên mình sẽ sử dụng 1 opensource của prometheus là prometheus cloudwatch exporter để get metrics từ cloud watch.
https://github.com/prometheus/cloudwatch_exporter

Tiếp đó là agent datadog sẽ get metrics của prometheus cloudwatch exporter thông qua package: OpenMetrics
https://docs.datadoghq.com/containers/kubernetes/prometheus/?tab=kubernetesadv2
https://docs.datadoghq.com/developers/custom_checks/prometheus/

Bạn sẽ bảo là datadog có thể chủ động lấy metrics từ aws và chỉ cần cung cấp access key và secret key là xong. Nim làm rườm ra quá.

Với cách của bạn thì mình thấy là datadog sẽ cần tạo 1 Lamda để craw data từ Cloudwatch.

Lý do:
1) Hiện tại mình đăng sài bạn free cho homelab thì không tùy ý sài nhiều dịch vụ trên aws, cũng như tạo nhiều instances của datadog được.
2) Hiện tại mình muốn test là làm sao để datadog draw metrics của các endpoints được viết dựa trên package prometheus.
Ví dụ mình muốn monitor keda thông qua endpoint metrics mặc định của keda thì sẽ cần dùng cách OpenMetrics.

2) Configure the monitoring components.

2.1) Install the Cloudwatch exporter.

mình sẽ cài thông qua helm.

REPO URL: https://prometheus-community.github.io/helm-charts
CHART: prometheus-cloudwatch-exporter:0.24.0

Tiếp đến là helm values:

aws:
  aws_access_key_id: XXXXXRU2NYXXXXX
  aws_secret_access_key: XXXXXXXXGpzKfj+L0eXPXXXXXXXX

config: |-
  # This is the default configuration for prometheus-cloudwatch-exporter
  region: us-west-2
  period_seconds: 300
  metrics:
  - aws_namespace: AWS/EBS
    aws_metric_name: VolumeReadOps
    aws_statistics: [Average]
    aws_dimensions: [VolumeId]

Theo mình thì phần căng nhất là bạn chả hiểu làm thể nào để define được cái select đúng không?

Cách đầu tiên bạn cần chọn bừa trên cloudwatch trên web

Sau bạn đã chọn các thông số phù hợp thì bạn dùng thêm command để get

aws cloudwatch get-metric-statistics \
--namespace AWS/EBS \
--metric-name VolumeWriteOps \
--start-time 2023-04-04T08:00:00 \
--end-time 2023-04-04T08:15:00 \
--period 300 \
--statistics Average \
--dimensions Name=VolumeId,Value=vol-04aea841f49924bdd \
--profile nimtechnology-staging \
--region us-west-2

Giờ mình cần note vài thứ:

statistics là gì?
sau đây là gợi ý của chatgpt:

To create a chart based on the AWS/EBS VolumeReadOps metric, you can use the CloudWatch console or API to retrieve the data points for the metric over a specific time range, and then plot the data points on a line chart.

Here are some statistics that you can calculate for the VolumeReadOps metric:

  1. Average: The average number of read operations per second over the specified time range.
  2. Minimum: The minimum number of read operations per second during the specified time range.
  3. Maximum: The maximum number of read operations per second during the specified time range.
  4. Sum: The total number of read operations that occurred during the specified time range.

You can choose any of these statistics to plot on the chart. For example, if you want to show the trend of the average number of read operations over time, you can plot the average statistic as a line chart. Or, if you want to show the total number of read operations over time, you can plot the sum statistic as a stacked area chart.

Lấy aws_metric_name ở đâu?

aws_dimensions thì sao?

Bạn sẽ lấy nó ở ô filter by nhé

lúc này bạn curl vào enpoind của cloudwatch exporter

Đã nhận.
Done Cloudwatch exporter!

2.2) Configure DataDog to collect metrics from prometheus-cloudwatch-exporter

Bạn sẽ setup OpenMetrics trên datadog agent để collect metrics từ CloudWatch Exporter.

Bạn sẽ sửa helm value của datadog.

datadog:
  ...
  ...
  confd:
    openmetrics.yaml: |-
      instances:
        - openmetrics_endpoint: http://cloudwatch-prometheus-cloudwatch-exporter.prometheus:9106/metrics
          namespace: cloudwatch
          metrics:
            - aws_ebs_volume_read_ops_average: aws_ebs_volume_read_ops_average
            - aws_ebs_volume_write_ops_average: aws_ebs_volume_write_ops_average

https://docs.datadoghq.com/containers/kubernetes/prometheus/?tab=kubernetesadv2

Tên file cố định là openmetrics.yaml vì bạn sử dụng openmetrics để collect metrics.
Nếu bạn đặt tên khác nó sẽ lỗi.

namespace: Set namespace to be prefixed to every metric when viewed in Datadog.

Có hình để bạn dễ tưởng tượng.

Phần metrics: bạn sẽ chỉ lấy một số metrics và đưa vào datadog thôi ví dụ.

Trong đống metrics đó bạn chỉ lấy: aws_ebs_volume_read_ops_average

The metrics configuration is a list of metrics to retrieve as custom metrics. Include each metric to fetch and the desired metric name in Datadog as key value pairs, for example, {"<METRIC_TO_FETCH>":"<NEW_METRIC_NAME>"}. You can alternatively provide a list of metric names strings, interpreted as regular expressions, to bring the desired metrics with their current names. If you want all metrics, then use ".*" rather than "*".

Note: Regular expressions can potentially send a lot of custom metrics.

For a full list of available parameters for instances, including namespace and metrics, see the sample configuration openmetrics.d/conf.yaml.

Vậy là datadog đã có metrics của cloudwatch

Solve ISsues.

Read timed out.

Một hôm mạng lag, thể là mình lên datadog mà thấy dashboard ko có data

Dưới đây là log trong datadog agent.

2023-04-17 04:25:19 UTC | CORE | ERROR | (pkg/collector/python/datadog_agent.go:130 in LogMessage) | openmetrics:cloudwatch:6d8b7e1d977e1d09 | (base.py:66) | There was an error scraping endpoint http://cloudwatch-prometheus-cloudwatch-exporter.prometheus:9106/metrics: HTTPConnectionPool(host='cloudwatch-prometheus-cloudwatch-exporter.prometheus', port=9106): Read timed out. (read timeout=10.0)

To increase the timeout for the OpenMetrics integration when calling the openmetrics_endpoint, you can add the timeout parameter to the instance configuration in the openmetrics.yaml file. The timeout parameter is specified in seconds.

Here’s an updated version of your configuration snippet with a 30-second timeout:

datadog:
  logs:
    enabled: true
    containerCollectAll: true
  confd:
    openmetrics.yaml: |-
      instances:
        - openmetrics_endpoint: http://cloudwatch-prometheus-cloudwatch-exporter.prometheus:9106/metrics
          namespace: cloudwatch
          metrics:
            - aws_ebs_volume_read_ops_average: aws_ebs_volume_read_ops_average
            - aws_ebs_volume_write_ops_average: aws_ebs_volume_write_ops_average
          timeout: 30

In this example, the timeout for the OpenMetrics integration when calling the specified endpoint is set to 30 seconds. Adjust the value of the timeout parameter to meet your specific requirements.

Nó ở đây Bạn có thể recheck lại.

https://github.com/DataDog/integrations-core/blob/master/openmetrics/datadog_checks/openmetrics/data/conf.yaml.example#L35

DataDog, Prometheus

Post navigation

Previous Post: [Datadog/Tracing] Apply the tracing datadog for PHP or WordPress.
Next Post: [Argo-Workflows] Lesson6: Output Parameter File

More Related Articles

[Kubernetes] Monitor Persistent Volume usage in Kubernetes using Prometheus Prometheus
[Prometheus] Relabelling – Đưa thông tin từ Discovered Label sang target label Log, Monitor & Tracing
[Prometheus – Grafana – Monitoring] Look into rate and irate, min, max, average and latest over a specific time. Prometheus
[Node exporter] Install node_exporter on MacOS BareMetal
[Prometheus/Grafana] Install Prometheus and Grafana on ubuntu. BareMetal
[Datadog] Using DataDog to monitor all services on kubernetes DataDog

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [AWS/EKS] Cache Docker image to accelerate EKS container deployment. July 10, 2025
  • [Laravel] Laravel Helpful June 26, 2025
  • [VScode] Hướng dẫn điều chỉnh font cho terminal June 20, 2025
  • [WordPress] Hướng dấn gửi mail trên WordPress thông qua gmail. June 15, 2025
  • [Bitbucket] Git Clone/Pull/Push with Bitbucket through API Token. June 12, 2025

Archives

  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.