Giter Club home page Giter Club logo

jenkins_exporter's Introduction

Jenkins Exporter

Build Status

Jenkins exporter for prometheus.io, written in python.

This exporter is based on Robust Perception's python exporter example: For more information see (http://www.robustperception.io/writing-a-jenkins-exporter-in-python)

Usage

jenkins_exporter.py [-h] [-j jenkins] [--user user] [-k]
                    [--password password] [-p port]

optional arguments:
  -h, --help            show this help message and exit
  -j jenkins, --jenkins jenkins
                        server url from the jenkins api
  --user user           jenkins api user
  --password password   jenkins api password
  -p port, --port port  Listen to this port
  -k, --insecure        Allow connection to insecure Jenkins API

Example

docker run -d -p 9118:9118 lovoo/jenkins_exporter:latest -j http://jenkins:8080 -p 9118

Installation

git clone [email protected]:lovoo/jenkins_exporter.git
cd jenkins_exporter
pip install -r requirements.txt

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

jenkins_exporter's People

Contributors

andel7 avatar bryanlarsen avatar fhemberger avatar joppa27 avatar joprice avatar jtilander avatar sengaya avatar sqisch avatar vanesa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jenkins_exporter's Issues

I was searching a way to hide the password not to be in clear text.

Hi,

Any suggestion how will be better to crypt/ hide the password due to security reason not to be visible, because in fact if is an admin user with visibility per all builds and someone see the password could change things in jenkins.
I was seeing bcrypt and passlib but...

Kind Regards,
Florin

error: [Errno 32] Broken pipe

Hey guys,

I have been trying to use this exporter with my Jenkins instance but I keep getting the following error:

----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 39590)
Traceback (most recent call last):
  File "/usr/lib64/python2.7/SocketServer.py", line 593, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib64/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib64/python2.7/SocketServer.py", line 651, in __init__
    self.finish()
  File "/usr/lib64/python2.7/SocketServer.py", line 710, in finish
    self.wfile.close()
  File "/usr/lib64/python2.7/socket.py", line 279, in close
    self.flush()
  File "/usr/lib64/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------

Have you guys addressed this issue in the past? It is a little bit odd because the error is quite inconsistent. The exporter may run fine for a while and then start firing this Exception.

kind regards,
Matteo

KeyError: 'lastBuild'

I'm having the following error using this exporter.

KeyError: 'lastBuild'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/local/lib/python2.7/SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "/usr/local/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.7/SocketServer.py", line 655, in __init__
    self.handle()
  File "/usr/local/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/local/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
    method()
  File "/usr/local/lib/python2.7/site-packages/prometheus_client/exposition.py", line 54, in do_GET
    self.wfile.write(generate_latest(core.REGISTRY))
  File "/usr/local/lib/python2.7/site-packages/prometheus_client/exposition.py", line 33, in generate_latest
    for metric in registry.collect():
  File "/usr/local/lib/python2.7/site-packages/prometheus_client/core.py", line 54, in collect
    for metric in collector.collect():
  File "./jenkins_exporter.py", line 30, in collect
    self._get_metrics(name, job)
  File "./jenkins_exporter.py", line 89, in _get_metrics
    status_data = job[status] or {}

What would it mean?
Thanks

Unable to get Jenkins metrics to Jenkins exporter

Hi

I have my jenkins server running at a remote host, as a pod in kubernetes. I have connected to that server**(10.138.77.67)** through ssh from my host**(10.138.77.242)** and I am accessing the jenkins pod at http://10.138.77.67:30331. I have created sample repository and created jobs to build them in jenkins.

Then, I have cloned the lovoo/jenkins_exporter and ran it using the below command:
./jenkins_exporter.py -j http://10.138.77.67:30331 -p 9118

I am facing the below error:
tcs@tcspoweredge:~/.go/src/github.com/jenkins_exporter$ ./jenkins_exporter.py -j http://10.138.77.67:30331 -p 9118

Serving at port: 9118

