For AI agents: the complete documentation index is available at https://docs.ovhcloud.com/it/llms.txt, the full documentation bundle is available at https://docs.ovhcloud.com/it/llms-full.txt, and this page is available as Markdown at https://docs.ovhcloud.com/it/guides/public-cloud/containers-orchestration/managed-kubernetes/monitoring-instances-prometheus-grafana.md.

Collect metrics from Public Cloud instances with Prometheus on an OVHcloud Managed Kubernetes Service

Vedi come Markdown

Find out how to collect metrics from VPS, Public Cloud instances or baremetal servers with Prometheus on an OVHcloud Managed Kubernetes Service

Objective

This tutorial show you how to configure the Prometheus operator to monitor static exporter, OVHcloud VPS, OVHcloud dedicated servers or Public Cloud OpenStack instances.

Before you begin

This tutorial presupposes the following:

Warning

Important information:

  • This node exporter process should be secured, this is not the subject of this tutorial.
Warning

Important information:

Info

This tutorial uses as an example a node-exporter to scrape but it can be adapted to any exporter, by adjusting the IP and listening port.

In the next step, you need the release name of your chart. To get it, just use the following command:

helm list -A
NAME                                NAMESPACE     REVISION    UPDATED                                 STATUS      CHART                           APP VERSION
kube-prometheus-stack-1720169205    prometheus    1           2024-07-05 10:47:00.03314 +0200 CEST    deployed    kube-prometheus-stack-61.2.0    v0.75.0

Here the release name is kube-prometheus-stack-1720169205, referenced in the next steps under the form <release_name>.

Instructions

Generate the configuration for static exporter

Let's assume you want to scrape the following exporter prometheus.demo.do.prometheus.io:9090.

Create a file named static.yaml with the following content:

apiVersion: monitoring.coreos.com/v1alpha1
kind: ScrapeConfig
metadata:
    name: static-config
    namespace: prometheus
    labels:
        release: `<release_name>`
spec:
    staticConfigs:
        - labels:
              job: prometheus
          targets:
              - prometheus.demo.do.prometheus.io:9090

Apply this custom resource (CR) using the following command:

$ kubectl apply -f static.yaml
scrapeconfig.monitoring.coreos.com/static-config created

$ kubectl get -A scrapeconfig -n prometheus
NAMESPACE    NAME            AGE
prometheus   static-config   7m51s

It could take a couple of minutes before reloading the Prometheus configuration automatically.

After a few minutes, by checking the Prometheus targets HTTP interface, you should be able to observe something like this inside the Prometheus User Interface (UI):

Prometheus static target

Generate the configuration for OpenStack

Create a dedicated user inside your Public Cloud project with the Infrastructure Supervisor role:

  1. Log in to the , go to the Public Cloud section, and select your project.
  2. In the left sidebar, click Users & Roles.
  3. Click Add user, fill in a username and optional description, then click Confirm.
  4. Once the user is created, click the ... button next to it and select Edit roles.
  5. Enable the Infrastructure Supervisor role and save.

Create a file openstack_user_password.yaml with the following content:

apiVersion: v1
kind: Secret
metadata:
    name: openstack-user-password
    namespace: prometheus
type: Opaque
stringData:
    password: <user_password>

Apply this secret to your Prometheus namespace inside your Kubernetes cluster with the following command:

kubectl apply -f openstack_user_password.yaml -n prometheus

Retrieve your OpenStack user info from the command-line tool (refer to the Setting OpenStack environment variables guide) for the region you want to scrape.

This example uses the GRA11 region.

To download the OpenRC file, go to Users & Roles in your Public Cloud project, click the ... button next to the user, and select Download OpenStack RC file. In the dialog, choose the region you want to scrape (this example uses GRA11) and confirm the download.

$ source openrc.sh
Enter your OpenStack Password:

$ openstack user show user-xxxxxxx
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| default_project_id  | <project_id>                     |
| description         | Prometheus Operator.             |
| domain_id           | default                          |
| enabled             | True                             |
| id                  | <user_id>                        |
| name                | user-xxxxxxx                     |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

The id is used as userid in the openstack_sd_config.

Create a file named openstack.yaml with the following content:

