monasca-persister/monasca_persister
Arseni Lipinski 26844c1dd0 Add tests for cassandra/retry_policy.py
Story: 2007280
Task: 38724

Depends-On: https://review.opendev.org/#/c/679076/

Change-Id: I440e36ad37dc94ffcd665f3925b7f25b5964cbf8
2020-02-13 10:39:05 +00:00
..
conf Add configuration option influxdb.batch_size 2020-01-21 11:07:22 +01:00
hacking Define extra hacking rules to ensure code quality 2017-06-05 13:42:28 +07:00
kafka Use Confluent Kafka client 2019-08-15 14:47:51 +02:00
repositories Add configuration option influxdb.batch_size 2020-01-21 11:07:22 +01:00
tests Add tests for cassandra/retry_policy.py 2020-02-13 10:39:05 +00:00
tools Support default_retention_hours for influxdb 2019-11-15 13:47:47 +00:00
__init__.py Refactor the python persister 2016-03-10 09:14:24 -07:00
config.py Tool to migrate existing data to db per tenant 2019-09-27 08:31:16 +00:00
persister.py Use Confluent Kafka client 2019-08-15 14:47:51 +02:00
README.md Replace git.openstack.org URLs with opendev.org URLs 2019-06-03 15:33:15 +02:00
version.py Pass version and description into oslo setup 2017-03-28 08:45:46 +02:00

Monasca Persister

A Monasca Persister written in Python.

Reads alarms and metrics from a Kafka queue and stores them in an InfluxDB database.

Deployment

Note that this document refers to the Python implementation of the persister. For information regarding the Java implementation, see the README.md in the root of this repository.

Package Installation

Monasca Persister should be installed from PyPI via pip. Use your distribution package manager, or other preferred method, to ensure that you have pip installed, it is typically called python-pip.

e.g. For Debian/Ubuntu:

sudo apt-get install python-pip

Alternately, you may want to follow the official instructions available at: https://pip.pypa.io/en/stable/installing/

Now, to install a particular released version:

sudo pip install monasca-persister==<version>

If using InfluxDB, the persister requires the necessary Python library to be installed. This can also be achieved via pip:

sudo pip install influxdb

Alternatively, pip can be used to install the latest development version or a specific revision. This requires you have git installed in addition to pip.

sudo apt-get install git
sudo pip install git+https://opendev.org/openstack/monasca-persister@<revision>#egg=monasca-persister

The installation will not cause the persister to run - it should first be configured.

Environment

Using the persister requires that the following components of the Monasca system are deployed and available:

  • Kafka
  • Zookeeper (Required by Kafka)
  • InfluxDB

If running the persister as a daemon, it is good practice to create a dedicated system user for the purpose, for example:

sudo groupadd --system monasca
sudo useradd --system --gid monasca mon-persister

Additionally, it is good practice to give the daemon a dedicated working directory, in the event it ever needs to write any files.

sudo mkdir -p /var/lib/monasca-persister
sudo chown mon-persister:monasca /var/lib/monasca-persister

The persister will write a log file in a location which can be changed via the configuration, but by default requires that a suitable directory be created as follows:

sudo mkdir -p /var/log/monasca/persister
sudo chown mon-persister:monasca /var/log/monasca/persister

Make sure to allow the user who will be running the persister to have write access to the log directory.

Configuration

There is minimum amount of configuration which must be performed before running the persister. A template configuration file is installed in the default location of /etc/monasca/monasca-persister.conf.

Note that the configuration will contain authentication information for the database being used, so depending on your environment it may be desirable to inhibit read access except for the monasca-persister group.

sudo chown root:monasca /etc/monasca/monasca-persister.conf
sudo chmod 640 /etc/monasca/monasca-persister.conf

Most of the configuration options should be left at default, but at a minimum, the following should be changed:

[zookeeper]
uri = <host1>:<port1>,<host2>:<port2>,...

[kafka_alarm_history]
uri = <host1>:<port1>,<host2>:<port2>,...

[kafka_metrics]
uri = <host1>:<port1>,<host2>:<port2>,...

[influxdb]
database_name =
ip_address =
port =
user =
password =

Running

The installation does not provide scripts for starting the persister, it is up to the user how the persister is run. To run the persister manually, which may be useful for troubleshooting:

sudo -u mon-persister \
  monasca-persister \
  --config-file /etc/monasca/monasca-persister.conf

Note that it is important to deploy the daemon in a manner such that the daemon will be restarted if it exits (fails). There are a number of situations in which the persister will fail-fast, such as all Kafka endpoints becoming unreachable. For an example of this, see the systemd deployment section below.

Running (systemd)

To run the persister as a daemon, the following systemd unit file can be used and placed in /etc/systemd/system/monasca-persister.service:

[Unit]
Description=OpenStack Monasca Persister
Documentation=https://github.com/openstack/monasca-persister/monasca-persister/README.md
Requires=network.target remote-fs.target
After=network.target remote-fs.target
ConditionPathExists=/etc/monasca/monasca-persister.conf
ConditionPathExists=/var/lib/monasca-persister
ConditionPathExists=/var/log/monasca/persister

[Service]
Type=simple
PIDFile=/var/run/monasca-persister.pid
User=mon-persister
Group=monasca
WorkingDirectory=/var/lib/monasca-persister
ExecStart=/usr/local/bin/monasca-persister --config-file /etc/monasca/monasca-persister.conf
Restart=on-failure
RestartSec=5
SyslogIdentifier=monasca-persister

[Install]
WantedBy=multi-user.target

After creating or modifying the service file, you should run:

sudo systemctl daemon-reload

The service can then be managed as normal, e.g.

sudo systemctl start monasca-persister

For a production deployment, it will almost always be desirable to use the Restart clause in the service file. The RestartSec clause is also important as by default, systemd assumes a delay of 100ms. A number of failures in quick succession will cause the unit to enter a failed state, therefore extending this period is critical.

License

(C) Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.