Exception happened during processing of request from ('10.138.77.242', 40777)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 649, in init
self.handle()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
self.handle_one_request()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
method()
File "build/bdist.linux-x86_64/egg/prometheus_client/exposition.py", line 76, in do_GET
self.wfile.write(generate_latest(core.REGISTRY))
File "build/bdist.linux-x86_64/egg/prometheus_client/exposition.py", line 55, in generate_latest
for metric in registry.collect():
File "build/bdist.linux-x86_64/egg/prometheus_client/core.py", line 54, in collect
for metric in collector.collect():
File "./jenkins_exporter.py", line 24, in collect
jenkins_data = self._request_data()
File "./jenkins_exporter.py", line 47, in _request_data
raise Exception('Response Status ({0}): {1}'.format(response.status_code, response.text))
Exception: Response Status (403): <script>window.location.replace('/login?from=%2Fapi%2Fjson%3Ftree%3Djobs%255Bname%252ClastBuild%255Bnumber%252Ctimestamp%252Cduration%252Cactions%255BqueuingDurationMillis%252CtotalDurationMillis%252CskipCount%252CfailCount%252CtotalCount%252CpassCount%255D%255D%252ClastCompletedBuild%255Bnumber%252Ctimestamp%252Cduration%252Cactions%255BqueuingDurationMillis%252CtotalDurationMillis%252CskipCount%252CfailCount%252CtotalCount%252CpassCount%255D%255D%252ClastFailedBuild%255Bnumber%252Ctimestamp%252Cduration%252Cactions%255BqueuingDurationMillis%252CtotalDurationMillis%252CskipCount%252CfailCount%252CtotalCount%252CpassCount%255D%255D%252ClastStableBuild%255Bnumber%252Ctimestamp%252Cduration%252Cactions%255BqueuingDurationMillis%252CtotalDurationMillis%252CskipCount%252CfailCount%252CtotalCount%252CpassCount%255D%255D%252ClastSuccessfulBuild%255Bnumber%252Ctimestamp%252Cduration%252Cactions%255BqueuingDurationMillis%252CtotalDurationMillis%252CskipCount%252CfailCount%252CtotalCount%252CpassCount%255D%255D%252ClastUnstableBuild%255Bnumber%252Ctimestamp%252Cduration%252Cactions%255BqueuingDurationMillis%252CtotalDurationMillis%252CskipCount%252CfailCount%252CtotalCount%252CpassCount%255D%255D%252ClastUnsuccessfulBuild%255Bnumber%252Ctimestamp%252Cduration%252Cactions%255BqueuingDurationMillis%252CtotalDurationMillis%252CskipCount%252CfailCount%252CtotalCount%252CpassCount%255D%255D%255D');</script>

Authentication required


I have configured proxy setting in jenkins and from the logs I see that it is trying to connect to my host IP i.e 10.138.77.242(not sure why).
Also, I am able to open http://10.138.77.67:9118 but a blank page is seen without any jenkins metrics.

I am not sure as to where I made a mistake. Can someone help.

Failed and print "unknown protocol" when Jenkins is using https

I got this error when I start jenkins_exporter.py:
requests.exceptions.SSLError: HTTPSConnectionPool(host='10.7.240.14', port=31296): Max retries exceeded with url: /api/json?tree=jobs%5BfullName%2Curl%2ClastBuild%5BfullName%2Cnumber%2Ctimestamp%2Cduration%2Cactions%5BqueuingDurationMillis%2CtotalDurationMillis%2CskipCount%2CfailCount%2CtotalCount%2CpassCount%5D%5D%2ClastCompletedBuild%5BfullName%2Cnumber%2Ctimestamp%2Cduration%2Cactions%5BqueuingDurationMillis%2CtotalDurationMillis%2CskipCount%2CfailCount%2CtotalCount%2CpassCount%5D%5D%2ClastFailedBuild%5BfullName%2Cnumber%2Ctimestamp%2Cduration%2Cactions%5BqueuingDurationMillis%2CtotalDurationMillis%2CskipCount%2CfailCount%2CtotalCount%2CpassCount%5D%5D%2ClastStableBuild%5BfullName%2Cnumber%2Ctimestamp%2Cduration%2Cactions%5BqueuingDurationMillis%2CtotalDurationMillis%2CskipCount%2CfailCount%2CtotalCount%2CpassCount%5D%5D%2ClastSuccessfulBuild%5BfullName%2Cnumber%2Ctimestamp%2Cduration%2Cactions%5BqueuingDurationMillis%2CtotalDurationMillis%2CskipCount%2CfailCount%2CtotalCount%2CpassCount%5D%5D%2ClastUnstableBuild%5BfullName%2Cnumber%2Ctimestamp%2Cduration%2Cactions%5BqueuingDurationMillis%2CtotalDurationMillis%2CskipCount%2CfailCount%2CtotalCount%2CpassCount%5D%5D%2ClastUnsuccessfulBuild%5BfullName%2Cnumber%2Ctimestamp%2Cduration%2Cactions%5BqueuingDurationMillis%2CtotalDurationMillis%2CskipCount%2CfailCount%2CtotalCount%2CpassCount%5D%5D%5D (Caused by SSLError(SSLError(1, u'[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:618)'),))

Python version: 2.7.5
System: centos 7
Jenkins Version: 2.121.3
requests version: 2.18.4
prometheus-client version: 0.6.0

Authentication does not work.

Hi,

We are using jenkin_exporter directly with python and we are trying to authenticate, but it does not seems to work.

We are using it with basic auth in the url, but it gives 403.
python -u jenkins_exporter.py -j https://user:[email protected] -p 9118

If we give it throught the args (--user --password) it freeze, and does nothing.
python -u jenkins_exporter.py -j https://url.com -p 9118 --user user --password password

How does the athentication works? the server must have a special configuration?

Bye

How to make dashbard in Grafana?

There is a Jenkins dashboard here: https://grafana.com/dashboards/306
However it does not seem to work with this plugin. Are there any docs as to what names / metrics are used and how to configure Grafana for this?

I can locally run curl 127.0.0.1:9118 and get a dump, but have no idea what / why the output is:

