Standalone
Standalone mode only deploys the Python script. You should install and configure Prometheus and Grafana (or another tools if you want) by yourself to have the stack described in the Design section.
You can use virtualenv to install and run the app in an isolated environment
Requirements
- Windows, Linux or macOS
- Python3 (version 3.8, 3.9 and 3.10 are tested)
Preparing Steps
-
Download the source code of the project from the latest release and extract it.
-
Move to the downloaded folder and execute this command in app folder:
python3 -m pip install -r requirements.txt
- Write a
config.yaml
(name can't be changed) following this doc in one of the following paths :
- Linux
- Windows
- MacOs
- ~/.config/app/SuiviBourse
- /etc/app/SuiviBourse
- %APPDATA%\app\SuiviBourse (APPDATA environment variable falls back to %HOME%\AppData\Roaming if undefined)
- ~/.config/app/SuiviBourse
- ~/Library/Application Support/app/SuiviBourse
To know more about config file location, please refer to the confuse library documentation
Running the app
You can simply run the app with the following command inside the project's root folder :
python3 app/src/main.py
However, we recommend chosing between the following methods to run the standalone app in production.
Replace <installation_path> with the path of the folder where you download and extract the project folder (see step 1 of preparing step)
- SystemD (Linux)
- Cron (Linux + MacOS)
- Windows Service
Almost all versions of Linux come with systemd out of the box, but if your’s didn’t come with it then you can simply install it. You should have a regular, non-root user with sudo privileges configured or access to root user to perform this.
Replace <user> and <group> with the user and the group of the user with whom you ran the step 2.
-
Create a user service unit file in
/etc/systemd/system/suivi-bourse.service
:[Unit]
Description=SuiviBourse
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python3 <installation_path>/app/src/main.py
User=<user>
Group=<group>
Environment=PYTHONUNBUFFERED=1
SyslogIdentifier=suivi-bourse
[Install]
WantedBy=default.target -
Reload systemd-daemon:
systemctl daemon-reload
-
Enable the service at boot:
systemctl enable suivi-bourse
-
Start the service:
systemctl start suivi-bourse
You can see the application logs in /var/log/syslog
and check the status with systemctl status suivi-bourse
Using cron and nohup command, you can run the application at boot in foreground:
-
Edit your crontab:
crontab -e
-
Add the following line:
@reboot nohup python3 <installation_path>/app/src/main.py > suivi-bourse.log
-
Run the following command or
reboot
your machine to start the script:nohup python3 <installation_path>/app/src/main.py > suivi-bourse.log &
The application logs path will be $HOME/suivi-bourse.log
I don't have any Windows machine to test it. Open a Github PR to complete this section.
Environment variables
Env variables can be used to override some default parameters :
ENV | Description | Default Value |
---|---|---|
SB_METRICS_PORT | Port TCP used to expose data | 8081 |
SB_SCRAPING_INTERVAL | Interval in seconds where app gets data from Yahoo! Finance API | 120 |
LOG_LEVEL | App log level | INFO |
Prometheus configuration
Add a static config to your Prometheus instance, to scrape data expoed by the app. Below, an example of configuration :
scrape_configs:
- job_name: 'suivi-bourse'
scrape_interval: '120s'
static_configs:
- targets: ['localhost:8081']
Grafana dashboard
Depending on your Grafana version, you can add this dashboard to vizualise app metrics :
From Version 9.x, the dashboard uses the Candlestick panel instead of the TimeSeries panel