Uptime-Kuma is an open-source, self-hosted monitoring tool with a user-friendly interface designed to track the uptime of websites, services, and APIs. When integrated into a CI/CD pipeline for a blog, it becomes an essential part of ensuring continuous availability and performance monitoring. Here's how Uptime-Kuma can be effectively utilized in this context:
Real-Time Monitoring: Uptime-Kuma can continuously monitor the uptime and performance of the blog's website and APIs, providing instant alerts if any downtime or performance issues are detected. This ensures that any disruptions are quickly addressed.
Integration with CI/CD Pipeline: During the deployment process, Uptime-Kuma can be triggered to perform automated checks on the website and its services, ensuring that all components are functioning properly before and after deployment. This helps in maintaining the reliability of the blog during updates.
Customizable Alerts: Uptime-Kuma allows for setting up customized alerts via various communication channels like email, Slack, or Telegram, ensuring that developers are immediately notified of any issues, enabling quick troubleshooting.
Historical Data and Reports: By tracking the uptime and performance over time, Uptime-Kuma generates valuable historical data. This can be analyzed to identify trends, improve performance, and plan for future infrastructure improvements.
Self-Hosted Solution: Since Uptime-Kuma is self-hosted, it offers full control over the monitoring infrastructure, ensuring data privacy and security while eliminating dependency on third-party monitoring services.
By integrating Uptime-Kuma into the CI/CD pipeline of a blog, you can automate performance checks, ensure smooth deployments, and maintain high availability, ultimately delivering a better user experience.
Step 1. On AWS, Create a ubuntu EC2 instance of t2 large type with storage of 30 gb. Configure Security Group:
Create a new security group.
Set the security group name and description.
Add a rule to allow all traffic (not recommended for production environments):
Type: All Traffic
Protocol: All
Port Range: All
Port Range : 22, 80, 443, 8080, 9000, 3001, 5000
Source: 0.0.0.0/0 (for IPv4) and ::/0 (for IPv6)
EC2 Instance is created.
Connect to EC2 instance.
Step2. Install jenkins, docker and trivy.
sudo apt update
Installed Jenkins
vim script1.sh
#!/bin/bash
sudo apt update -y
wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /etc/apt/keyrings/adoptium.asc
echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
sudo apt update -y
sudo apt install temurin-17-jdk -y
/usr/bin/java --version
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 -y
sudo apt-get install jenkins -y
sudo systemctl start jenkins
sudo systemctl status jenkins
Give executable permissions to script1.sh file.
sudo chmod 777 jenkins.sh
sudo su #move into root and run
./script1.sh # this will installl jenkins
jenkins is up and running.
Now, grab your Public IP Address. 8080 port is use for jenkins.
<EC2 Public IP Address:8080>
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Unlock Jenkins using an administrative password and install the suggested plugins.
jenkins and libraries are installed.
Install Docker
vim script2.sh
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
sudo usermod -aG docker ubuntu
newgrp docker
sudo chmod 777 /var/run/docker.sock
chmod 777 script2.sh
give execution permissions to script2.sh
sh script2.sh
After the docker installation, we create a sonarqube container, add 9000 ports in the security group.
sudo chmod 777 /var/run/docker.sock
docker run -d --name sonar -p 9000:9000 sonarqube:lts-community
Now Sonarqube container is up and running.
Install Trivy
vim script3.sh
sudo apt-get install wget apt-transport-https gnupg lsb-release -y
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy -y
Give permissions and run script.
sudo chmod 777 script3.sh
sh script3.sh
trivy --version
Next, we will log in to Jenkins and start to configure our Pipeline in Jenkins
Step3. Install Plugins on jenkins
Goto Manage Jenkins →Plugins → Available Plugins →
Install below plugins
Blue ocean
1 → Eclipse Temurin Installer
2 → SonarQube Scanner
3 → NodeJs Plugin
4 → Docker
5 → Docker commons
6 → Docker pipeline
7 → Docker API
8 → Docker Build step
9 → Owasp Dependency Check
Step4. Configure Java , sonar-scanner, Nodejs , dependency-check and docker in Global Tool Configuration.
Goto Manage Jenkins → Tools → Install JDK(17)
Sonar-scanner
Nodejs
Dependency-Check installations
Docker
Apply and save.
Step5. Go to sonarqube.
Click on Administration → Security → Users → Click on Tokens and Update Token → Give it a name → and click on Generate Token.
Select user -> update token
Copy token. squ_43197e8b2c48ab75f29699313fa13a6a9a86198c
Step 6. Go to Jenkins
Dashboard → Manage Jenkins → Credentials → Add Secret Text.
Now, go to Dashboard → Manage Jenkins → System and Add like the below image.
Search for SonarQube Installation
Click on Apply and Save
The Configure System option is used in Jenkins to configure different server
Global Tool Configuration is used to configure different tools that we install using Plugins.
For pushing image to docker hub we need dockerHub credentials. Go to Jenkins Dashboard → Manage Jenkins → Credentials → username and password.
Step 7. In the Sonarqube Dashboard add a quality gate also
Administration–> Configuration–>Webhooks
Step8. Create Job for Uptime-kuma on jenkins
Write this stage to Pipeline Script. go to Dashboard-> create a job.
pipeline {
agent any
tools {
jdk 'jdk17'
nodejs 'node18'
}
environment {
SCANNER_HOME = tool name: 'sonar-scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
}
stages {
stage('Checkout from Git') {
steps {
git branch: 'main', url: 'https://github.com/Pardeep32/Uptime-kuma.git'
}
}
stage('Install Dependencies') {
steps {
sh "npm install"
}
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('sonar-server') {
sh '''
$SCANNER_HOME/bin/sonar-scanner \
-Dsonar.projectName=uptime \
-Dsonar.projectKey=uptime
'''
}
}
}
stage('Quality Gate') {
steps {
script {
def qualityGate = waitForQualityGate()
if (qualityGate.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qualityGate.status}"
}
}
}
}
stage('OWASP Dependency Check') {
steps {
dependencyCheck additionalArguments: '--scan ./ --disableYarnAudit --disableNodeAudit', odcInstallation: 'DP-Check'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
stage('Trivy File System Scan') {
steps {
sh "trivy fs . > trivyfs.json"
}
}
stage('Docker Build & Push') {
steps {
script {
withDockerRegistry(credentialsId: 'docker', toolName: 'docker') {
sh "docker build -t uptime ."
sh "docker tag uptime pardeepkaur/uptime:latest"
sh "docker push pardeepkaur/uptime:latest"
}
}
}
}
stage('Trivy Image Scan') {
steps {
sh "trivy image pardeepkaur/uptime:latest > trivy.json"
}
}
stage('Remove Existing Container') {
steps {
sh "docker stop uptime || true"
sh "docker rm uptime || true"
}
}
stage('Deploy to Container') {
steps {
sh 'docker run -d --name uptime -v /var/run/docker.sock:/var/run/docker.sock -p 3001:3001 pardeepkaur/uptime:latest'
}
}
}
}
apply and save the pipeline.
Step 9 :Go to github -> settings -> webhook
Select add webhook - Public_ipaddress_of_EC2:8080/github-webhook/
webhook is active.
On jenkins where job is created, Select Build Now. It will build pipeline.
Different stages of pipeline
Output:
Tool installed
Git checkuot
NPM Install
SonarQube Analysis
Quality gate
OWASP Dependency check
Trivy file scan
Docker build and push
Image is push to dockerhub using dockerhub credentials that are inserted in global configuration if jenkins.
Trivy image scan and deploy to docker.
Deploy to container
Output on http://35.183.131.139:3001/
add new monitor:
Step10. Create an account on twilio.
You will get Account SID and Auth Token.
Step 10. Twilio webhook setup
clone the git repo on server and update these values in app.py
git clone https://github.com/Aj7Ay/Uptime-kuma.git
cd Uptime-kuma
cd Webhook
Update the app.py
add account_sid, auth_token and numbers to call
Now install These on Server
sudo apt install python3-pip
sudo apt install python3.12-venv
python3 -m venv venv
source venv/bin/activate
Now install Requirements
pip install -r requirements.txt
cd Uptime-kuma/webhook
docker build -t webhook .
docker run -d --name webhook -p 5000:5000 webhook:latest
Step 11. Go to uptime kuma and add new monitor
go to profile -> settings -> notification
my sonar conatiner is up and running
stop docker sonar container
again start the conatiner.
when server was down i got a call on my phone number that i mentioned above.
Thank you for reading my article! If you have any questions or concerns, feel free to reach out to me at pardeep17.kp@gmail.com. I'm happy to help!