Search code examples
javajenkinsmonitoringmetricsprometheus

Working with jenkins prometheus plugin


I have Jenkins in https://jenkins.example.com. Plugin working witn 2 env. variables:

PROMETHEUS_ENDPOINT Configures rest endpoint. Defaults to "prometheus" PROMETHEUS_NAMESPACE Configure prometheus metric namespace. Defaults to "default"

I need the metrics to be sent to https://jenkins.example.com/metrics

What PROMETHEUS_ENDPOINT and PROMETHEUS_NAMESPACE values?

Plugin documentation


Solution

  • Shortly: You actually don't need to edit this values. if you wish so you can configure them on:

    Jenkins -> Manage Jenkins -> Configure System -> Promethues (section)

    In short PROMETHEUS_ENDPOINT using the GET Http request in order to get the index page of the jenkins metrics - https://<your-jenkins-path>/prometheus

    Useful / Golden Tips for using jenkins prometheus plugin:

    1. set parameter Enable authentication for prometheus end-point to true and you'll be able to get information about internal processes and jobs running on your jenkins endpoint.

    2. create User account on jenkins dedicated to prometheus monitoring, create a token for authentication.

    3. set screen privileges permissions for viewing jenkins metrics for this user:

    For Enabling Metrics permission:

    Managing jenkins -> Manage and assign roles -> Manage Roles -> Metrics (set view and health-check to true).

    For Assign this permission to specific user: (your prometheus user) -

    Managing jenkins -> Manage and assign roles -> Assign Roles -> find your user and add screen permission.

    1. Configure this credentials on prometheus.yml in your prometheus stack. I'm attaching example for this, this pattern works for me:
    - job_name: 'jenkins'
    metrics_path: /prometheus
    scheme: http
    tls_config:
      insecure_skip_verify: true
    static_configs:
      - targets: ['company.jenkins.com:8080']
    basic_auth:
      username: '[email protected]'
      password: 'abc123'
    
    1. In order to test this is actual works use curl for perform http request the plugin api and integration for jenkins. curl -u user:token jenkinsURL:port/prometheus/

    for example:

    curl -u [email protected]:abc123 company.jenkins.com:8080/prometheus/
    
    1. For testing your integration with prometheus, go to your http://yourPrometheusURL.com:9090/targets and make sure your endpoint is up. you should get the metrics and start using it. Good Luck.