Package: tlr
tlrOverviewtlris a package that act as a service for VOGAMOS (Volcanic Gas Monitoring
System) data acquisition. It listens for data from telnet server, parse the
data, and store it to the database server.Deployment GuideClone the project from GitLab repository server:git clone https://gitlab.com/bpptkg/tlr.gitThen, change directory to the tlr root directory:cd tlr/First, install Python virtual environment, pip, and MySQL library:sudo apt install python-virtualenv python3-pip python3-dev libmysqlclient-devMake Python virtual environment and activate the virtual environment:virtualenv -p python3 venv
source venv/bin/activateInstall all package requirements:pip install -r requirements.txtThen, copy project settings from.env.examplefile:cp .env.example .envSet some important settings, includingDATABASE_ENGINE,TELNET_HOST,TELNET_PORT,TELNET_TIMEOUT, andSENTRY_DSN. Don't forget to setDEBUGtoFalseif used in the production environment.If database table isn't migrated yet, you can run database migration by
executing this command:./bin/migrateInstall Supervisord. We will use it to monitor script daemon process:sudo apt install supervisorCopy Supervisord tlr configuration fromsupervisor/directory:sudo cp supervisor/tlr.conf /etc/supervisor/conf.d/Edit/etc/supervisor/conf.d/tlr.confaccording to your need:[program:tlr]
directory=/path/to/tlr
command=bash -c "source /path/to/tlr/venv/bin/activate && /path/to/tlr/run.py"
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/tlr.log
stderr_logfile=/var/log/supervisor/tlr_error.log
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8

[group:tlr]
programs:tlrIn the configuration above, we start the service using the command:bash -c "source /path/to/tlr/venv/bin/activate && /path/to/tlr/run.py"It will start the service within Python virtual environment and make sure that
we have only one process running.Reread and update Supervisord configuration:sudo supervisorctl reread
sudo supervisorctl updateYou can view Supervisord status by running this command:sudo supervisorctl statusFinally, monitor your database if data has been stored.Monitoring for ErrorsIf any error occurred, you can see the error from the log file instorage/logs/tlr.log(logging directory may be different if you use customLOGGING_ROOT), from Supervisord log (/var/log/supervisor/tlr_error.log), or
fromSentryweb interface.Viewing error logs from Supervisord is basically good to debug system-related
errors. In addition to that, viewing from Sentry web is recommended to track
errors in the application level.Applying Code UpdatesFirst, tap into deployment server viasshor any other ways. Then, pull
updates from GitLab repository:cd /path/to/tlr/
git pullRestart tlr service:sudo supervisorctl restart tlrIf you ever modify tlr configuration in/etc/supervisor/conf.d/tlr.conf, you
have to reread and update the service:sudo supervisorctl reread
sudo supervisorctl updateDeveloper ReferenceAfter cloning the project and creating Python virtual environment, install all
development package requirements:pip install -r dev-requirements.txtBefore submitting your changes to our GitLab repository, write unit test in thetests/directory. You can run all unit tests to see if your test has passed by
runningpytestcommand:pytestMain script entry point isrun.py. You can run the script by executing this
command:python run.pyNote that you have to run the script within your Python virtual environment.Installing tlr LibraryIf you want to access tlr API, you can install the package from PyPI:pip install -U tlrExample:fromtlr.parserimportT1Parserfromtlr.utilsimportforce_str# Data from telner serverbytes_data=b'T#01 56.92,\r\nT#03 88.10,90.62,90.42,29.68,14.39\r\n\r\nC\xfc'# Decode raw data to ordinary string formatstr_data=force_str(bytes_data,errors='backslashreplace')# Create a parser objectdata_parser=T1Parser()# Parse the datacleaned_data=data_parser.parse_as_dict(str_data)# Print cleaned dataprint(cleaned_data)Output:[{'temperature': 56.92}]ContributingSeeCONTRIBUTING.mdto learn how to contribute to this project.SupportThis project is maintained by Indra Rudianto. If you have any question about
this project, you can contact him atindrarudianto.official@gmail.com.LicenseBy contributing to the project, you agree that your contributions will be
licensed under its MIT license. SeeLICENSEfor details.