diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c382bb..a978079 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,6 @@ on: - 'capture/**' - 'ansible/**' - 'dashboards/**' - - 'scripts/**' - '.gitignore' - 'LICENSE' diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 86149c5..2df2645 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -12,7 +12,6 @@ on: - 'capture/**' - 'ansible/**' - 'dashboards/**' - - 'scripts/**' - '.gitignore' - 'LICENSE' diff --git a/README.md b/README.md index c2e2b6d..7bbef4e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # 🚀 Container Exporter (CXP) -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. - -Check out the [web page](https://shayan-ghani.github.io/Container-Exporter/) for more information. +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). ## Table of Contents 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 7. [Contact Information](#contact-information) ## 🛠️ DEV STACK -![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) +![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) -see a sample of the metrics page [here](https://shayan-ghani.github.io/Container-Exporter/metrics.html). +see a sample of the metrics page in [here](./extra/metrics.txt). ## 🎥 DEMO - + ## 📋 Step-by-Step Guide @@ -115,7 +113,7 @@ PORT="8000" ./start.sh & ### 🔥 Add CXP to Prometheus - Edit your `prometheus.yml` file and add the address of container-exporter in scrape_configs: -![Prometheus config](https://github.com/Shayan-Ghani/Container-Exporter/blob/media/capture/scrape-config.png "Prometheus configuration file") +![Prometheus config](./capture/scrape-config.png "Prometheus configuration file") - Reload or restart your Prometheus server and reach out to `http://127.0.0.1:8000/metrics` ### 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 - [x] Network I/O Usage - [x] Add metrics in units of byte - [x] Check and Unregister *stat* metrics for containers that are not running - - [x] Design and develop a static website to showcase Documentation, new features, etc. + - [x] Enable functionality and smoke testing in ci - [ ] Design grafana dashboards and share them on grafana cloud - - [ ] Add unit tests - - [ ] Add `clear_metrics` functionality to switch on clearing the labels or setting them to 0 to maintain time series data, on user's demand. - + - [ ] Design and develop a static website to showcase Documentation, new features, etc. ## Contributions -Welcome to CXP! This project is production-ready now, and we encourage contributions to enhance its functionality, optimize code, and add new features +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 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! diff --git a/scripts/healthcheck-ci.sh b/scripts/healthcheck-ci.sh index 5cc54a8..7c9d446 100644 --- a/scripts/healthcheck-ci.sh +++ b/scripts/healthcheck-ci.sh @@ -1,26 +1,71 @@ #!/bin/bash +set -e + log_dir="/opt/src/logs" -mkdir -p $log_dir +mkdir -p "$log_dir" + +container_name="healthcheck_test_container" + +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +log() { + echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] $1${NC}" +} + +pass() { + echo -e "${GREEN}✅ $1${NC}" +} + +fail() { + echo -e "${RED}❌ $1${NC}" + [ -n "$container_name" ] && docker rm -f "$container_name" >/dev/null 2>&1 || true + exit 1 +} + +log "Starting CI Healthcheck..." + +log "Spinning up test container: $container_name" +docker run -d --name "$container_name" alpine sleep 60 >/dev/null || fail "Failed to start container" + +log "Checking root endpoint..." +if curl --silent --fail http://localhost:8000/ > "${log_dir}/index.txt"; then + pass "Root endpoint responded successfully." +else + fail "Port 8000 not responding." +fi + +log "Checking /metrics endpoint..." +if curl --max-time 6 --silent --show-error http://localhost:8000/metrics > "${log_dir}/metrics.txt"; then + pass "/metrics endpoint responded successfully." +else + fail "/metrics endpoint not responding." +fi + +log "Displaying container-related metrics:" +echo -e "\n${GREEN}--- Metrics with container added ---${NC}" +grep 'container_name' "${log_dir}/metrics.txt" | sort | uniq || echo "(No container metrics found)" + +log "Removing test container..." +docker rm -f "$container_name" >/dev/null || fail "Failed to remove test container" -for i in 1 2 -do - sleep 5 - - if ! curl http://localhost:8000/ > "${log_dir}/index.txt"; then - echo "Port 8000 not responding" - exit 1 - fi +log "Waiting 5s for app to reflect container removal..." +sleep 1 +log "Checking /metrics endpoint again after container removal..." +if curl --max-time 6 --silent --show-error http://localhost:8000/metrics > "${log_dir}/metrics_post_remove.txt"; then + pass "/metrics endpoint responded successfully post-removal." +else + fail "/metrics endpoint not responding after container removal." +fi - if ! curl --max-time 6 --silent --show-error http://localhost:8000/metrics > "${log_dir}/metrics.txt"; then - echo "/metrics endpoint not responding" - exit 1 - fi - - echo -e "METRICS : \n\n" - cat "${log_dir}/metrics.txt" | grep 'container_name' | sort | uniq -done +log "Displaying container-related metrics after removal:" +echo -e "\n${GREEN}--- Metrics after container removed ---${NC}" +grep 'container_name' "${log_dir}/metrics_post_remove.txt" | sort | uniq || echo "(No container metrics found)" +pass "Full Healthcheck Completed Successfully." -exit 0 +exit 0 \ No newline at end of file