Skip to content

euiyounghwang/DB-Interface-Export

Repository files navigation

DB-Interface-Export

Python DB Interface with Prometheus-Export

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.8+ based on standard Python. This is a repository that provides to deliver the records to the Prometheus-Export application.

Install Poerty

https://python-poetry.org/docs/?ref=dylancastillo.co#installing-with-the-official-installer

Using Python Virtual Environment

python -m venv .venv
source .venv/bin/activate

Using Poetry: Create the virtual environment in the same directory as the project and install the dependencies:

  • Gunicorn is a Python WSGI HTTP Server that usually lives between a reverse proxy (e.g., Nginx) or load balancer (e.g., AWS ELB) and a web application such as Django or Flask.
  • Better performance by optimizing Gunicorn config (https://medium.com/building-the-system/gunicorn-3-means-of-concurrency-efbb547674b7)
  • The suggested number of workers is (2*CPU)+1.
  • gunicorn --workers=5 --threads=2 --worker-class=gthread main:app, the maximum concurrent requests areworkers * threads 10 in our case.
poetry config virtualenvs.in-project true
poetry init
poetry add fastapi
poetry add uvicorn
poetry add pytz
poetry add httpx
poetry add pytest
poetry add pytest-cov
poetry add requests
poetry add python-dotenv
poetry add JPype1
poetry add psycopg2-binary
poetry add jaydebeapi

...

# start with gunicorn config
gunicorn.config.py

import multiprocessing
 
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = "uvicorn.workers.UvicornWorker"
wsgi_app = "app.main:app"
timeout = 60
loglevel = "info"
bind = "0.0.0.0:8000"
max_requests = 1000
max_requests_jitter = 100

...
gunicorn -c app/gunicorn.config.py

gunicorn -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:8004 --workers 4

..
uvicorn app.main:app --reload for dev

or you can run this shell script ./create_virtual_env.sh to make an environment. then go to virtual enviroment using source .venv/bin/activate

Register Service

  • sudo service db_es_api status/stop/start/restart
#-- /etc/systemd/system/db_es_api.service
[Unit]
Description=DB ES Service

[Service]
User=devuser
Group=devuser
Type=simple
ExecStart=/bin/bash /home/devuser/db_interface_api/service-start.sh
ExecStop= /usr/bin/killall db_es_service

[Install]
WantedBy=default.target


# Service command
sudo systemctl daemon-reload 
sudo systemctl enable db_es_api.service
sudo systemctl start db_es_api.service 
sudo systemctl status db_es_api.service 
sudo systemctl stop db_es_api.service 

sudo service db_es_api status/stop/start

Service

  • Run this command ./start-start.sh or python -m uvicorn main:app --reload --host=0.0.0.0 --port=8002 --workers 4
  • Service : http://localhost:8002/docs

About

Python DB Interface with Prometheus-Export

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors