You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
4.7 KiB
Markdown

# Monitor
## Introduction
Monitor is part of ReCodEx solution for reporting progress of job evaluation back to user in the real time. It gets progress notifications from broker and sends them through WebSockets to clients' browsers. For now, it's meant as an optional part of whole solution, but for full experince it's recommended to use one.
Monitor is one per broker, that is one per separate ReCodEx instance. Also, monitor has to be publicly visible (has to have public IP address) and also needs a connection to the broker.
## Architecture
Monitor is written in Python, tested versions are 3.4 and 3.5. For it's functionality following packages are required:
- zmq - binding to ZeroMQ framework
- websockets - framework for communication over WebSockets
- asyncio - library for fast asynchronous operations
- pyyaml - parsing YAML configuration files
- argparse - parsing command line arguments
**Monitor's architecture and message flow describes following diagram:**
![Monitor message flow](https://raw.githubusercontent.com/ReCodEx/GlobalWiki/master/images/Monitor_arch.png)
There are 2 threads - _Thread 1_ is main thread, which initializes all components like logger or starts the other thread and then runs the ZeroMQ part of the application. _Thread 2_ is responsible for managing all of WebSocket connections asynchronously. Whole thread is one big _asyncio_ event loop through which are processed all actions. None of custom data types is thread-safe, so all events from other threads (actually only `send_message` method) must be called within the event loop (via `asyncio.loop.call_soon_threadsafe` function). Please note, that most of the Python interpreter use GIL ([Global Interpreter Lock](https://wiki.python.org/moin/GlobalInterpreterLock)), so there is actualy no parallelism in the performance view, but proper synchronization is still required!
## Installation
Installation will provide you with following files:
- `/usr/bin/recodex-monitor` - simple startup script located in PATH
- `/etc/recodex/monitor/config.yml` - configuration file
- `/etc/systemd/system/recodex-monitor.service` - systemd startup script
- code files will be installed in location depending on your settings, mostly into `/usr/lib/python3.5/site-packages/monitor/` or similar
Systemd script runs monitor binary as specific _recodex_ user, so in `postinst` script user and group of this name are created. Also, ownership of configuration file will be granted to that user.
Make sure to allow TCP connection to WebSocket address and port specified in configuration in your firewall. Otherwise, monitor won't work.
**Fedora (and other RPM distributions):**
- run `python3 setup.py bdist_rpm --post-install ./install/postints` to generate binary `.rpm` package or download it from releases tab of monitor GitHub repository (it's architecture independent package)
- install package using `sudo dnf install ./dist/recodex-monitor-0.1.0-1.noarch.rpm` (number depends on actual version)
**Other Linux systems:**
- run installation as `python3 setup.py install --install-scripts /usr/bin`
- run postinst script as root - `sudo ./install/postinst`
## Configuration
Configuration file is located in subdirectory `monitor` of standard ReCodEx configuration folder `/etc/recodex/`. It's in YAML format as all of the other configurations. Format is very similar to configurations of broker or workers. Example configuration file is here:
```{.yml}
---
websocket_uri:
- "127.0.0.1"
- 4567
zeromq_uri:
- "127.0.0.1"
- 7894
logger:
file: "/var/log/recodex/monitor.log"
level: "debug"
max-size: 1048576 # 1 MB
rotations: 3
...
```
### Configuration items
- **websocket_uri** - URI where is the endpoint of websocket connection. Must be publicly visible!
- string representation of IP address or a hostname
- port number
- **zeromq_uri** - URI where is the endpoint of zeromq connection from broker. Could be hidden from public internet.
- string representation of IP address or a hostname
- port number
- **logger** - settings of logging
- **file** - path with name of log file. Defaults to `/var/log/recodex/monitor.log`
- **level** - logging level, one of "debug", "info", "warning", "error" and "critical"
- **max-size** - maximum size of log file before rotation in bytes
- **rotations** - number of rotations kept
## Usage
Preferred way to start monitor as a service is via systemd as `sudo systemctl start recodex-monitor.service`. After that, check if application lauch was successful using `sudo systemctl status recodex-monitor.service`. Now you should see green **Active (running)**.
Alternative starting command is `recodex-monitor -c /etc/recodex/monitor/config.yml` from command line. But note that it won't start monitor as a daemon.