Using ELK to get Jenkins build data from logs - jenkins

I currently am using filebeat to ship my Jenkins build log from /var/log/jenkins.
I grok the build logs with Logstash so I can display the success/fail etc in Kibana and make some dashboard --> this is working well.
One thing I cannot seem to get is the total build times for the job as a whole.
I am using pipeline and multi pipeline build job types.
I can see the build stage time totals in the console logs but no matter the logging level I set globally for Jenkins, these do not display in the logs.
Has anyone managed to get this right?
Thanks

We have been using this Jenkins logstash-plugin https://wiki.jenkins.io/display/JENKINS/Logstash+Plugin
successfully to stash the data from Jenkins jobs to elasticsearch.
Supported indexers by this plugins are available in this link
https://wiki.jenkins.io/display/JENKINS/Logstash+Plugin#LogstashPlugin-IndexersCurrentlySupported
We are using the elasticsearch indexer which stashes the data directly to elasticsearch but if you want your data to go via logstash you can use Logstash indexer.
The payload format for the data is as below
https://wiki.jenkins.io/display/JENKINS/Logstash+Plugin#LogstashPlugin-JSONPayloadFormat

Related

Configure fluentd to pick Jenkins job/application logs in a kubernetes cluster

I have a kubernetes cluster in which I have jenkins and spinnaker pods up and running. I need to implement a logging mechanism which collects and sends logs to splunk server. I chose to do so using fluentd. I have deployed a daemon set of fluentd to run on each node and collect logs from each node and send to splunk server.
It is working fine for logs that we see using "kubectl logs" or logs that come to stdout. However, I need to pick logs from a jenkins job (Console output of a jenkins job build). These logs are not going to std out of the node, and are stored at /var/jenkins_home/jobs/XXX/builds/<buildno> inside the container storage which is not directly accessible to fluentd for log collection.
I am open for any kind of solution to this problem. Please suggest.
Fluentd dont have any feature like this in case of kubernetes as kubernetes will not allow direct access to any third party plugin to read the data from container. For STDOUT log also first processed by kubernetes and kept at node level. After that you will be able to see.
As a workaround you can follow below link.
Kubernetes - How to read logs that are written to files in pods instead of stdout/stderr?
Long way:
Add hostpath directory volume to a jenkins deployment:
https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
Run a separate FluentBit/Fluentd to collect logs from that directory.
Both of them support putting path in a dedicated field in a log or to a tag:
https://docs.fluentbit.io/manual/pipeline/inputs/tail
Use path/tag to parse-out job name and organize the destination storage accordingly. Or just leave it as is and filter on the view.
Short way:
Use jenkins kubernetes plugin to run each job as a separate pod:
https://plugins.jenkins.io/kubernetes/.
Then it will get collected and tagged by a daemonset separately.
Regarding Cloud Native Jenkins log management
Pipeline Log Storage API and reference implementations are available for preview, only Jenkins Pipeline job types are supported. Related JEP: JEP-210. Available plugins are AWS CloudWatch and Elasticsearch
Jenkins core APIs and reference implementations have not been merged/released yet, but prototypes are available for evaluation. Related JEPs: JEP-207, JEP-212. Available plugins are External Logging API and Elasticsearch
Reference: https://www.jenkins.io/sigs/cloud-native/pluggable-storage/

Jenkins Prometheus plugin not generating any data

I have Jenkins running at https://jenkins.example.com:8443. We installed the Prometheus plugin and restarted the instance with no issues.
When browsing to https://jenkins.example.com:8443/prometheus/ I get a 200 but no data is generated. Left the page open and no data generated more than an hour later, restarted the instance, still just a blank page. I have installed the Prometheus plugin on a bunch of other instances with the same exact setup and configuration and those have no issues. Running Jenkins ver. 2.164.1 with Prometheus 2.0.6. I tried setting up logging for the plugin but not seeing any logs being generated either. The Prometheus config has the Jenkins instance configured in the scrape and Jenkins target is up in the targets page of the Prometheus UI. But again, no data is being generated.
Plugin documentation is here: https://plugins.jenkins.io/prometheus/
Try to generate Access Keys in the metrics section and access the url https://jenkins_ipaddres:portnumber/metrics/accesskey you would now be able to view the metrics.
Path to generate the Access Keys:
Jenkins > Manage Jenkins > Configure Systems > Metrics >> Add >> Generate >> Save
Thanks

Issue in displaying Jenkins build data to influxDB

I am facing some issues in fetching Jenkins build data into influxDB. Actually, the main requirement is to show Jenkins job build results on Grafana dashboard. So, I have created a Jenkins freestyle job and also installed influxDB plugin(1.17) and then I executed Windows batch command (as I am using a Windows 7 machine). it throws nullpointerexception. Please let me know what i need to do.
Images are given below.
configure InfluxDB details
Configure job
Build Configure Job
Build Outputlog

Jenkins - How to get test results?

I'm trying to create the following scenario:
One instance running Jenkins server. It polls repo and if change occurs it spins up a production instance of my app - let's code name this instance APP_INSTANCE. NOTE: this APP_INSTANCE is NOT a Jenkins slave in any way. It is literally the production server of a web application. No Jenkins stuff installed.
Jenkins passes some configs to APP_INSTANCE like BRANCH_NAME.
APP_INSTANCE checks out BRANCH_NAME and runs test suites.
Jenkins polls APP_INSTANCE via ssh to see when test report file is done being generated.
If Jenkins finds test report file, it assumes tests are done and it copies test report file.
This last part is the part I'm stuck on, how to make Jenkins:
1. copy a file from APP_INSTANCE
2. parse it for test results so it can display them in its web interface. (I assume the test report format has to be jUnit or some sht, right?)
So am I dumb for trying to build this?
P.S. I'm using AWS and this is all happening in the cloud.
Try this plugin.
https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs
And read this:
Setup Jenkins to monitor external job

Automatic jenkins master discovery and monitoring using nagios

I want a way to automatically discover Jenkins master servers and automatically monitor the health of the jobs on those Jenkins master servers so that I can look at a single console(using nagios host) to detect issues when a job is failing anywhere in integration.
Could someone help me out to finding Jenkins master servers using nagios?
There's a nagios plugin for retrieving job health information from Jenkins, but it looks like it requires manual configuration for each job, see Nagios Jenkins plugin.
I'm not familiar enough with nagios to know how any built-in auto-discovery works, but it looks like there are several example scripts (check_find_new_hosts and device discovery) for generating the necessary configuration from a network scan. You'll have to do some work to integrate the results of the scan into your nagios instance. (IIRC, you need to restart nagios after writing new configuration?)
To get the list of Jenkins servers, you can build on one of the existing network scan scripts for nagios. The script should scan an IP range and identify devices that respond to http://IP:8080/api/xml. The resulting XML document (JSON results are also supported) should contain a root tag named <hudson> (in my instance, maybe this will change to "jenkins" in a future release). If the server responds to this request, then you'll want your script to generate the nagios configuration for monitoring it.
In addition, the XML response will contain a list of jobs, like:
<job>
<name>My Job</name>
<url>http://jenkins:8080/job/My%20job/</url>
<color>blue</color>
</job>
By iterating through this list, you get the job names, job urls (for more details or polling for status), and the current statuses (blue means success). This list of jobs can provide input to the Nagios Jenkins plugin configuration.
The Jenkins Remote API is documented on your Jenkins instance, just go to http://jenkins:8080/api.

Resources