...
# HELP jenkins_job_last_unstable_build Jenkins build number for lastUnstableBuild
# TYPE jenkins_job_last_unstable_build gauge
# HELP jenkins_job_last_unsuccessful_build_fail_count Jenkins build fail counts for lastUnsuccessfulBuild
# TYPE jenkins_job_last_unsuccessful_build_fail_count gauge
# HELP jenkins_job_last_unsuccessful_build_total_count Jenkins build total counts for lastUnsuccessfulBuild
# TYPE jenkins_job_last_unsuccessful_build_total_count gauge
# HELP jenkins_job_last_unsuccessful_build_skip_count Jenkins build skip counts for lastUnsuccessfulBuild
# TYPE jenkins_job_last_unsuccessful_build_skip_count gauge
# HELP jenkins_job_last_unsuccessful_build_queuing_duration_seconds Jenkins build queuing duration in seconds for lastUnsuccessfulBuild
# TYPE jenkins_job_last_unsuccessful_build_queuing_duration_seconds gauge
# HELP jenkins_job_last_unsuccessful_build_duration_seconds Jenkins build duration in seconds for lastUnsuccessfulBuild
# TYPE jenkins_job_last_unsuccessful_build_duration_seconds gauge
...

Promtools gives warning for metrics names.

(envVar23) λ curl --noproxy "*" http://localhost:9118|promtool check metrics
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 27065    0 27065    0     0  36873      0 --:--:-- --:--:-- --:--:-- 36873
jenkins_job_last_build_fail_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_build_pass_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_build_skip_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_build_total_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_completed_build_fail_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_completed_build_pass_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_completed_build_skip_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_completed_build_total_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_failed_build_fail_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_failed_build_pass_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_failed_build_skip_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_failed_build_total_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_stable_build_pass_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_stable_build_skip_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_stable_build_total_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_successful_build_fail_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_successful_build_pass_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_successful_build_skip_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_successful_build_total_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_unstable_build_fail_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_unstable_build_pass_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_unstable_build_skip_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_unstable_build_total_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_unsuccessful_build_fail_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_unsuccessful_build_pass_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_unsuccessful_build_skip_count non-histogram and non-summary metrics should not have "_count" suffix
jenkins_job_last_unsuccessful_build_total_count non-histogram and non-summary metrics should not have "_count" suffix

Jenkins builds seems stagnant over time

We're demoing this tool right now, but I'm understanding this tool wrong, or something about the output is incorrect.

Checking (roughly) the number of current jobs on our jenkins server:

[jenkins-server jobs]# ls -lA */builds | grep -v ^l | wc -l
28220

Versus the output from the tool:

Screen Shot 2019-03-11 at 3 49 00 PM

Where the number is at a constant 12K and almost never updates.

We're on the latest version of this tool, and using Jenkins 2.164.

We recycle old jobs from time to time, but even the number of jobs we currently have is much higher than what is showing up in Prometheus. Build count should be much higher regardless.

Jenkins Exporter fails if one of the statuses is not present

If we create a brand new pipeline in jenkins and try to run the exporter it fails. This is because none of the statuses are currently part of job data returned by jenkins. I hit the following failure in one of use cases
Exception happened during processing of request from ('127.0.0.1', 46385)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 649, in init
self.handle()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
self.handle_one_request()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
method()
File "build/bdist.linux-x86_64/egg/prometheus_client/exposition.py", line 76, in do_GET
self.wfile.write(generate_latest(core.REGISTRY))
File "build/bdist.linux-x86_64/egg/prometheus_client/exposition.py", line 55, in generate_latest
for metric in registry.collect():
File "build/bdist.linux-x86_64/egg/prometheus_client/core.py", line 54, in collect
for metric in collector.collect():
File "jenkins_exporter.py", line 34, in collect
self._get_metrics(name, job)
File "jenkins_exporter.py", line 94, in _get_metrics
status_data = job[status] or {}
KeyError: 'lastBuild'

A simple one liner can fix this up, if you are fine I can generate a pull request.

fix: In _get_metrics just adding this fixes the issue
if status in job.keys():

Feature Request for the Exporter

Hi,

It is possible to have extra information collected with this exporter?
I've used and created Dashboard also with the information collected from the exporter and there is room for improvement.

Main key statistics needed for a decent monitoring are:

Jenkins master status/ health, version of jenkins, maybe the plugins (number, name, versions) or some statistics.
For Build: health/ status, result code, duration of build, state, version and also if possible a tag where we can collect per build the real version of soft deployed (e.g if I deploy a component from a pipeline and I know that the release will be R1M2P3 for example as name, I will want to extract this field also), the build number from jenkins helps but is not related to the build version itself from software point of view.
For Pipeline: stage view from jenkins, pipeline duration build, state, health, status, percent of success/ build for pipelines, also to see the tag per build of software release version, etc.

Let me know what do you think.
Kind Regards,

Jenkins all jobs listing

Hello Team,
How can i get the information for jobs which is inside folders, using this exporter I am not able to find.

Adding some of the common prometheus metrices

Hello,

Is it possible to consider adding some of the common prometheus metrics like 1) scrape_count
and 2) scrape_error to jenkins exporter. These metrics are usually available in all the prometheus exporter.

Regards
Ashish

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.