How to Monitor Jenkins Performance with the help of Prometheus and Grafana
- Launch 1 EC2 instance with t2.medium with Ubuntu OS and open port 8080,9090,3000 where 8080=Jenkins, 9090=Prometheus & 3000=Grafana
- After Launch Instance Connect it and update before start
apt-get update
3. After Updating first check is java in installed on your vm if yes you can skip this step if not let’s install Java version 17 because java-11 not support to Jenkins now
apt install openjdk-17-jre-headless
4. After Installing Java let’s begin Installation of Jenkins first we add or download Jenkins key
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
5. You can see my Jenkins running now, for accessing jenkins open port 8080 in AWS SG group and copy public ip of instance and hit with port 8080
6. to login further see the /var/lib/jenkins/secrets/initialAdminPassword file for an initial password
cat /var/lib/jenkins/secrets/initialAdminPassword
7. After paste the password click on continue and then install “Suggested Plugin”
8. Now fill the user details as you want and keep url same
9. and finally click on “Start using Jenkins”
10. Now lets install Prometheus and Grafana quickly
##################Prometheus############################
#Download the latest version of Prometheus using the following command:
wget https://github.com/prometheus/prometheus/releases/download/v2.30.0/prometheus-2.30.0.linux-amd64.tar.gz
#Extract the downloaded archive:
tar xvfz prometheus-2.30.0.linux-amd64.tar.gz
#Move into the extracted directory:
cd prometheus-2.30.0.linux-amd64
11. After Installing lets create a service of Prometheus
cd /etc/systemd/system/
sudo vi prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/path/to/prometheus --config.file=/path/to/prometheus.yml
Restart=always
[Install]
WantedBy=default.target
12. After save this file reload the daemon service to verify our configuration file is correct and also enable and start the Prometheus service
sudo systemctl daemon-reload
sudo systemctl enable prometheus.service
sudo systemctl start prometheus.service
sudo systemctl status prometheus.service
13. If all things work fine you will see you service is running properly and after that copy the Public IP of your Instance and hit with port 9090 “PublicIP:9090” you will see Prometheus UI
14. After Successfully installing Prometheus lets install Grafana also
#####################Grafana############################\
#Import the GPG key used by the Grafana package:
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
#Add the Grafana repository to the APT sources:
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
#Update the package lists:
sudo apt update
#Install Grafana:
sudo apt install grafana
#Start the Grafana service:
sudo systemctl start grafana-server
#Enable the Grafana service to start on system boot:
sudo systemctl enable grafana-server
15. If all things work fine you will see you service is running properly and after that copy the Public IP of your Instance and hit with port 3000 “PublicIP:3000” you will see Grafana UI (Note: While Installing Grafana if you see any “Warning” you can ignore it)
16. The Initial Username and Password for Grafana is “admin/admin” after login you can change it.
17. Now lets create a sample job for that click on “New Item” then Give the name select “FreeStyle Project” and save
18. Choose “Source Code Management” as “Git” and give following Git URL i.e. Opensource
https://github.com/shrihariharidass/Simple-DevOps-Project.git
19. & then “Apply & Save” run the job now for that click on “Build Now” button
20. As you can see my build was successful that means my job run now let’s go to monitor part of Jenkins
21. So go to “Mange Jenkins” and then go to “Plugins” option open that and Search of “Metrics Plugin”, ”Prometheus Metrics” & “Disk Usage Simple” and install it & restart Jenkins Once.
22. After restarting Jenkins PublicIP:8080 use metrics path as follows and you will see metrics of Jenkins
PublicIP:8080/prometheus
23. Now Open “Prometheus.yml” file where Prometheus you install and change same configuration and add below one for Jenkins
- job_name: "Jenkins Job"
metrics_path: /prometheus/
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["Public Ip:8080"]
24. Save this file and restart Prometheus service and after restarting go again Prometheus and check in targets is our job is up or not
25. Now go to grafana and add data source as “Prometheus” & give Prometheus IP:9090
26. Now scroll down and click on “Save & Test” after that click on “Import Dashboard” option
27. And then Paste Dashboard number as “9964” as its Jenkins Dashboard and click on load, select source as Prometheus and click on “Import”
28. And here you can see the Final Output