2019-05-20 11:35:47 -05:00
# Dispatcher Service
> Status: Release Candidate
2020-05-12 22:39:44 +02:00
The LibreNMS dispatcher service (`librenms-service.py` ) is a new method
2021-06-17 03:16:21 +08:00
of running the poller service at set times. It does not replace the php scripts,
2020-05-12 22:39:44 +02:00
just the cron entries running them.
2019-05-20 11:35:47 -05:00
2021-07-10 03:34:01 +08:00
## External Requirements
2019-05-20 11:35:47 -05:00
2021-07-10 03:34:01 +08:00
### A recent version of Python
2019-09-09 05:48:35 -05:00
The LibreNMS service requires Python 3 and some features require
behaviour only found in Python3.4+.
2021-07-10 03:34:01 +08:00
### Python modules
2019-09-09 05:48:35 -05:00
- PyMySQL is recommended as it requires no C compiler to
install. MySQLclient can also be used, but does require compilation.
- python-dotenv .env loader
2023-04-14 13:11:44 +01:00
- redis-py 4.0+ and Redis 5.0+ server (if using distributed polling)
2020-09-30 05:50:40 +01:00
- psutil
2019-05-20 11:35:47 -05:00
These can be obtained from your OS package manager, or from PyPI with the below commands.
2019-09-09 05:48:35 -05:00
2019-05-20 11:35:47 -05:00
```bash
pip3 install -r requirements.txt
```
2021-07-10 03:34:01 +08:00
### Redis (distributed polling)
2019-05-20 11:35:47 -05:00
2019-09-09 05:48:35 -05:00
If you want to use distributed polling, you'll need a Redis instance
to coordinate the nodes. It's recommended that you do not share the
Redis database with any other system - by default, Redis supports up
to 16 databases (numbered 0-15). You can also use Redis on a single host if you want
2019-05-20 11:35:47 -05:00
2019-09-09 05:48:35 -05:00
It's strongly recommended that you deploy a resilient cluster of redis
systems, and use redis-sentinel.
2019-05-20 11:35:47 -05:00
2019-09-09 05:48:35 -05:00
You should not rely on the password for the security of your
system. See <https://redis.io/topics/security>
2019-05-20 11:35:47 -05:00
2021-07-10 03:34:01 +08:00
### Memcached (distributed polling)
2019-10-21 01:15:25 +02:00
2020-12-12 19:02:11 +02:00
LibreNMS can still use memcached as a locking mechanism when using
distributed polling. So you can configure memcached for this purpose
2021-06-17 03:16:21 +08:00
unless you have updates disabled.
2020-12-12 19:02:11 +02:00
See `Locking Mechanisms` at
<https://docs.librenms.org/Extensions/Distributed-Poller/>
2019-10-21 01:15:25 +02:00
2021-07-10 03:34:01 +08:00
### MySQL
2019-05-20 11:35:47 -05:00
2019-09-09 05:48:35 -05:00
You should already have this, but the pollers do need access to the
SQL database. The LibreNMS service runs faster and more aggressively
than the standard poller, so keep an eye on the number of open
connections and other important health metrics.
2019-05-20 11:35:47 -05:00
2021-07-10 03:34:01 +08:00
## Configuration
2019-09-09 05:48:35 -05:00
Connection settings are required in `.env` . The `.env` file is
2020-12-30 09:38:14 -05:00
generated after composer install and `APP_KEY` and `NODE_ID` are set.
2020-05-12 22:39:44 +02:00
Remember that the APP_KEY value must be the same on all your pollers.
2019-05-20 11:35:47 -05:00
```dotenv
#APP_KEY= #Required, generated by composer install
#NODE_ID= #Required, generated by composer install
DB_HOST=localhost
DB_DATABASE=librenms
DB_USERNAME=librenms
DB_PASSWORD=
```
2021-07-10 03:34:01 +08:00
### Distributed Polling Configuration
2019-05-20 11:35:47 -05:00
2020-10-07 07:36:35 -05:00
Once you have your Redis database set up, configure it in the .env file on each node. Configure the redis cache driver for distributed locking.
2019-05-20 11:35:47 -05:00
2023-04-14 13:11:44 +01:00
There are a number of options - most of them are optional if your redis instance is standalone and unauthenticated (neither recommended).
2019-05-20 11:35:47 -05:00
```dotenv
2023-04-14 13:11:44 +01:00
##
## Standalone
##
2019-05-20 11:35:47 -05:00
REDIS_HOST=127.0.0.1
2019-10-01 01:51:07 -05:00
REDIS_PORT=6379
REDIS_DB=0
2023-04-14 13:11:44 +01:00
REDIS_TIMEOUT=60
# If requirepass is set in redis set everything above as well as: (recommended)
REDIS_PASSWORD=PasswordGoesHere
# If ACL's are in use, set everything above as well as: (highly recommended)
REDIS_USERNAME=UsernameGoesHere
2020-10-07 07:36:35 -05:00
2023-04-14 13:11:44 +01:00
##
## Sentinel
##
REDIS_SENTINEL=redis-001.example.org:26379,redis-002.example.org:26379,redis-003.example.org:26379
REDIS_SENTINEL_SERVICE=mymaster
# If requirepass is set in sentinel, set everything above as well as: (recommended)
REDIS_SENTINEL_PASSWORD=SentinelPasswordGoesHere
# If ACL's are in use, set everything above as well as: (highly recommended)
REDIS_SENTINEL_USERNAME=SentinelUsernameGoesHere
2019-05-20 11:35:47 -05:00
```
2023-04-14 13:11:44 +01:00
For more information on ACL's, see <https://redis.io/docs/management/security/acl/>
Note that if you use Sentinel, you may still need `REDIS_PASSWORD` , `REDIS_USERNAME` , `REDIS_DB` and `REDIS_TIMEOUT` - Sentinel just provides the address of the instance currently accepting writes and manages failover. It's possible (and recommended) to have authentication both on Sentinel and the managed Redis instances.
2021-07-10 03:34:01 +08:00
### Basic Configuration
2019-05-20 11:35:47 -05:00
2023-05-11 01:05:12 +01:00
Additional configuration settings can be set in your config.
2019-05-20 11:35:47 -05:00
2019-09-09 05:48:35 -05:00
The defaults are shown here - it's recommended that you at least tune
the number of workers.
2019-05-20 11:35:47 -05:00
2023-05-11 01:05:12 +01:00
!!! setting "poller/distributed"
```bash
lnms config:set service_poller_workers 24
lnms config:set service_services_workers 8
lnms config:set service_discovery_workers 16
```
Optional Settings
!!! setting "poller/distributed"
```bash
lnms config:set service_poller_frequency 300
lnms config:set service_services_frequency 300
lnms config:set service_discovery_frequency 21600
lnms config:set service_billing_frequency 300
lnms config:set service_billing_calculate_frequency 60
lnms config:set service_poller_down_retry 60
lnms config:set service_loglevel INFO
lnms config:set service_update_frequency 86400
```
2019-05-20 11:35:47 -05:00
2019-09-09 05:48:35 -05:00
There are also some SQL options, but these should be inherited from
your LibreNMS web UI configuration.
2019-05-20 11:35:47 -05:00
2019-09-09 05:48:35 -05:00
Logs are sent to the system logging service (usually `journald` or
`rsyslog` ) - see
<https://docs.python.org/3/library/logging.html#logging -levels> for the
options available.
2019-05-20 11:35:47 -05:00
```php
2020-05-22 09:16:56 +10:00
$config['distributed_poller'] = true; # Set to true to enable distributed polling
$config['distributed_poller_name'] = php_uname('n'); # Uniquely identifies the poller instance
$config['distributed_poller_group'] = 0; # Which group to poll
2019-05-20 11:35:47 -05:00
```
2020-03-19 12:41:54 +01:00
### Tuning the number of workers
2021-06-17 03:16:21 +08:00
See https://your_librenms_install/poller
2020-03-19 12:41:54 +01:00
You want to keep Consumed Worker Seconds comfortably below Maximum Worker Seconds. The closer the values are to each other, the flatter the CPU graph of the poller machine. Meaning that you are utilizing your CPU resources well. As long as Consumed WS stays below Maximum WS and Devices Pending is 0, you should be ok.
If Consumed WS is below Maximum WS and Devices Pending is > 0, your hardware is not up to the task.
Maximum WS equals the number of workers multiplied with the number of seconds in the polling period. (default 300)
2019-05-20 11:35:47 -05:00
2021-07-10 03:34:01 +08:00
## Fast Ping
2019-09-09 05:48:35 -05:00
The [fast ping ](Fast-Ping-Check.md ) scheduler is disabled by default.
You can enable it by setting the following:
2019-05-20 11:35:47 -05:00
```php
$config['service_ping_enabled'] = true;
```
2021-07-10 03:34:01 +08:00
## Watchdog
2020-03-31 21:10:45 -07:00
The watchdog scheduler is disabled by default. You can enable it by setting the following:
```php
$config['service_watchdog_enabled'] = true;
```
The watchdog scheduler will check that the poller log file has been written to within the last poll period. If there is no change to the log file since, the watchdog will restart the polling service. The poller log file is set by `$config['log_file']` and defaults to `./logs/librenms.log`
2021-07-10 03:34:01 +08:00
## Cron Scripts
2019-09-09 05:48:35 -05:00
2024-05-08 14:33:47 +02:00
Once the LibreNMS service is installed, the cron scripts used by LibreNMS to start alerting, polling, discovery and maintenance tasks are no longer required and must be disabled either by removing or commenting them out. The service handles these tasks when enabled.
2019-09-09 05:48:35 -05:00
2021-07-10 03:34:01 +08:00
## Service Installation
2019-09-09 05:48:35 -05:00
2022-11-22 13:54:04 +01:00
A systemd unit file is provided - You must adapt `ExecStart` and `WorkingDirectory` if you did not install librenms in `/opt/librenms`
The sysv and upstart init scripts could also be used with a little modification.
2019-05-20 11:35:47 -05:00
2022-11-06 11:53:21 -05:00
### systemd service
2019-05-20 11:35:47 -05:00
2019-09-09 05:48:35 -05:00
A systemd unit file can be found in `misc/librenms.service` . To
2022-11-14 17:19:08 +01:00
install run:
```bash
cp /opt/librenms/misc/librenms.service /etc/systemd/system/librenms.service && systemctl enable --now librenms.service
```
2019-05-20 11:35:47 -05:00
2022-11-22 13:54:04 +01:00
2022-11-06 11:53:21 -05:00
### systemd service with watchdog
This service file is an alternative to the above service file. It uses the systemd WatchdogSec= option to restart the service if it does not receive a keep-alive from the running process.
2021-03-22 15:34:45 +00:00
A systemd unit file can be found in `misc/librenms-watchdog.service` . To
2022-11-14 17:19:08 +01:00
install run:
```bash
cp /opt/librenms/misc/librenms-watchdog.service /etc/systemd/system/librenms.service && systemctl enable --now librenms.service
```
2021-03-22 15:34:45 +00:00
This requires: python3-systemd (or python-systemd on older systems)
or https://pypi.org/project/systemd-python/
2022-11-06 11:53:21 -05:00
If you run this systemd service without python3-systemd it will restart every 30 seconds.
2021-03-22 15:34:45 +00:00
2021-07-10 03:34:01 +08:00
### OS-Specific Instructions
2019-05-20 11:35:47 -05:00
2021-07-10 03:34:01 +08:00
#### RHEL/CentOS
2019-09-09 05:48:35 -05:00
To get the LibreNMS service running under python3.4+ on
RHEL-derivatives with minimal fuss, you can use the software
collections build:
2019-05-20 11:35:47 -05:00
First, enable SCL's on your system:
2021-07-10 03:34:01 +08:00
##### CentOS 7
2019-09-09 05:48:35 -05:00
2019-05-20 11:35:47 -05:00
```
# yum install centos-release-scl
```
2021-07-10 03:34:01 +08:00
##### RHEL 7
2019-09-09 05:48:35 -05:00
2019-05-20 11:35:47 -05:00
```
# subscription-manager repos --enable rhel-server-rhscl-7-rpms
```
Then install and configure the runtime and service:
```
2020-09-30 05:50:40 +01:00
# yum install gcc rh-python36 rh-python36-python-devel epel-release
2020-05-22 09:16:56 +10:00
# yum --enablerepo=remi install redis
2019-05-20 11:35:47 -05:00
# vi /opt/librenms/config.php
# vi /etc/redis.conf
# systemctl enable --now redis.service
# scl enable rh-python36 bash
2020-05-22 09:16:56 +10:00
# change directory to librenms (default /opt/librenms)
2020-05-12 22:39:44 +02:00
# pip3 install -r requirements.txt
2019-05-20 11:35:47 -05:00
# cp /opt/librenms/misc/librenms.service.scl /etc/systemd/system/librenms.service
# systemctl enable --now librenms.service
```
2019-09-09 05:48:35 -05:00
If you want to use another version of python 3, change `rh-python36`
in the unit file and the commands above to match the name of the
replacement scl.
2019-05-20 11:35:47 -05:00
2021-07-10 03:34:01 +08:00
#### Debian/Ubuntu
2019-05-20 11:35:47 -05:00
2022-11-22 13:54:04 +01:00
##### Debian 11 (Bullseye)
2019-05-20 11:35:47 -05:00
2022-11-22 13:54:04 +01:00
Warning: Bullseye provide PHP 7.4 that is too old to run LibreNMS.
2019-05-20 11:35:47 -05:00
2022-11-22 13:54:04 +01:00
##### Debian 12 (Bookworm)
Install dependancies
2019-05-20 11:35:47 -05:00
```
2022-11-22 13:54:04 +01:00
apt install python3 python3-mysqldb python3-dotenv
```
Add the `python3-systemd` package for service with watchdog.