Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# 👇 Only log in to Docker Hub for non-pull-request events
- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# 👇 Skip message for PRs
- name: Skip Docker login on pull requests
if: github.event_name == 'pull_request'
run: echo "Skipping Docker login — secrets are unavailable in PRs."

# 👇 Build and push Docker image
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
push: ${{ github.event_name != 'pull_request' }}
tags: aryansharma04/systemmonitoring:latest

- name: Clean up images
Expand Down
33 changes: 28 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
FROM python:3.8.8-slim
# Use full Python image (not slim) to avoid missing system libs
FROM python:3.11

COPY . .
# Set working directory
WORKDIR /app

# Install required system dependencies for pandas & scikit-learn
RUN apt-get update && apt-get install -y \
gcc \
g++ \
make \
build-essential \
libopenblas-dev \
liblapack-dev \
gfortran \
&& rm -rf /var/lib/apt/lists/*

# Copy requirements first to leverage Docker cache
COPY req.txt .

RUN pip install -r req.txt
# Upgrade pip and install Python dependencies
RUN pip install --upgrade pip setuptools wheel --no-cache-dir \
&& pip install --no-cache-dir -r req.txt

# Copy application files
COPY . .

RUN python data_prepare.py
# Expose FastAPI port
EXPOSE 8000

CMD uvicorn --host=0.0.0.0 app:app
# Run FastAPI app
CMD ["uvicorn", "apps:app", "--host", "0.0.0.0", "--port", "8000"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ https://hub.docker.com/r/aryansharma04/systemmonitoring
<img src="assets/grafana-2.png" width="800">

</p>
## 🚀 Running the SystemMonitoring Stack with Docker

### Build and Start
```bash
docker-compose up --build

15 changes: 15 additions & 0 deletions apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from fastapi import FastAPI
from prometheus_fastapi_instrumentator import Instrumentator

app = FastAPI()

# Create metrics endpoint
Instrumentator().instrument(app).expose(app)

@app.get("/")
def read_root():
return {"message": "Hello World"}

@app.get("/health")
def health_check():
return {"status": "ok"}
55 changes: 24 additions & 31 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,45 @@
version: "3.8"
version: "3.9"

services:
app:
# FastAPI App
fastapi:
build: .
restart: unless-stopped
container_name: reco-app
container_name: systemmonitoring_app
ports:
- 8000:8000
- "8000:8000"
depends_on:
- prometheus
networks:
example-network:
ipv4_address: 172.16.238.10
- monitoring

# Prometheus
prometheus:
image: prom/prometheus:latest
restart: unless-stopped
container_name: prometheus
ports:
- 9090:9090
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
ports:
- "9090:9090"
networks:
example-network:
ipv4_address: 172.16.238.11
- monitoring

# Grafana
grafana:
image: grafana/grafana:latest
restart: unless-stopped
user: "472"
container_name: grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_INSTALL_PLUGINS=grafana-piechart-panel,grafana-clock-panel
volumes:
- ./provisioning:/etc/grafana/provisioning:ro
ports:
- "3000:3000"
depends_on:
- prometheus
ports:
- 3000:3000
volumes:
- ./provisioning/:/etc/grafana/provisioning/
env_file:
- ./config.monitoring
networks:
example-network:
ipv4_address: 172.16.238.12
- monitoring

networks:
example-network:
name: example-network
monitoring:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
22 changes: 8 additions & 14 deletions prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
global:
scrape_interval: 1m
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: "reco-app"

rule_files:
monitor: "systemmonitoring"

scrape_configs:
# - job_name: "prometheus"

# static_configs:
# - targets: ["localhost:9090"]
- job_name: "prometheus"
static_configs:
- targets: ["prometheus:9090"]

- job_name: "reco-app"
dns_sd_configs:
- names: ["reco-app"]
port: 8000
type: A
refresh_interval: 30s
- job_name: "fastapi"
static_configs:
- targets: ["fastapi:8000"]
4 changes: 2 additions & 2 deletions req.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pandas==1.3.5
fastapi==0.70.1
starlette==0.16.0
pydantic==1.9.0
pydantic<2
prometheus_client==0.12.0
prometheus_fastapi_instrumentator==5.7.1
uvicorn==0.16.0
scikit-learn==1.0.2
scikit-learn==1.2.2
Loading