Configure Prometheus to scrape MSR metrics

To collect MSR metrics, you must install a Prometheus server on your MSR cluster.

Kubernetes deployments

To install a Prometheus server:

  1. Add the Prometheus repository:

    helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    
  2. Update the Prometheus repository:

    helm repo update
    
  3. Obtain the target IP address and port for the msr-api service:

    kubectl get svc
    

    The IP address is listed under CLUSTER-IP and the port is listed under PORT(S).

  4. Create a prometheus-values.yaml file with the following configuration detail:

    extraScrapeConfigs: |
      - job_name: '<metrics-job-name>'
        metrics_path: /api/v0/admin/metrics
        static_configs:
          - targets: ['<msr-api-service-cluster-ip>:<port>']
        basic_auth:
          username: '<user-name>'
          password: '<password>'
        scheme: https
        tls_config:
          <tls-detail>
    

    Note

    For more information on how to fill out this configuration detail, refer to <scrape_config> in the official Prometheus documentation.

    To learn how to generate and add your own certs to MSR, refer to Add a custom TLS certificate.

    Note

    The Helm chart used herein includes the prometheus-node-exporter, which may crash at start up on some local environments.

    To resolve this issue, include the following configuration detail in the prometheus-values.yaml file:

    prometheus-node-exporter:
      hostRootFsMount:
        enabled: false
    
  5. Install the Prometheus server:

    helm install -f prometheus-values.yaml prometheus prometheus-community/prometheus
    

To verify that your Prometheus server is running and scraping the MSR metrics endpoint:

  1. Forward the Prometheus server to port 9090:

    kubectl port-forward `kubectl get pods | grep prometheus-server | tr -s ' ' | cut -d' ' -f1`  9090
    
  2. In a web browser, navigate to http://<prometheus-host>:9090.

  3. Select Status > Targets in the Prometheus UI menu bar.

  4. Verify that the MSR metrics endpoint is listed on the page with the up status.

    The metrics endpoint is labeled with the job-name entered in the extraScrapeConfigs section of the prometheus-values.yaml file.

Swarm deployments

To install a Prometheus server:

  1. SSH into a manager node on your Swarm cluster.

  2. Create a prometheus.yml file that includes the following values:

    scrape_configs:
      - job_name: '<metrics-job-name>'
        metrics_path: /api/v0/admin/metrics
        static_configs:
          - targets: ['msr-api-server:443']
        basic_auth:
          username: '<user-name>'
          password: '<password>'
        scheme: https
        tls_config:
          <tls-detail>
    

    Note

    For more information on how to fill out this configuration detail, refer to <scrape_config> in the official Prometheus documentation.

    To learn how to generate and add your own certs to MSR, refer to Add a custom TLS certificate.

  3. Create the following docker-stack.yaml file to configure a Swarm service for deploying the Prometheus server:

    version: '3.7'
    
    volumes:
      prometheus_data:
    
    services:
      prometheus:
        image: prom/prometheus:v2.45.0
        volumes:
          - ./prometheus.yml:/etc/prometheus/prometheus.yml
          - prometheus_data:/prometheus
        ports:
          - <prometheus-ui-port>:9090
        networks:
          - msr_msr-ol
        deploy:
          placement:
            constraints:
              - node.role==manager
    
    networks:
      msr_msr-ol:
        name: msr_msr-ol
        external: true
    

    Note

    For the <prometheus-ui-port> value in the ports section, select a port that is currently available in your Swarm cluster.

  4. Deploy the Prometheus server onto your Swarm cluster:

    docker stack deploy -c docker-stack.yaml prometheus
    

To verify that your Prometheus server is running and scraping the MSR metrics endpoint:

  1. Verify that your Prometheus service is running:

    docker service ls
    
  2. In a web browser, navigate to http://<manager-node-ip>:<prometheus-ui-port>. This is the same <prometheus-ui-port> that you included in the ports section of the docker-stack.yaml file.

  3. Select Status > Targets in the Prometheus UI menu bar.

  4. Verify that the MSR metrics endpoint is listed on the page with the up status. You may need to wait approximately 30 seconds for this to occur.

    The metrics endpoint is labeled with the <metrics-job-name> entered in the scrape_configs section of the prometheus.yml file.