Skip to content
Open
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
Binary file added docker/docker-bind/docker-bind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker/docker-compose/docker-compose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docker/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
api:
image: jusan-fastapi-final:dockerized
container_name: jusan-compose
ports:
- "8282:8080"
Binary file added docker/docker-exec/docker-exec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker/docker-mount/docker-mount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker/docker-run/docker-run_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker/docker-run/docker-run_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docker/dockerfile/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM nginx:mainline
WORKDIR /var/www
COPY jusan-dockerfile.conf /etc/nginx/conf.d/jusan-dockerfile.conf
COPY jusan-dockerfile .
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Binary file added docker/dockerfile/dockerfile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docker/dockerize/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.8
WORKDIR /opt
COPY main.py /opt/
RUN pip3 install fastapi uvicorn
EXPOSE 8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
Binary file not shown.
Binary file added docker/dockerize/dockerize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 159 additions & 0 deletions docker/dockerize/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
from fastapi import FastAPI, Response, status
from prometheus_client import Counter, Histogram, Gauge, generate_latest, REGISTRY
from prometheus_client.exposition import basic_auth_handler
import time

app=FastAPI()

REQUESTS = Counter('http_requests_total', 'Number of HTTP requests received', ['endpoint', 'method'])

REQUEST_LATENCY = Histogram('http_requests_milliseconds', 'Duration of HTTP requests in milliseconds', ['endpoint', 'method'], buckets=[0.1, 0.3, 0.5, 1, 2, 5, 10])

LAST_VALUE_SUM1N = Gauge('last_sum1n', 'Value stores last result of sum1n')

LAST_VALUE_FIBO = Gauge('last_fibo', 'Value stores last result of fibo')

LAST_SIZE = Gauge('last_size', 'Value stores current list size')

LAST_CALCULATOR = Gauge('last_calculator', 'Value stores last result of calculator')

ERRORS_CALCULATOR = Counter('errors_calculator_total', 'Number of errors in calculator')

@app.get("/")
async def root():
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/', method='HTTP').inc()
return {"message": duration}

@app.get("/metrics")
async def metrics():
return Response(generate_latest(REGISTRY), media_type="text/plain")

@app.get("/sum1n/{item}")
def sum1n(item):
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/sum1n', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/sum1n', method='HTTP').inc()
result = 0
i = 1
while i <= int(item):
result += i
i += 1
LAST_VALUE_SUM1N.set(result)
return {"result": result}

@app.get("/fibo/")
def fibo(n: int = 0):
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/fibo', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/fibo', method='HTTP').inc()
fibon = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
LAST_VALUE_FIBO.set(fibon[int(n)-1])
return {"result": fibon[int(n)-1]}

@app.post("/reverse")
def reverse(item:str):
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/reverse', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/reverse', method='HTTP').inc()
word = item [::-1]
return {"reversed word":word}

ary = []
@app.put("/list")
def list(item:str):
ary.append(item)
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/list', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/list', method='HTTP').inc()
LAST_SIZE.set(len(ary))
return {"result":ary}

@app.get("/list")
def list():
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/list', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/list', method='HTTP').inc()
return {"result":ary}

@app.post("/calculator")
def calc(item:str, response: Response):
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/calculator', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/hello', method='HTTP').inc()
ind = []

for i in range(len(item)):
if item[i] == ",":
ind.append(i)

num1_arr = ""
num2_arr = ""
oper=item[ind[0]+1]

for i in range(ind[0]):
num1_arr =num1_arr + item[i]


for i in range(ind[1]+1, len(item), 1):
num2_arr = num2_arr + item[i]

if len(ind) == 2 and num1_arr.isnumeric() == True and num2_arr.isnumeric() == True:
if oper == "+":
LAST_CALCULATOR.set(int(num1_arr)+int(num2_arr))
return {"result":(int(num1_arr)+int(num2_arr))}
elif oper == "-":
LAST_CALCULATOR.set(int(num1_arr)-int(num2_arr))
return {"result":(int(num1_arr)-int(num2_arr))}
elif oper == "*":
LAST_CALCULATOR.set(int(num1_arr)*int(num2_arr))
return {"result":(int(num1_arr)*int(num2_arr))}
elif oper == "/":
if int(num2_arr)==0:
response.status_code = status.HTTP_403_FORBIDDEN
ERRORS_CALCULATOR.inc()
return{"error": "zerodiv"}
else:
LAST_CALCULATOR.set(int(num1_arr)/int(num2_arr))
return{"result":(int(num1_arr)/int(num2_arr))}
else:
response.status_code = status.HTTP_400_BAD_REQUEST
ERRORS_CALCULATOR.inc()
return{"error": "invalid"}
else:
response.status_code = status.HTTP_400_BAD_REQUEST
ERRORS_CALCULATOR.inc()
return{"error":"invalid"}

