Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 5cc04f2f authored by KADDOUR Sidi Mohammed's avatar KADDOUR Sidi Mohammed
Browse files

update readme.md

parent 1f727f21
No related branches found
No related tags found
No related merge requests found
images/cadvisor-ui-image.png

66.8 KiB

images/jaeger-ui-image.png

89.3 KiB

images/object-recognizer-ui-image.png

202 KiB

images/prometheus-ui-image.png

62.1 KiB

images/zipkin-ui-image.png

93.3 KiB

...@@ -328,11 +328,21 @@ services: ...@@ -328,11 +328,21 @@ services:
``` ```
2. **Access the services**: 2. **Access the services**:
- Access Jaeger UI: [http://localhost:16686](http://localhost:16686)
- Access Zipkin UI: [http://localhost:9411](http://localhost:9411) - Access Jaeger UI: [http://localhost:16686](http://localhost:16686)
- Access Prometheus UI: [http://localhost:9090](http://localhost:9090) ![Jaeger UI](image/jaeger-ui-image.png)
- Access cAdvisor UI: [http://localhost:8080](http://localhost:8080)
- Access object recognizer interface : [http://localhost:5000](http://localhost:5000) - Access Zipkin UI: [http://localhost:9411](http://localhost:9411)
![Zipkin UI](image/zipkin-ui-image.png)
- Access Prometheus UI: [http://localhost:9090](http://localhost:9090)
![Prometheus UI](image/to/prometheus-ui-image.png)
- Access cAdvisor UI: [http://localhost:8080](http://localhost:8080)
![cAdvisor UI](image/cadvisor-ui-image.png)
- Access Object Recognizer Interface: [http://localhost:5000](http://localhost:5000)
![Object Recognizer Interface](image/object-recognizer-image.png)
## **Deploying on K3S using Enoslib on Grid'5000** ## **Deploying on K3S using Enoslib on Grid'5000**
......
...@@ -9,7 +9,7 @@ import os # Import os for environment variables ...@@ -9,7 +9,7 @@ import os # Import os for environment variables
from telemetry.tracerprovider import tracer, meter from telemetry.tracerprovider import tracer, meter
import imutils # pip install imutils import imutils # pip install imutils
import logging import logging
from opentelemetry.propagate import inject
# Configure logging # Configure logging
logging.basicConfig( logging.basicConfig(
format='%(asctime)s - %(levelname)s - %(message)s', format='%(asctime)s - %(levelname)s - %(message)s',
...@@ -108,8 +108,10 @@ def main(): ...@@ -108,8 +108,10 @@ def main():
logging.info(f"Motion: {motion}") logging.info(f"Motion: {motion}")
while (frame_number < interval_frame_count) or (not motion): while (frame_number < interval_frame_count) or (not motion):
frame_number += 1 frame_number += 1
with tracer.start_as_current_span("sending frame") as span: carrier = {}
with tracer.start_as_current_span("sending frame from camera") as span:
try: try:
inject(carrier)
img, frame = vid.read() img, frame = vid.read()
if not img: if not img:
if motion: if motion:
...@@ -126,7 +128,9 @@ def main(): ...@@ -126,7 +128,9 @@ def main():
data = { data = {
'frame': frame, 'frame': frame,
'capture_time': current_time 'capture_time': current_time,
'carrier': carrier
} }
a = pickle.dumps(data) a = pickle.dumps(data)
message = struct.pack("Q", len(a)) + a message = struct.pack("Q", len(a)) + a
......
...@@ -11,7 +11,9 @@ import queue ...@@ -11,7 +11,9 @@ import queue
import psutil import psutil
import imutils import imutils
import logging # Import the logging module import logging # Import the logging module
from telemetry.tracerprovider import meter from telemetry.tracerprovider import tracer , meter
from opentelemetry import trace
from opentelemetry.propagate import extract, inject
# Configure logging # Configure logging
logging.basicConfig( logging.basicConfig(
...@@ -40,6 +42,7 @@ def receive_frames(client_socket, frame_queue): ...@@ -40,6 +42,7 @@ def receive_frames(client_socket, frame_queue):
unit="s" unit="s"
) )
while True: while True:
try: try:
while len(data) < payload_size: while len(data) < payload_size:
packet = client_socket.recv(4 * 1024) # 4K packet = client_socket.recv(4 * 1024) # 4K
...@@ -106,77 +109,87 @@ def process_frames(addr, frame_queue, or_host_ip, or_port): ...@@ -106,77 +109,87 @@ def process_frames(addr, frame_queue, or_host_ip, or_port):
except queue.Empty: except queue.Empty:
logging.info(f"Queue is empty for {addr}, waiting for frames...") logging.info(f"Queue is empty for {addr}, waiting for frames...")
continue continue
received_carrier=recieveddata['carrier']
frame = recieveddata['frame'] extracted_context = extract(received_carrier)
logging.debug("Frame loaded for processing.") carrier = {}
text = f"CLIENT: {addr}" with tracer.start_as_current_span("processing the frame",context=extracted_context) as span:
try:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) inject(carrier)
gray = cv2.GaussianBlur(gray, (21, 21), 0) frame = recieveddata['frame']
logging.debug("Frame converted to grayscale and blurred.") logging.debug("Frame loaded for processing.")
text = f"CLIENT: {addr}"
if firstFrame is None:
firstFrame = gray gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
logging.info("Initialized reference frame for motion detection.") gray = cv2.GaussianBlur(gray, (21, 21), 0)
continue logging.debug("Frame converted to grayscale and blurred.")
starting_processing_time = time.time() if firstFrame is None:
fps_frame_count += 1 firstFrame = gray
elapsed_time = time.time() - fps_start_time logging.info("Initialized reference frame for motion detection.")
if elapsed_time >= 10.0:
fps = round(fps_frame_count / elapsed_time, 2)
fps_count.set(fps)
logging.info(f"FPS: {fps}")
fps_frame_count = 0
fps_start_time = time.time()
frameDelta = cv2.absdiff(firstFrame, gray)
thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations=2)
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
detected_cnt = 0
detected = False
for c in cnts:
if cv2.contourArea(c) < 10000:
continue
detected = True
detected_cnt += 1
logging.debug(f"Motion detected. Contour area: {cv2.contourArea(c)}.")
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
text = "md: motion detected"
if detected:
logging.info("Motion detected, preparing to send frame to Object Recognizer.")
md_detected_motion.set(1)
orclient_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
orclient_socket.connect((or_host_ip, or_port))
ordata = {
"frame": frame,
"capture_time": recieveddata["capture_time"],
"sentfromedgetime": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
while True:
try:
a = pickle.dumps(ordata)
message = struct.pack("Q", len(a)) + a
logging.info(f"Packet size: {len(message)} bytes.") # Log the size of the packet
orclient_socket.sendall(message)
logging.info("Frame successfully sent to Object Recognizer.")
break
except Exception as e:
logging.error(f"Sending frame to Object Recognizer failed: {e}")
time.sleep(1)
continue continue
orclient_socket.close()
md_detected_motion.set(0)
processing_time.set(time.time() - starting_processing_time)
logging.debug("Processing time logged for frame.")
starting_processing_time = time.time()
fps_frame_count += 1
elapsed_time = time.time() - fps_start_time
if elapsed_time >= 10.0:
fps = round(fps_frame_count / elapsed_time, 2)
fps_count.set(fps)
logging.info(f"FPS: {fps}")
fps_frame_count = 0
fps_start_time = time.time()
frameDelta = cv2.absdiff(firstFrame, gray)
thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations=2)
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
detected_cnt = 0
detected = False
for c in cnts:
if cv2.contourArea(c) < 10000:
continue
detected = True
detected_cnt += 1
logging.debug(f"Motion detected. Contour area: {cv2.contourArea(c)}.")
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
text = "md: motion detected"
if detected:
logging.info("Motion detected, preparing to send frame to Object Recognizer.")
md_detected_motion.set(1)
orclient_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
orclient_socket.connect((or_host_ip, or_port))
ordata = {
"frame": frame,
"capture_time": recieveddata["capture_time"],
"sentfromedgetime": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'carrier':carrier
}
while True:
try:
a = pickle.dumps(ordata)
message = struct.pack("Q", len(a)) + a
logging.info(f"Packet size: {len(message)} bytes.") # Log the size of the packet
orclient_socket.sendall(message)
logging.info("Frame successfully sent to Object Recognizer.")
break
except Exception as e:
logging.error(f"Sending frame to Object Recognizer failed: {e}")
time.sleep(1)
continue
orclient_socket.close()
md_detected_motion.set(0)
processing_time.set(time.time() - starting_processing_time)
logging.debug("Processing time logged for frame.")
except Exception as e:
logging.error(f"Error processing frame: {e}")
break
def main(): def main():
# Retrieve environment variables instead of command-line arguments # Retrieve environment variables instead of command-line arguments
......
...@@ -33,7 +33,7 @@ otlp_trace_exporter = OTLPSpanExporter(endpoint="otel-collector:4317", insecure= ...@@ -33,7 +33,7 @@ otlp_trace_exporter = OTLPSpanExporter(endpoint="otel-collector:4317", insecure=
trace.get_tracer_provider().add_span_processor( trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(otlp_trace_exporter) BatchSpanProcessor(otlp_trace_exporter)
) )
tracer = trace.get_tracer("md tracer") tracer = trace.get_tracer("motion detector tracer")
# Set up the meter provider for metrics # Set up the meter provider for metrics
meter_provider = MeterProvider() meter_provider = MeterProvider()
...@@ -49,4 +49,4 @@ reader = PeriodicExportingMetricReader( ...@@ -49,4 +49,4 @@ reader = PeriodicExportingMetricReader(
) )
meterProvider = MeterProvider(resource=resource, metric_readers=[reader]) meterProvider = MeterProvider(resource=resource, metric_readers=[reader])
metrics.set_meter_provider(meterProvider) metrics.set_meter_provider(meterProvider)
meter = metrics.get_meter("md meter") meter = metrics.get_meter("motion detector meter")
\ No newline at end of file \ No newline at end of file
...@@ -6,10 +6,10 @@ import pickle ...@@ -6,10 +6,10 @@ import pickle
import struct import struct
import cv2 import cv2
import logging import logging
from opentelemetry.propagate import extract
from model.model import recognize from model.model import recognize
from webserver import run_flask from webserver import run_flask
from telemetry.tracerprovider import meter from telemetry.tracerprovider import meter, tracer
# Configure logging # Configure logging
logging.basicConfig( logging.basicConfig(
...@@ -48,7 +48,12 @@ def draw_prediction(img, class_id, confidence, x, y, x_plus_w, y_plus_h, classes ...@@ -48,7 +48,12 @@ def draw_prediction(img, class_id, confidence, x, y, x_plus_w, y_plus_h, classes
def process_frame(mddata): def process_frame(mddata):
recognize(mddata['frame']) received_carrier = mddata['carrier']
extracted_context = extract(received_carrier)
carrier = {}
with tracer.start_as_current_span("detecting motion in the frame", context=extracted_context) as span:
recognize(mddata['frame'])
def receive_frames(client_socket, frame_queue): def receive_frames(client_socket, frame_queue):
data = b"" data = b""
......
from flask import Flask, send_file from flask import Flask, send_file, render_template_string
import threading
import os import os
import time
# Flask application setup # Flask application setup
app = Flask(__name__) app = Flask(__name__)
IMAGE_PATH = "/app/output/res.jpg" IMAGE_PATH = "/app/output/res.jpg"
# Disable browser caching by adding cache headers # Disable browser caching by adding cache headers
@app.after_request @app.after_request
def add_no_cache_headers(response): def add_no_cache_headers(response):
response.cache_control.no_store = True response.cache_control.no_store = True
return response return response
@app.route("/") @app.route("/")
def home(): def home():
return "<h1>Object Recognizer</h1><p>Go to <a href='/image'>/image</a> to see the latest detection.</p>" return "<h1>Object Recognizer</h1><p>Go to <a href='/image'>/image</a> to see the latest detection.</p>"
@app.route("/image") @app.route("/image")
def serve_image(): def serve_image():
if os.path.exists(IMAGE_PATH): if os.path.exists(IMAGE_PATH):
return send_file(IMAGE_PATH, mimetype='image/jpeg') html_template = """
<!DOCTYPE html>
<html>
<head>
<title>Object Recognizer</title>
<script>
// Refresh the image every 5 seconds
function refreshImage() {
const image = document.getElementById('image');
image.src = '/static_image?' + new Date().getTime(); // Append timestamp to bypass cache
}
// Update the date-time every second
function updateDateTime() {
const now = new Date();
document.getElementById('datetime').innerText = now.toLocaleString();
}
setInterval(refreshImage, 5000); // Refresh every 5 seconds
setInterval(updateDateTime, 1000); // Update date-time every second
</script>
</head>
<body>
<h1>Object Recognizer</h1>
<p id="datetime"></p>
<img id="image" src="/static_image" alt="Latest detection" width="600">
</body>
</html>
"""
return render_template_string(html_template)
else: else:
return "<h1>No image available</h1>", 404 return "<h1>No image available</h1>", 404
@app.route("/static_image")
def static_image():
if os.path.exists(IMAGE_PATH):
return send_file(IMAGE_PATH, mimetype='image/jpeg')
else:
return "", 404
# Flask server runner # Flask server runner
def run_flask(): def run_flask():
app.run(host="0.0.0.0", port=5000, debug=False, threaded=True) app.run(host="0.0.0.0", port=5000, debug=False, threaded=True)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment