Comments (13)
@lukenuyen02 You need to specify the container name when you run stream_monitor.py
like so:
python3 stream_monitor.py -c focused_dubinsky
Get your container name by running docker ps
command in terminal
from deep-license-plate-recognition.
@lukenuyen02 You need to specify the container name when you run
stream_monitor.py
like so:python3 stream_monitor.py -c focused_dubinskyGet your container name by running
docker ps
command in terminal
You can not just close the ticket like this. please reopen the Ticket. Even with container the issue is still persist
from deep-license-plate-recognition.
@marcbelmont @danleyb2 I would like to reopen the issue ticket please.
from deep-license-plate-recognition.
@lukenuyen02 What is your stream container name? I tested the script and it works as expected for me with 1 camera
from deep-license-plate-recognition.
@danleyb2 with 1 camera, yes its working, but not with Multiple
my container name is stream as the script is already define it as the default value.
from deep-license-plate-recognition.
@lukenuyen02 I have been unable to reproduce this with multiple cameras.
Do the cameras startup okay and there is newer log from Stream container showing the health score?
Try enabling debug logging from the monitor script by setting the env variable like so export LOGGING=DEBUG
from deep-license-plate-recognition.
@danleyb2 everything looks good
support@ia-88aedd0bb29d:~$ sudo docker logs --tail 10 stream
INFO:3cc21d76-3a34-4794-8851-7c1c50bb29b5:2023-05-24T17:44:14+00:00: Health Score: 100%
INFO:3d92981d-5344-4e0c-8734-181b7a8cd7c0:2023-05-24T17:44:17+00:00: Health Score: 95%
INFO:3cc21d76-3a34-4794-8851-7c1c50bb29b5:2023-05-24T17:44:19+00:00: Health Score: 100%
INFO:3d92981d-5344-4e0c-8734-181b7a8cd7c0:2023-05-24T17:44:22+00:00: Health Score: 95%
INFO:3d92981d-5344-4e0c-8734-181b7a8cd7c0:2023-05-24T17:44:23+00:00: New vehicle: jys2511
INFO:3cc21d76-3a34-4794-8851-7c1c50bb29b5:2023-05-24T17:44:24+00:00: Health Score: 100%
INFO:3d92981d-5344-4e0c-8734-181b7a8cd7c0:2023-05-24T17:44:27+00:00: Health Score: 95%
INFO:3cc21d76-3a34-4794-8851-7c1c50bb29b5:2023-05-24T17:44:29+00:00: Health Score: 100%
INFO:3d92981d-5344-4e0c-8734-181b7a8cd7c0:2023-05-24T17:44:33+00:00: Health Score: 95%
INFO:3cc21d76-3a34-4794-8851-7c1c50bb29b5:2023-05-24T17:44:35+00:00: Health Score: 100%
would you like to my version of the stream_monitor.py so you can compare and test? i
from deep-license-plate-recognition.
@lukenuyen02 yes please share
from deep-license-plate-recognition.
# python stream_monitor.py --help
# python stream_monitor.py -c stream -i 30 -d 120
import re
import os
import time
import logging
import sys
import threading
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
import subprocess
from functools import partial
from datetime import datetime, timedelta
from django.core.management.base import BaseCommand
LOG_LEVEL = os.environ.get('LOGGING', 'INFO').upper()
logging.basicConfig(
stream=sys.stdout,
level=LOG_LEVEL,
format='%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
_state = {'container_active': False, 'last_log_times': {}}
log_line_regex = r'(\w+):([^:]*):(.*):\b'
compiled = re.compile(log_line_regex)
class GetHandler(BaseHTTPRequestHandler):
def __init__(self, offline_diff_duration, *args, **kwargs):
self.offline_diff_duration = offline_diff_duration
super().__init__(*args, **kwargs)
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
logging.debug('state: ')
logging.debug(_state)
online_time = datetime.now() - timedelta(
seconds=self.offline_diff_duration)
response = {'active': _state['container_running']}
cameras = {}
for k, v in _state['last_log_times'].items():
logging.debug(f'Comparing times: [{v}] and [{online_time}]')
if online_time < v:
cameras[k] = {"status": "running"}
else:
cameras[k] = {"status": "offline"}
response['cameras'] = cameras
logging.debug('response')
logging.debug(response)
self.wfile.write(json.dumps(response).encode())
self.wfile.write(b'\n')
def parse_log_line(line):
"""
:param line: Stream log line
:return: Log split into [level, camera, time]
"""
m = re.match(log_line_regex, line)
if m:
groups = m.groups()
return [groups[0], groups[1], groups[2]]
def monitor_worker(container_name, check_interval):
captures = 0
previous_log_time = None
while True:
result = subprocess.run(
['docker', 'logs', '--tail', '1', container_name],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
docker_log = result.stdout.decode('utf-8')
logging.debug(f'docker_log: {docker_log}')
if 'No such container' in docker_log:
_state['container_running'] = False
time.sleep(check_interval)
continue
else:
_state['container_running'] = True
if len(docker_log) > 0:
log_line = parse_log_line(docker_log)
logging.debug(f'log_line: {log_line}')
if log_line:
log_time = log_line[2]
if previous_log_time and log_time == previous_log_time:
logging.debug('No new logs detected')
else:
camera = log_line[1]
_state['last_log_times'][camera] = datetime.now()
captures += 1
previous_log_time = log_time
else:
logging.debug('Log line empty')
time.sleep(check_interval)
logging.debug(f'Captures: {captures}')
def server_worker(host, port, offline_diff_duration):
handler = partial(GetHandler, offline_diff_duration)
server = HTTPServer((host, port), handler)
logging.info('Starting server, use <Ctrl-C> to stop')
server.serve_forever()
class Command(BaseCommand):
help = "Monitor Stream HEALTH through it's logs. " \
"Exposes a single API endpoint that returns the Camera Status:"
def add_arguments(self, parser):
parser.add_argument("-c",
"--container",
type=str,
default='stream',
help="Stream Container Name or ID")
# Server listening HOST and PORT
parser.add_argument("-l",
"--listen",
type=str,
default='localhost',
help="Server listen address")
parser.add_argument("-p",
"--port",
type=int,
default=8002,
help="Server listen port")
# Check Interval
parser.add_argument("-i",
"--interval",
type=int,
default=2,
help="Interval between reading logs in seconds")
# Active Duration
parser.add_argument(
"-d",
"--duration",
type=int,
default=20,
help="Duration to use in considering a camera as "
"offline in seconds")
def handle(self, *args, **options):
# Container Name
monitor = threading.Thread(target=monitor_worker,
args=(
options['container'],
options['interval']
))
server = threading.Thread(target=server_worker,
args=(
options['listen'],
options['port'],
options['duration'],
))
monitor.start()
server.start()
from deep-license-plate-recognition.
@lukenuyen02 Your version of the script works but doesn't list all the cameras. kindly try this instead:
# python stream_monitor.py --help
# python stream_monitor.py -c stream -i 30 -d 120
import re
import os
import time
import logging
import sys
import threading
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
import subprocess
from functools import partial
from datetime import datetime, timedelta
from django.core.management.base import BaseCommand
LOG_LEVEL = os.environ.get('LOGGING', 'INFO').upper()
logging.basicConfig(
stream=sys.stdout,
level=LOG_LEVEL,
format='%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
_state = {'container_active': False, 'last_log_times': {}}
log_line_regex = r'(\w+):([^:]*):(.*):\b'
compiled = re.compile(log_line_regex)
class GetHandler(BaseHTTPRequestHandler):
def __init__(self, offline_diff_duration, *args, **kwargs):
self.offline_diff_duration = offline_diff_duration
super().__init__(*args, **kwargs)
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
logging.debug('state: ')
logging.debug(_state)
online_time = datetime.now() - timedelta(
seconds=self.offline_diff_duration)
response = {'active': _state['container_running']}
cameras = {}
for k, v in _state['last_log_times'].items():
logging.debug(f'Comparing times: [{v}] and [{online_time}]')
if online_time < v:
cameras[k] = {"status": "running"}
else:
cameras[k] = {"status": "offline"}
response['cameras'] = cameras
logging.debug('response')
logging.debug(response)
self.wfile.write(json.dumps(response).encode())
self.wfile.write(b'\n')
def parse_log_line(line):
"""
:param line: Stream log line
:return: Log split into [level, camera, time]
"""
m = re.match(log_line_regex, line)
if m:
groups = m.groups()
return [groups[0], groups[1], groups[2]]
def monitor_worker(container_name, check_interval):
captures = 0
previous_log_time = None
while True:
result = subprocess.run(
['docker', 'logs', '--tail', '10', container_name],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
docker_log = result.stdout.decode('utf-8')
logging.debug(f'docker_log: {docker_log}')
if 'No such container' in docker_log:
_state['container_running'] = False
time.sleep(check_interval)
continue
else:
_state['container_running'] = True
if len(docker_log) > 0:
for line in docker_log.splitlines():
log_line = parse_log_line(line)
logging.debug(f'log_line: {log_line}')
if log_line:
log_time = log_line[2]
if previous_log_time and log_time == previous_log_time:
logging.debug('No new logs detected')
else:
camera = log_line[1]
_state['last_log_times'][camera] = datetime.now()
captures += 1
previous_log_time = log_time
else:
logging.debug('Log line empty')
time.sleep(check_interval)
logging.debug(f'Captures: {captures}')
def server_worker(host, port, offline_diff_duration):
handler = partial(GetHandler, offline_diff_duration)
server = HTTPServer((host, port), handler)
logging.info('Starting server, use <Ctrl-C> to stop')
server.serve_forever()
class Command(BaseCommand):
help = "Monitor Stream HEALTH through it's logs. " \
"Exposes a single API endpoint that returns the Camera Status:"
def add_arguments(self, parser):
parser.add_argument("-c",
"--container",
type=str,
default='stream',
help="Stream Container Name or ID")
# Server listening HOST and PORT
parser.add_argument("-l",
"--listen",
type=str,
default='localhost',
help="Server listen address")
parser.add_argument("-p",
"--port",
type=int,
default=8002,
help="Server listen port")
# Check Interval
parser.add_argument("-i",
"--interval",
type=int,
default=2,
help="Interval between reading logs in seconds")
# Active Duration
parser.add_argument(
"-d",
"--duration",
type=int,
default=20,
help="Duration to use in considering a camera as "
"offline in seconds")
def handle(self, *args, **options):
# Container Name
monitor = threading.Thread(target=monitor_worker,
args=(
options['container'],
options['interval']
))
server = threading.Thread(target=server_worker,
args=(
options['listen'],
options['port'],
options['duration'],
))
monitor.start()
server.start()
from deep-license-plate-recognition.
@danleyb2 I will test this as soon as possible. if you dont heard back from for 1 or 2 days you can close the ticket
Thank you in advance for your time and assistance
from deep-license-plate-recognition.
@lukenuyen02 if it doesn't work let's jump on screen share session. It will make it easier
from deep-license-plate-recognition.
@lukenuyen02 I can confirm the code i had shared or this PR fixes the issue you were having with multiple cameras.
#125
I'll close the issue and we can re-open another if you still facing it
from deep-license-plate-recognition.
Related Issues (20)
- Django CSFR Error HOT 8
- FFMPEGCV cannot process grayscale videos HOT 2
- FFMPEGCV incorrectly reads video fps as 60 most of the time HOT 9
- Error With .asf Video Format
- Response to the use of ffmpegcv in the code HOT 2
- Need Help HOT 4
- An error occurs during recognition
- Reorder docker folder HOT 1
- stream_monitor.py ignores log content HOT 2
- How to reduce confidence threshold for lpr reading? HOT 1
- Contact page at PlateRecognizer.com is not working HOT 1
- PlateRecognizer-Installer.exe detected as malware HOT 1
- issue localhost port 8080: Connection refused HOT 18
- Incorrect total_calls (hardcoded to 2500) HOT 1
- Docker run failing with `Low disk space. Make sure to have at least 100MB of free disk space.` error HOT 18
- What is the license for self hosted docker image HOT 3
- Installer cannot run Docker.
- Merge sftp_processor.py and ftp_processor.py HOT 6
- stream_monitor.py not reliable for multiple cameras HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deep-license-plate-recognition.