@app.get("/hello")
def hello():
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/hello', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/hello', method='HTTP').inc()
return {"hello":"world"}

@app.post("/create")
def create(item:int):
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/create', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/create', method='HTTP').inc()
return {"newitem":item}

@app.get("/new/{item}/{item2}")
def new(item,item2):
start_time = time.time()
duration = start_time/1000000000
REQUEST_LATENCY.labels(endpoint='/new', method='HTTP').observe(duration)
REQUESTS.labels(endpoint='/new', method='HTTP').inc()
return {"new":item,
"new2":item2}
84 changes: 84 additions & 0 deletions fastapi/fast_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from fastapi import FastAPI, Response, status

app=FastAPI()

@app.get("/sum1n/{item}")
def sum1n(item):
result = 0
i = 1
while i <= int(item):
result += i
i += 1
return {"result": result}

@app.get("/fibo/")
def fibo(n: int = 0):
fibon = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
return {"result": fibon[int(n)-1]}

@app.post("/reverse")
def reverse(item:str):
word = item [::-1]
return {"reversed word":word}

ary = []
@app.put("/list")
def list(item:str):
ary.append(item)
return {"result":ary}

@app.get("/list")
def list():
return {"result":ary}

@app.post("/calculator")
def calc(item:str, response: Response):
ind = []

for i in range(len(item)):
if item[i] == ",":
ind.append(i)

num1_arr = ""
num2_arr = ""
oper=item[ind[0]+1]

for i in range(ind[0]):
num1_arr =num1_arr + item[i]


for i in range(ind[1]+1, len(item), 1):
num2_arr = num2_arr + item[i]

if len(ind) == 2 and num1_arr.isnumeric() == True and num2_arr.isnumeric() == True:
if oper == "+":
return {"result":(int(num1_arr)+int(num2_arr))}
elif oper == "-":
return {"result":(int(num1_arr)-int(num2_arr))}
elif oper == "*":
return {"result":(int(num1_arr)*int(num2_arr))}
elif oper == "/":
if int(num2_arr)==0:
response.status_code = status.HTTP_403_FORBIDDEN
return{"error": "zerodiv"}
else:
return{"result":(int(num1_arr)/int(num2_arr))}
else:
response.status_code = status.HTTP_400_BAD_REQUEST
return{"error": "invalid"}
else:
response.status_code = status.HTTP_400_BAD_REQUEST
return{"error":"invalid"}

@app.get("/hello")
def hello():
return {"hello":"world"}

@app.post("/create")
def create(item:int):
return {"newitem":item}

@app.get("/new/{item}/{item2}")
def new(item,item2):
return {"new":item,
"new2":item2}
7 changes: 7 additions & 0 deletions git/0 git_homework/1 git-init.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
https://github.com/khalykbaiakaris/jusan-git/tree/e2d7ccc7db8d4c0ebd582c79edab18e39e2f9feaf683


### вывод лога
### git log --all --decorate --oneline --graph
### * ccc7db8 (HEAD -> main, origin/main) add: README.md
### * e2d743e add: script.sh
1 change: 1 addition & 0 deletions git/0 git_homework/2 readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/khalykbaiakaris/jusan-git/tree/06ef4226f63b5bba8290e04e6ab897d203f28187
1 change: 1 addition & 0 deletions git/0 git_homework/3 gitignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/khalykbaiakaris/jusan-git/tree/58065e3386ff0ca3488172403a662e839e31a9d0
1 change: 1 addition & 0 deletions git/0 git_homework/4 branch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/khalykbaiakaris/jusan-git/tree/5612c4829f4320b05ea88e403d7600097578f135
1 change: 1 addition & 0 deletions git/0 git_homework/5 merge.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/khalykbaiakaris/jusan-git/tree/23c9068bf6dff83881da56408bcf847d8d5be6d4
1 change: 1 addition & 0 deletions git/0 git_homework/6 my-pr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/khalykbaiakaris/jusan-git/pull/1
1 change: 1 addition & 0 deletions git/0 git_homework/7 fork-pr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/jusan-singularity/fork-me/pull/113
6 changes: 6 additions & 0 deletions monitoring/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.8
WORKDIR /opt
COPY main.py /opt
RUN pip3 install fastapi uvicorn prometheus_client
EXPOSE 8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080", "--workers", "1"]
Binary file added monitoring/alerting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions monitoring/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
services:
api:
build: .
ports:
- 8080:8080
restart: on-failure
prometheus:
image: prom/prometheus:v2.34.0
ports:
- 9090:9090
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
depends_on:
- api

grafana:
image: grafana/grafana:8.4.5
ports:
- 3000:3000
depends_on:
- prometheus
Binary file added monitoring/grafana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading