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
37 changes: 29 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
import os
import logging
import time
from flask import Flask, request, render_template
import requests

app = Flask(__name__)

# Specify the full path to the logs folder
logs_folder = os.path.join(os.getcwd(), 'logs')

# Create the logs folder if it doesn't exist
if not os.path.exists(logs_folder):
os.makedirs(logs_folder)

# Configure logging to write logs to the specified folder
log_file = os.path.join(logs_folder, 'app.log')
logging.basicConfig(filename=log_file, level=logging.DEBUG, format='%(asctime)s %(levelname)s: %(message)s')

@app.route("/")
def home():

return render_template("home.html")


@app.route("/search", methods=["POST"])
def search():

# Get the search query
query = request.form["q"]

# Pass the search query to the Nominatim API to get a location
logging.info(f'Search query: {query}')

start_time = time.time()

location = requests.get(
"https://nominatim.openstreetmap.org/search",
{"q": query, "format": "json", "limit": "1"},
).json()

# If a location is found, pass the coordinate to the Time API to get the current time
end_time = time.time()

duration = end_time - start_time

logging.info(f'Latency for search: {duration} seconds')

if location:
coordinate = [location[0]["lat"], location[0]["lon"]]

Expand All @@ -31,9 +48,13 @@ def search():
{"latitude": coordinate[0], "longitude": coordinate[1]},
)

logging.info(f'Successful search for location: {location[0]["display_name"]}')

return render_template("success.html", location=location[0], time=time.json())

# If a location is NOT found, return the error page
else:

logging.warning(f'No location found for query: {query}')
return render_template("fail.html")

if __name__ == "__main__":
app.run(debug=True)
42 changes: 42 additions & 0 deletions docker-compose.monitoring.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: "3.8"
networks:
monitoring:
driver: bridge
volumes:
prometheus-data:
driver: local
grafana-data:
driver: local
services:
grafana:
image: grafana/grafana-oss:latest
container_name: grafana
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
restart: unless-stopped

#password: admin/admin




loki:
image: grafana/loki:2.5.0
container_name: loki
ports:
- "3100:3100"
volumes:
- ./loki-config/:/etc/loki/
command: -config.file=/etc/loki/local-config.yaml

promtail:
image: grafana/promtail:2.5.0
ports:
- "9080:9080"
volumes:
- ./logs:/var/apilogs
- /var/log:/var/log
- ./promtail-config/:/etc/promtail/
command: -config.file=/etc/promtail/promtail.yaml
Binary file added grafana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions loki-config/local-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
auth_enabled: false

server:
http_listen_port: 3100

common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
query_range:

ingester:
lifecycler:
address: 127.0.0.1
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 1h
max_chunk_age: 1h
chunk_target_size: 1048576
chunk_retain_period: 30s
max_transfer_retries: 0
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v12
index:
prefix: index_
period: 24h
24 changes: 24 additions & 0 deletions promtail-config/promtail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
server:
http_listen_port: 9080

positions:
filename: /tmp/positions.yaml

clients:
- url: http://loki:3100/loki/api/v1/push

scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log
- job_name: API
static_configs:
- targets:
- localhost
labels:
job: apilog
__path__: /var/apilogs/*log
Binary file added q1.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 q2-3:promtail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.