Skip to content

Commit 8cb8591

Browse files
committed
everything for system status
1 parent 04d8be8 commit 8cb8591

13 files changed

Lines changed: 461 additions & 0 deletions

File tree

status/prom/docker-compose.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: '2'
2+
3+
services:
4+
coin-api:
5+
container_name: coin-api
6+
build:
7+
context: .
8+
dockerfile: ./dockerfile
9+
restart: 'on-failure'
10+
ports:
11+
- "5000:5000"
12+
prometheus:
13+
image: prom/prometheus:latest
14+
restart: always
15+
ports:
16+
- 9090:9090
17+
volumes:
18+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
19+
command:
20+
- --config.file=/etc/prometheus/prometheus.yml
21+
22+
scraper:
23+
container_name: scraper
24+
build:
25+
context: .
26+
dockerfile: ./dockerfile.scraper
27+
volumes:
28+
- ./output:/app/output
29+
- ./templates:/app/templates
30+
- ./json.json:/app/json.json
31+
ports:
32+
- "8000:8000"
33+
restart: 'on-failure'
34+
command: python3 scraper.py --json json.json
35+
36+
nginx:
37+
image: nginx:1.25.3
38+
ports:
39+
- 80:80
40+
volumes:
41+
- ./nginx.conf:/etc/nginx/nginx.conf

status/prom/dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM python:3.9-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt .
6+
7+
RUN pip3 install -r requirements.txt
8+
9+
COPY server.py .
10+
11+
12+
EXPOSE 5000
13+
14+
CMD ["python3", "server.py"]

status/prom/dockerfile.scraper

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# filepath: /Users/vineet/Projects/sce_system_status/prom/Dockerfile.scraper
2+
FROM python:3.9-slim
3+
4+
WORKDIR /app
5+
6+
COPY requirements.txt .
7+
8+
RUN pip3 install -r requirements.txt
9+
10+
COPY flags.py .
11+
COPY scraper.py .
12+
COPY templates/ ./templates/
13+
14+
CMD ["python3", "scraper.py", "--json", "json.json"]

status/prom/flags.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import argparse
2+
3+
def get_args():
4+
parser = argparse.ArgumentParser()
5+
parser.add_argument(
6+
"--interval",
7+
"-int",
8+
type= int,
9+
default = 15,
10+
help = "interval for how often queries should be done"
11+
)
12+
parser.add_argument(
13+
"--port",
14+
type = int,
15+
default = 8000,
16+
help = "port for server to be hosted on, defaults to 8000"
17+
)
18+
parser.add_argument(
19+
"--json",
20+
type = str,
21+
required = True,
22+
help = "argument to a json file, where the json file specifies what services we need to query"
23+
)
24+
25+
return parser.parse_args()

status/prom/json.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"hostname": "localhost:3000/metrics",
4+
"queries": [
5+
6+
{
7+
"serviceName": "Coin-API",
8+
"query": "up"
9+
}
10+
11+
]
12+
}
13+
]

status/prom/nginx.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
http {
2+
# Define cache path and parameters
3+
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=html_cache:10m max_size=100m inactive=60m;
4+
proxy_temp_path /var/cache/nginx/temp;
5+
6+
#for http://localhost/status
7+
server{
8+
listen 80;
9+
server_name _;
10+
11+
# Enable caching
12+
proxy_cache html_cache;
13+
proxy_cache_valid 200 302 30s;
14+
proxy_cache_valid 404 30s;
15+
16+
location /{
17+
proxy_pass http://scraper:8000;
18+
19+
# Cache HTML files
20+
location ~* \.html$ {
21+
proxy_pass http://scraper:8000;
22+
proxy_cache html_cache;
23+
proxy_cache_min_uses 1;
24+
proxy_cache_lock on;
25+
add_header X-Cache-Status $upstream_cache_status;
26+
}
27+
}
28+
}
29+
}
30+
31+
events{ }

status/prom/output/metrics.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>Prometheus Metrics</title>
6+
</head>
7+
<body>
8+
<h1>Prometheus Metrics</h1>
9+
<table border="1">
10+
<tr>
11+
<th>Instance</th>
12+
<th>Value</th>
13+
</tr>
14+
15+
<tr>
16+
<td>coin-api:5000</td>
17+
<td>1</td>
18+
</tr>
19+
20+
</table>
21+
</body>
22+
</html>

status/prom/prometheus.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global:
2+
scrape_interval: 10s
3+
4+
5+
scrape_configs:
6+
- job_name: 'coin-api'
7+
static_configs:
8+
- targets: ['coin-api:5000']

status/prom/queries.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"hostname": "localhost:9090/metrics",
3+
"queries": [
4+
{
5+
"serviceName": "My FastAPI API - CPU Usage",
6+
"query": "rate(node_cpu_seconds_total[5m])"
7+
},
8+
{
9+
"serviceName": "Prometheus - Memory Usage",
10+
"query": "node_memory_MemAvailable_bytes"
11+
},
12+
{
13+
"serviceName": "My FastAPI API - Uptime",
14+
"query": "time() - process_start_time_seconds"
15+
},
16+
{
17+
"serviceName": "Last Down::",
18+
"query": "down"
19+
}
20+
]
21+
}

status/prom/requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fastapi==0.84.0
2+
uvicorn==0.18.3
3+
Jinja2==3.0.2
4+
py-grpc-prometheus==0.7.0
5+
prometheus_api_client
6+

0 commit comments

Comments
 (0)