From c3167f484d4b83bd723514823055a07cd522d6d9 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 Jul 2024 08:37:38 +0000 Subject: [PATCH 1/7] commit --- app/main.py | 4 +++- docker-compose.yml | 34 ++++++++++++++++++++++++++++++++++ dockerfile | 17 +++++++++++++++++ prometheus.yml | 10 ++++++++++ requirements.txt | Bin 100 -> 91 bytes 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yml create mode 100644 dockerfile create mode 100644 prometheus.yml diff --git a/app/main.py b/app/main.py index 2e6fb50..19ea5e2 100644 --- a/app/main.py +++ b/app/main.py @@ -1,11 +1,13 @@ from typing import List from fastapi import FastAPI - +from prometheus_fastapi_instrumentator import Instrumentator from app import services from app.schema import UserIn, BaseResponse, UserListOut app = FastAPI() +# Initialize Prometheus Instrumentator +instrumentator = Instrumentator().instrument(app).expose(app) @app.get("/") async def index(): diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..04664ea --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,34 @@ +version: '3.8' + +services: + web: + build: . + command: uvicorn app.main:app --host 0.0.0.0 + volumes: + - .:/app + ports: + - 8008:8000 + + prometheus: + image: prom/prometheus + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" + + grafana: + image: grafana/grafana + environment: + GF_SECURITY_ADMIN_USER: admin + GF_SECURITY_ADMIN_PASSWORD: admin + ports: + - "3000:3000" + volumes: + - grafana-data:/var/lib/grafana + depends_on: + - prometheus + +volumes: + grafana-data: + + diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..3173238 --- /dev/null +++ b/dockerfile @@ -0,0 +1,17 @@ +# Dockerfile + +# pull the official docker image +FROM python:3.11.1-slim + +# set work directory +WORKDIR /app + +# set env variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# install dependencies +COPY requirements.txt . +RUN pip install -r requirements.txt +# copy project +COPY . . diff --git a/prometheus.yml b/prometheus.yml new file mode 100644 index 0000000..6a69451 --- /dev/null +++ b/prometheus.yml @@ -0,0 +1,10 @@ +global: + scrape_interval: 15s + +scrape_configs: + - job_name: "api" + metrics_path: "/metrics" + static_configs: + - targets: ["13.232.27.191:8008"] + + diff --git a/requirements.txt b/requirements.txt index c4d2fc05e14d39e16c68f63f30c84950e5bedeb2..5bc04e94e486790c365ea48cad87f02196a5db08 100644 GIT binary patch literal 91 zcmaFAdw)_+Vsf^vt&y>wp`HO(T4HfYVnL>@t%07U5s+V6mYJMiln3G)836eOMftg@ kB^jxu#qm(3@tJwWB}JvVsd*)dCHY0Rwx)W9hI&R^0I0 Date: Sat, 20 Jul 2024 15:29:24 +0530 Subject: [PATCH 2/7] commit --- jenkinsfile | 1 + 1 file changed, 1 insertion(+) create mode 100644 jenkinsfile diff --git a/jenkinsfile b/jenkinsfile new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/jenkinsfile @@ -0,0 +1 @@ + From deefd5a2f4cdca5050c2956e34f00fe6effa5e2a Mon Sep 17 00:00:00 2001 From: jayanth <83051900+jayan@users.noreply.github.com> Date: Sat, 20 Jul 2024 15:30:30 +0530 Subject: [PATCH 3/7] commit --- jenkinsfile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/jenkinsfile b/jenkinsfile index 8b13789..1ccdf6c 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -1 +1,27 @@ +pipeline { + agent any + + environment { + GIT_REPO = 'https://github.com/jayan/docker-fastapi-test.git' + } + + stages { + stage('Checkout') { + steps { + // Checkout the code from GitHub + checkout([ + $class: 'GitSCM', + branches: [[name: '*/main']], + userRemoteConfigs: [[url: "${env.GIT_REPO}"]] + ]) + } + } + stage('Deploy') { + steps { + // Run docker compose up --build -d + sh 'docker compose up --build -d' + } + } + } +} From 1e2ba0df71202b184460b747d6996674027bff87 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 Jul 2024 10:14:59 +0000 Subject: [PATCH 4/7] commit --- Terraform/ec2.tf | 68 ++++++++++++++++++++++++++++++++++++++++++++++ install/docker.sh | 16 +++++++++++ install/jenkins.sh | 9 ++++++ 3 files changed, 93 insertions(+) create mode 100644 Terraform/ec2.tf create mode 100644 install/docker.sh create mode 100644 install/jenkins.sh diff --git a/Terraform/ec2.tf b/Terraform/ec2.tf new file mode 100644 index 0000000..0c426bb --- /dev/null +++ b/Terraform/ec2.tf @@ -0,0 +1,68 @@ +#provider +provider "aws" { + region = "us-east-1" # Change to your desired region +} + +# security group +resource "aws_security_group" "web_sg" { + name_prefix = "web-sg-" + + ingress { + from_port = 3000 + to_port = 3000 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 9090 + to_port = 9090 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 8000 + to_port = 8000 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 8008 + to_port = 8008 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 8080 + to_port = 8080 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "web-sg" + } +} + +#EC2 instance +resource "aws_instance" "web_server" { + ami = "ami-0c55b159cbfafe1f0" + instance_type = "t2.micro" + key_name = "webserver" + + security_groups = [aws_security_group.web_sg.name] + + tags = { + Name = "web-server-instance" + } +} diff --git a/install/docker.sh b/install/docker.sh new file mode 100644 index 0000000..df1abe4 --- /dev/null +++ b/install/docker.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Add Docker's official GPG key: +sudo apt-get update -y +sudo apt-get install ca-certificates curl -y +sudo install -m 0755 -d /etc/apt/keyrings -y +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 -y + +sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y diff --git a/install/jenkins.sh b/install/jenkins.sh new file mode 100644 index 0000000..1a2cace --- /dev/null +++ b/install/jenkins.sh @@ -0,0 +1,9 @@ +#!/bin/bash +#install jenkins +sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \ + https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key +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 From 947b07eadf6bcdb75f236b8bde915ac796f10fda Mon Sep 17 00:00:00 2001 From: jayanth <83051900+jayan@users.noreply.github.com> Date: Sat, 20 Jul 2024 16:41:27 +0530 Subject: [PATCH 5/7] commited --- README.md | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 179 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b7a613..32f7eb9 100644 --- a/README.md +++ b/README.md @@ -1 +1,179 @@ -# docker-fastapi-test \ No newline at end of file +# docker-fastapi-test + + + +Application:- +clone the below repositry + +Repo URL:- https://github.com/jayan/docker-fastapi-test + +To clone the these use +```bash + git clone https://github.com/jayan/docker-fastapi-test +``` + +Dockerized the application + +```bash + nano dockerfile +``` + +```bash +# Dockerfile + +# pull the official docker image +FROM python:3.11.1-slim + +# set work directory +WORKDIR /app + +# set env variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# install dependencies +COPY requirements.txt . +RUN pip install -r requirements.txt +# copy project +COPY . . +``` + +create docker-compose.yml file + +```bash + nano docker-compose.yml +``` + +```bash +version: '3.8' + +services: + web: + build: . + command: uvicorn app.main:app --host 0.0.0.0 + volumes: + - .:/app + ports: + - 8008:8000 + + prometheus: + image: prom/prometheus + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" + + grafana: + image: grafana/grafana + environment: + GF_SECURITY_ADMIN_USER: admin + GF_SECURITY_ADMIN_PASSWORD: admin + ports: + - "3000:3000" + volumes: + - grafana-data:/var/lib/grafana + depends_on: + - prometheus + +volumes: + grafana-data: +``` + +create prometheus.yml + +```bash + nano prometheus.yml +``` + +```bash +global: + scrape_interval: 15s + +scrape_configs: + - job_name: "api" + metrics_path: "/metrics" + static_configs: + - targets: ["13.232.27.191:8008"] + +``` + +create a jenkins file + +```bash + nano jenkinsfile +``` + +```bash +pipeline { + agent any + + environment { + GIT_REPO = 'https://github.com/jayan/docker-fastapi-test.git' + } + + stages { + stage('Checkout') { + steps { + // Checkout the code from GitHub + checkout([ + $class: 'GitSCM', + branches: [[name: '*/main']], + userRemoteConfigs: [[url: "${env.GIT_REPO}"]] + ]) + } + } + stage('Deploy') { + steps { + // Run docker compose up --build -d + sh 'docker compose up --build -d' + } + } + } +} +``` + +# upload it into the git hub using these commands + +```bash + git add . + git commit -m "commit" + git push origin main +``` +#install jenkins and docker using jenkins.sh and docker.sh + +After configuring, create a job to run the Jenkinsfile in Jenkins and check whether the FastAPI application is up and running. + + +![6114142690867264183](https://github.com/user-attachments/assets/9dcc15a0-e577-4e2a-adb6-bde66f394ec5) + +![6114142690867264183](https://github.com/user-attachments/assets/a0f55a14-e709-4b53-a9b1-7ea016d0daad) + +These is my Fast api application +```bash + http://13.232.27.191:8008/docs +``` + +![6114142690867264184](https://github.com/user-attachments/assets/ba0cdbd7-6096-4f8f-862d-dae8085e7654) + +monitoring tools Prometheus and Grafana +```bash + http://13.232.27.191:9090/ + http://13.232.27.191:3000/ +``` + +![6114142690867264182](https://github.com/user-attachments/assets/e67b7142-cab1-472b-9846-c745f85b88f9) + + +![6114142690867264185](https://github.com/user-attachments/assets/2fc6a74c-cb01-4235-aa5f-b7a1ec7f2bbe) + + +#Once the application runs successfully, make sure to destroy containers and recreate another one and check if previous data is still present. + +These is the data Before destroying the previous containers + + +![6114142690867264188 (1)](https://github.com/user-attachments/assets/87df6d2e-f51f-4bbb-8513-2e48fd7e1df7) + +After destrying the containers i recreated the containers these is the output + +![6114142690867264189](https://github.com/user-attachments/assets/d860eeb1-1c6d-4900-a2e8-8846e4b3cb5f) From 6edddbf44bfcbb4a232abc5b7614c927b62a58b3 Mon Sep 17 00:00:00 2001 From: jayanth <83051900+jayan@users.noreply.github.com> Date: Sat, 20 Jul 2024 16:42:51 +0530 Subject: [PATCH 6/7] Updated --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 32f7eb9..dc8a1bd 100644 --- a/README.md +++ b/README.md @@ -177,3 +177,5 @@ These is the data Before destroying the previous containers After destrying the containers i recreated the containers these is the output ![6114142690867264189](https://github.com/user-attachments/assets/d860eeb1-1c6d-4900-a2e8-8846e4b3cb5f) + +Previous data was still existed From 9dd0668140e832ddb93612da610d513e482055e0 Mon Sep 17 00:00:00 2001 From: jayanth <83051900+jayan@users.noreply.github.com> Date: Sat, 20 Jul 2024 16:46:44 +0530 Subject: [PATCH 7/7] commited --- Dashboard.json | 1058 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1058 insertions(+) create mode 100644 Dashboard.json diff --git a/Dashboard.json b/Dashboard.json new file mode 100644 index 0000000..b7de4cd --- /dev/null +++ b/Dashboard.json @@ -0,0 +1,1058 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "datasource", + "uid": "grafana" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 9, + "x": 0, + "y": 0 + }, + "id": 2, + "links": [], + "options": { + "legend": { + "calcs": [ + "mean", + "lastNotNull", + "max", + "min" + ], + "displayMode": "table", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "10.1.5", + "targets": [ + { + "$$hashKey": "object:214", + "datasource": { + "type": "prometheus", + "uid": "e4584a9f-5364-4b3d-a851-7abbc5250820" + }, + "editorMode": "code", + "expr": "increase(http_requests_total{job=\"app\"}[1m])", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "{{ method }} {{ handler }}", + "range": true, + "refId": "A" + } + ], + "title": "Total requests per minute", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "bars", + "fillOpacity": 100, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "short" + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "4xx" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "red", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "HTTP 500" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#bf1b00", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 7, + "w": 10, + "x": 9, + "y": 0 + }, + "id": 13, + "links": [], + "options": { + "legend": { + "calcs": [ + "mean", + "max" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "pluginVersion": "10.1.5", + "targets": [ + { + "$$hashKey": "object:140", + "datasource": { + "type": "prometheus", + "uid": "e4584a9f-5364-4b3d-a851-7abbc5250820" + }, + "editorMode": "code", + "expr": "sum by (status) (rate(http_requests_total[1m]))", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "{{ status }}", + "range": true, + "refId": "A" + } + ], + "title": "Request per minute", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "short" + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "errors" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "#c15c17", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 7, + "w": 5, + "x": 19, + "y": 0 + }, + "id": 4, + "links": [], + "options": { + "legend": { + "calcs": [ + "mean", + "lastNotNull", + "max" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "pluginVersion": "10.1.5", + "targets": [ + { + "$$hashKey": "object:766", + "datasource": { + "type": "prometheus", + "uid": "e4584a9f-5364-4b3d-a851-7abbc5250820" + }, + "editorMode": "code", + "expr": "sum(rate(http_requests_total{status=\"5xx\"}[30s]))", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "errors", + "range": true, + "refId": "A" + } + ], + "title": "Errors per second", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 9, + "x": 0, + "y": 7 + }, + "id": 6, + "links": [], + "options": { + "legend": { + "calcs": [ + "mean", + "lastNotNull", + "max", + "min" + ], + "displayMode": "table", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "10.1.5", + "targets": [ + { + "$$hashKey": "object:146", + "datasource": { + "type": "prometheus", + "uid": "e4584a9f-5364-4b3d-a851-7abbc5250820" + }, + "editorMode": "code", + "expr": "http_request_duration_seconds_sum{job=\"app\",handler!=\"none\"} / http_request_duration_seconds_count", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "{{ handler }}", + "range": true, + "refId": "A" + } + ], + "title": "Average response time", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 25, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "normal" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 10, + "x": 9, + "y": 7 + }, + "id": 15, + "links": [], + "options": { + "legend": { + "calcs": [ + "mean", + "lastNotNull", + "max", + "min" + ], + "displayMode": "table", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "10.1.5", + "targets": [ + { + "$$hashKey": "object:426", + "datasource": { + "type": "prometheus", + "uid": "e4584a9f-5364-4b3d-a851-7abbc5250820" + }, + "editorMode": "code", + "expr": "histogram_quantile(0.5, rate(http_request_duration_seconds_bucket{handler!=\"none\"}[30s]))", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "{{ handler }}", + "range": true, + "refId": "A" + } + ], + "title": "Request duration [s] - p50", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "decbytes" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 5, + "x": 19, + "y": 7 + }, + "id": 8, + "links": [], + "options": { + "legend": { + "calcs": [ + "lastNotNull" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "pluginVersion": "10.1.5", + "targets": [ + { + "$$hashKey": "object:638", + "datasource": { + "type": "prometheus", + "uid": "e4584a9f-5364-4b3d-a851-7abbc5250820" + }, + "editorMode": "code", + "expr": "process_resident_memory_bytes{job=\"app\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "mem", + "range": true, + "refId": "A" + } + ], + "title": "Memory usage", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percentunit" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 5, + "x": 19, + "y": 13 + }, + "id": 9, + "links": [], + "options": { + "legend": { + "calcs": [ + "lastNotNull", + "max" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "pluginVersion": "10.1.5", + "targets": [ + { + "$$hashKey": "object:638", + "datasource": { + "type": "prometheus", + "uid": "e4584a9f-5364-4b3d-a851-7abbc5250820" + }, + "editorMode": "code", + "expr": "rate(process_cpu_seconds_total{job=\"app\"}[30s])", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "cpu", + "range": true, + "refId": "A" + } + ], + "title": "CPU usage", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "max": 1, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percentunit" + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "none" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "red", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 7, + "w": 9, + "x": 0, + "y": 15 + }, + "id": 11, + "links": [], + "options": { + "legend": { + "calcs": [ + "lastNotNull" + ], + "displayMode": "table", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "pluginVersion": "10.1.5", + "targets": [ + { + "$$hashKey": "object:1079", + "datasource": { + "type": "prometheus", + "uid": "e4584a9f-5364-4b3d-a851-7abbc5250820" + }, + "editorMode": "code", + "expr": "increase(http_request_duration_seconds_bucket{le=\"0.1\"}[1m]) \n/ ignoring (le) increase(http_request_duration_seconds_count[1m])", + "format": "time_series", + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "{{ handler }}", + "refId": "A" + } + ], + "title": "Requests under 100ms", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "line+area" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "transparent", + "value": null + }, + { + "color": "red", + "value": 0 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 10, + "x": 9, + "y": 15 + }, + "id": 16, + "links": [], + "options": { + "legend": { + "calcs": [ + "mean", + "lastNotNull", + "max", + "min" + ], + "displayMode": "table", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "pluginVersion": "10.1.5", + "targets": [ + { + "$$hashKey": "object:426", + "datasource": { + "type": "prometheus", + "uid": "e4584a9f-5364-4b3d-a851-7abbc5250820" + }, + "editorMode": "code", + "expr": "histogram_quantile(0.9, rate(http_request_duration_seconds_bucket{handler!=\"none\"}[30s]))", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "{{ handler }}", + "range": true, + "refId": "A" + } + ], + "title": "Request duration [s] - p90", + "type": "timeseries" + } + ], + "refresh": "3s", + "schemaVersion": 38, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-5m", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "3s" + ], + "time_options": [ + "5m", + "15m", + "1h", + "6h", + "12h", + "24h", + "2d", + "7d", + "30d" + ] + }, + "timezone": "", + "title": "FastAPI Dashboard", + "uid": "_eX4mpl3", + "version": 5, + "weekStart": "" +}