apiVersion: monitoring.coreos.com/v1alpha1
kind: ScrapeConfig
metadata:
    name: openstack-sd-config
    namespace: prometheus
    labels:
        release: `<release_name>`
spec:
    openstackSDConfigs:
        - role: instance
          # specify the Public Cloud region to scrape
          region: "GRA11"
          identityEndpoint: "https://auth.cloud.ovh.net/v3"
          # userid can be found using the previously exposed command
          userid: "`<user_id>`"
          # password is exposed at user creation and can be reset from the OVHcloud Manager
          password:
              name: openstack-user-password
              key: password
    relabelings:
        # This section is used to keep only IPv4 IPs to avoid double scrape with IPv6
        - sourceLabels: [__address__]
          action: keep
          regex: ^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}:\d{1,5}$
        # This section is to force the listen port of the exporter to 9100
        - sourceLabels: [__address__]
          action: replace
          regex: "(.*)((?::))(?:[0-9]+)$"
          replacement: $1:9100
          targetLabel: __address__

For more information, refer to the official Prometheus documentation.

Apply this CR using the following command:

$ kubectl apply -f openstack.yaml
scrapeconfig.monitoring.coreos.com/openstack-sd-config created

$ kubectl get -A scrapeconfig -n prometheus
NAMESPACE    NAME                  AGE
prometheus   openstack-sd-config   20s
prometheus   static-config         8m7s

It could take a couple of minutes before reloading the Prometheus configuration automatically.

After a few minutes, by checking the Prometheus targets HTTP interface, you should be able to observe something like this inside the Prometheus UI:

Prometheus OpenStack targets

Generate the configuration for OVHcloud VPS

Create dedicated script credentials (as described here). Follow our First steps with the OVHcloud APIs tutorial to generate them via the , then note the application key, application secret, and consumer key — you will need them in the next step.

Warning

Important information:

This subject is not covered in this tutorial but you should restrict the API routes the token has access to.

Create a file named ovhcloud_api_credentials.yaml containing your API secrets:

apiVersion: v1
kind: Secret
metadata:
    name: ovhcloud-api-credentials
    namespace: prometheus
type: Opaque
stringData:
    consumerKey: xxxxxxxxxxxxxxxxxxxxxxxxx
    applicationSecret: xxxxxxxxxxxxxxxxxxxxxxxxxx

Apply this secret to your Prometheus namespace inside your Kubernetes cluster with the following command:

kubectl apply -f ovhcloud_api_credentials.yaml -n prometheus

Create a file named ovhcloud.yaml with the following content:

apiVersion: monitoring.coreos.com/v1alpha1
kind: ScrapeConfig
metadata:
    name: ovhcloud
    namespace: prometheus
    labels:
        release: `<release_name>`
spec:
    ovhcloudSDConfigs:
        - applicationKey: "xxxxxxxxxxxxxxxx"
          applicationSecret:
              name: ovhcloud-api-credentials
              key: applicationSecret
          consumerKey:
              name: ovhcloud-api-credentials
              key: consumerKey
          service: "VPS"
          endpoint: "ovh-eu"
    relabelings:
        - sourceLabels: [__address__]
          action: replace
          regex: ([^:]+)(?::\d+)?
          replacement: $1:9100
          targetLabel: __address__

For more information, please refer to the official Prometheus documentation.

Apply this CR using the following command:

$ kubectl apply -f ovhcloud.yaml
scrapeconfig.monitoring.coreos.com/ovhcloud created

$ kubectl get -A scrapeconfig -n prometheus
NAMESPACE    NAME                  AGE
prometheus   openstack-sd-config   6m44s
prometheus   ovhcloud              14s
prometheus   static-config         14m

It could take a couple of minutes before reloading the Prometheus configuration automatically.

After a few minutes, by checking the Prometheus targets HTTP interface, you should be able to observe something like this inside the Prometheus UI:

Prometheus OVHcloud targets

Go further

For more information, please read the following links

For training or technical assistance implementing our solutions, contact your sales representative or visit our Professional Services page to request a quote and have your project analysed by our experts.

Join our community of users.

Questa pagina ti è stata utile?