Skip to content

Commit 2cdfc04

Browse files
committed
chore: improved ci healthcheck functionality testing
1 parent 83c3dfa commit 2cdfc04

File tree

4 files changed

+71
-32
lines changed

4 files changed

+71
-32
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
- 'capture/**'
99
- 'ansible/**'
1010
- 'dashboards/**'
11-
- 'scripts/**'
1211
- '.gitignore'
1312
- 'LICENSE'
1413

.github/workflows/dev.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ on:
1212
- 'capture/**'
1313
- 'ansible/**'
1414
- 'dashboards/**'
15-
- 'scripts/**'
1615
- '.gitignore'
1716
- 'LICENSE'
1817

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 🚀 Container Exporter (CXP)
22

3-
A resource-friendly, highly efficient, and minimal Prometheus exporter to track Memory, CPU, Disk and Network I/O usage of Docker containers along with their lifecycle (up/down) state used for alerting.
4-
5-
Check out the [web page](https://shayan-ghani.github.io/Container-Exporter/) for more information.
3+
A resource-friendly, highly efficient, and minimal Prometheus exporter to track Memory, CPU, Disk and Network I/O usage of Docker containers along with their lifecycle (uptime).
64

75
## Table of Contents
86
1. [DEV STACK](#%EF%B8%8F-dev-stack)
@@ -21,12 +19,12 @@ Check out the [web page](https://shayan-ghani.github.io/Container-Exporter/) for
2119
7. [Contact Information](#contact-information)
2220

2321
## 🛠️ DEV STACK
24-
![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54) ![Flask](https://img.shields.io/badge/fastapi-%23000.svg?style=for-the-badge&logo=fastapi&logoColor=ffdd54) ![Docker](https://img.shields.io/badge/docker-3670A0?style=for-the-badge&logo=docker&logoColor=ffff) ![Prometheus](https://img.shields.io/badge/Prometheus-E6522C?style=for-the-badge&logo=Prometheus&logoColor=white) ![Uvicorn](https://img.shields.io/badge/uvicorn-%298729.svg?style=for-the-badge&logo=uvicorn&logoColor=white)
22+
![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54) ![Flask](https://img.shields.io/badge/flask-%23000.svg?style=for-the-badge&logo=flask&logoColor=ffdd54) ![Docker](https://img.shields.io/badge/docker-3670A0?style=for-the-badge&logo=docker&logoColor=ffff) ![Prometheus](https://img.shields.io/badge/Prometheus-E6522C?style=for-the-badge&logo=Prometheus&logoColor=white) ![Gunicorn](https://img.shields.io/badge/gunicorn-%298729.svg?style=for-the-badge&logo=gunicorn&logoColor=white)
2523

26-
see a sample of the metrics page [here](https://shayan-ghani.github.io/Container-Exporter/metrics.html).
24+
see a sample of the metrics page in [here](./extra/metrics.txt).
2725

2826
## 🎥 DEMO
29-
<img src="https://github.com/Shayan-Ghani/Container-Exporter/blob/media/capture/CXP-DEMO.gif" width="100%" height="50%" />
27+
<img src="https://shayan-ghani.github.io/Container-Exporter/CXP-DEMO.gif" width="100%" height="50%" />
3028

3129

3230
## 📋 Step-by-Step Guide
@@ -115,7 +113,7 @@ PORT="8000" ./start.sh <your custome port> &
115113
### 🔥 Add CXP to Prometheus
116114
- Edit your `prometheus.yml` file and add the address of container-exporter in scrape_configs:
117115

118-
![Prometheus config](https://github.com/Shayan-Ghani/Container-Exporter/blob/media/capture/scrape-config.png "Prometheus configuration file")
116+
![Prometheus config](./capture/scrape-config.png "Prometheus configuration file")
119117

120118
- Reload or restart your Prometheus server and reach out to `http://127.0.0.1:8000/metrics`
121119
### That is it you are good to go, Enjoy Using CXP! "}"
@@ -143,13 +141,11 @@ Check out [dashboards](./dashboards) directory for Json files. including CPU & M
143141
- [x] Network I/O Usage
144142
- [x] Add metrics in units of byte
145143
- [x] Check and Unregister *stat* metrics for containers that are not running
146-
- [x] Design and develop a static website to showcase Documentation, new features, etc.
144+
- [x] Enable functionality and smoke testing in ci
147145
- [ ] Design grafana dashboards and share them on grafana cloud
148-
- [ ] Add unit tests
149-
- [ ] Add `clear_metrics` functionality to switch on clearing the labels or setting them to 0 to maintain time series data, on user's demand.
150-
146+
- [ ] Design and develop a static website to showcase Documentation, new features, etc.
151147
## Contributions
152-
Welcome to CXP! This project is production-ready now, and we encourage contributions to enhance its functionality, optimize code, and add new features
148+
Welcome to CXP! This project is currently in an experimental yet stable version, and we encourage contributions to enhance its functionality, optimize code, and add new features
153149

154150
Feel free to contribute in any wacacy you can. If you come across a bug or have a suggestion, please don't hesitate to file an issue. Your input is valuable and helps us improve CXP for everyone; Therefore, add any desired function or feature to TO DO section. We appreciate your contribution to making CXP even better! If you have any questions or need assistance, feel free to reach out. Thank you!
155151

scripts/healthcheck-ci.sh

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,71 @@
11
#!/bin/bash
22

3+
set -e
4+
35
log_dir="/opt/src/logs"
4-
mkdir -p $log_dir
6+
mkdir -p "$log_dir"
7+
8+
container_name="healthcheck_test_container"
9+
10+
GREEN='\033[0;32m'
11+
RED='\033[0;31m'
12+
YELLOW='\033[1;33m'
13+
NC='\033[0m' # No Color
14+
15+
log() {
16+
echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] $1${NC}"
17+
}
18+
19+
pass() {
20+
echo -e "${GREEN}$1${NC}"
21+
}
22+
23+
fail() {
24+
echo -e "${RED}$1${NC}"
25+
[ -n "$container_name" ] && docker rm -f "$container_name" >/dev/null 2>&1 || true
26+
exit 1
27+
}
28+
29+
log "Starting CI Healthcheck..."
30+
31+
log "Spinning up test container: $container_name"
32+
docker run -d --name "$container_name" alpine sleep 60 >/dev/null || fail "Failed to start container"
33+
34+
log "Checking root endpoint..."
35+
if curl --silent --fail http://localhost:8000/ > "${log_dir}/index.txt"; then
36+
pass "Root endpoint responded successfully."
37+
else
38+
fail "Port 8000 not responding."
39+
fi
40+
41+
log "Checking /metrics endpoint..."
42+
if curl --max-time 6 --silent --show-error http://localhost:8000/metrics > "${log_dir}/metrics.txt"; then
43+
pass "/metrics endpoint responded successfully."
44+
else
45+
fail "/metrics endpoint not responding."
46+
fi
47+
48+
log "Displaying container-related metrics:"
49+
echo -e "\n${GREEN}--- Metrics with container added ---${NC}"
50+
grep 'container_name' "${log_dir}/metrics.txt" | sort | uniq || echo "(No container metrics found)"
51+
52+
log "Removing test container..."
53+
docker rm -f "$container_name" >/dev/null || fail "Failed to remove test container"
554

6-
for i in 1 2
7-
do
8-
sleep 5
9-
10-
if ! curl http://localhost:8000/ > "${log_dir}/index.txt"; then
11-
echo "Port 8000 not responding"
12-
exit 1
13-
fi
55+
log "Waiting 5s for app to reflect container removal..."
56+
sleep 1
1457

58+
log "Checking /metrics endpoint again after container removal..."
59+
if curl --max-time 6 --silent --show-error http://localhost:8000/metrics > "${log_dir}/metrics_post_remove.txt"; then
60+
pass "/metrics endpoint responded successfully post-removal."
61+
else
62+
fail "/metrics endpoint not responding after container removal."
63+
fi
1564

16-
if ! curl --max-time 6 --silent --show-error http://localhost:8000/metrics > "${log_dir}/metrics.txt"; then
17-
echo "/metrics endpoint not responding"
18-
exit 1
19-
fi
20-
21-
echo -e "METRICS : \n\n"
22-
cat "${log_dir}/metrics.txt" | grep 'container_name' | sort | uniq
23-
done
65+
log "Displaying container-related metrics after removal:"
66+
echo -e "\n${GREEN}--- Metrics after container removed ---${NC}"
67+
grep 'container_name' "${log_dir}/metrics_post_remove.txt" | sort | uniq || echo "(No container metrics found)"
2468

69+
pass "Full Healthcheck Completed Successfully."
2570

26-
exit 0
71+
exit 0

0 commit comments

Comments
 (0)