Enabling Prometheus Metrics in Harbor Project

  ·   3 min read

Harbor is an open-source container image registry that provides various features such as vulnerability scanning, role-based access control, and image replication. As with any critical infrastructure component, monitoring is essential to ensure its smooth operation. Prometheus is a popular open-source monitoring and alerting toolkit that can be integrated with Harbor to collect and visualize metrics. In this article, we will explore how to enable Prometheus metrics in the Harbor project.

Prerequisites

Before we begin, ensure you have the following prerequisites:

  1. Harbor Installation: You should have a running instance of Harbor. This can be deployed on a Kubernetes cluster or as a standalone Docker Compose setup.
  2. Prometheus: A running instance of Prometheus to scrape metrics from Harbor.
  3. Access to Harbor Configuration: Ensure you have access to modify Harbor’s configuration files.

Step-by-Step Guide

Step 1: Enable Metrics in Harbor

Harbor provides a built-in metrics endpoint that can be exposed to Prometheus. To enable this, follow these steps:

  1. Locate the Harbor Configuration File: Depending on your deployment method, this could be a harbor.yml file or a Kubernetes ConfigMap.

  2. Modify the Configuration: Add or modify the following section in your configuration file to enable metrics:

    metrics:
      enabled: true
      port: 9090
    

    This configuration enables the metrics endpoint and sets it to listen on port 9090.

  3. Restart Harbor: After making changes to the configuration, restart your Harbor services to apply the changes. For Docker Compose, this can be done using:

    docker-compose down
    docker-compose up -d
    

    For Kubernetes, apply the updated ConfigMap and restart the pods.

Step 2: Configure Prometheus to Scrape Harbor Metrics

Now that Harbor is exposing metrics, configure Prometheus to scrape these metrics:

  1. Edit Prometheus Configuration: Locate your Prometheus configuration file, typically named prometheus.yml.

  2. Add a New Scrape Job: Add a new job under the scrape_configs section to scrape metrics from Harbor:

    scrape_configs:
      - job_name: 'harbor'
        static_configs:
          - targets: ['<harbor-host>:9090']
    

    Replace <harbor-host> with the actual hostname or IP address of your Harbor instance.

  3. Reload Prometheus Configuration: After updating the configuration, reload Prometheus to apply the changes. This can be done by sending a SIGHUP signal to the Prometheus process or using the Prometheus web interface.

Step 3: Verify Metrics Collection

To verify that Prometheus is successfully scraping metrics from Harbor:

  1. Access Prometheus UI: Open the Prometheus web interface in your browser.

  2. Check Targets: Navigate to the “Targets” page to see if the Harbor target is listed and in the “UP” state.

  3. Query Metrics: Use the Prometheus query interface to explore available metrics. For example, you can query harbor_up to check the status of the Harbor instance.

Conclusion

By following these steps, you have successfully enabled Prometheus metrics in your Harbor project. This integration allows you to monitor the health and performance of your Harbor instance, providing valuable insights and enabling proactive management. For further customization, consider integrating Grafana to visualize these metrics in a more user-friendly manner.

References