https://docs.google.com/document/d/1xIBwOCU0p7NjxlX5_Y98w9nitYV5z7rnCT491lMl-QE/edit?usp=sharing
There is a need to capture metrics beyond the basics of what are provided by the Prometheus Node Exporter installed on all hosts. Additional metrics may be related to the application running on a specific host or hosts, specialized system checks beyond the scope of the node exporter, or other metrics that will replace Nagios or CheckMK.
Install brew
and python 3.7
(based on your setup, you might have to specify python version in the command line)
These steps will install the pre-requisites for running iris on your local machine.
# Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Make sure python3 (3.7) is installed
brew install python3
python3 --version
which python3.7
- Checkout iris repo from github
- Install iris into your virtual environment
git clone git@github.com:XXX/iris.git
cd iris
# Create a venv directory to hold our virtual environment. Point it to python3.7
virtualenv venv --python=python3.7
# Activate the virtual environment so we can download the dependencies into it
source venv/bin/activate
# Make sure a new version of pip is installed
pip install --upgrade pip setuptools
# Download the dependencies
python setup.py install
By default, Iris will download and create all dependent files to the /opt/iris
directory specified by the iris_root_path
field in iris.cfg
To run and test the Iris code locally:
- open
iris.cfg
- set
dev_mode = true
- set
ec2_dev_instance_id
field to the instance id of the ec2 host you want to test on- this will direct boto3 EC2 API calls to point at the specified host
- set
- run the
scripts/download_configs.py
file to pull down the current configs for iris. They will be located in/opt/iris/downloads
sudo python scripts/download_configs.py
- create new test metrics or edit existing ones in
/opt/iris/downloads/metrics.json
- add your test metric to
metrics.json
in the following format
# metrics.json { "node_logged_in_users": { "help": "The number of users currently logged into the node", "metric_type": "gauge", "execution_frequency": 30, "bash_command": "who | wc -l", "export_method": "textfile" }, "node_running_processes": { "help": "The number of running processes on the node", "metric_type": "gauge", "execution_frequency": 20, "bash_command": "ps ax | wc -l", "export_method": "textfile" }, ... ... "test_metric_1" : { "help": "test metric 1", "metric_type": "gauge", "execution_frequency": 27, "bash_command": "test command 1", "export_method": "textfile" }, "test_metric_2" : { "help": "test metric 2", "metric_type": "gauge", "execution_frequency": 25, "bash_command": "test command 2", "export_method": "textfile" } }
- add your test metric to
- create a new profile config or edit an existing one in
/opt/iris/downloads/profiles/
for the test instance specified by theec2_dev_instance_id
field iniris.cfg
- name the file after the host name (if
host_name = testclient101.net
, then name the filetestclient101.json
). - profile config file format:
# test_instance_name.json { "profile_name": "test_instance_name", "metrics": [ "node_logged_in_users", "node_running_processes", "test_metric_1", "test_metric_2", ] }
- name the file after the host name (if
- create the iris tags for the ec2 instance you are testing on
- add
xxx:iris:profile
tag and set it to the profile config name without the.json
suffix- e.g.
xxx:iris:enabled = tvclient
for thetestclient101.net
host
- e.g.
- add
xxx:iris:enabled = True
- add
Make sure that these requirements are fulfilled to complete testing:
tox
runs successfully (unit testing, linting, type checking, coverage)pyinstaller
binary builds and runs successfully (check pyinstaller section)- go back in
iris.cfg
and setiris_mode = prod
andiris_root_path = /opt/iris
before committing and deploying
We use Tox
to automate and run our testing environment. This includes running coverage
, pytest
via setup.py test, mypy
for type checking, and flake8
for linting
tox
We use Pyinstaller
to transform Iris into an executable file that will run Iris as a daemon.
Use this as the final step to local testing by making sure the binary builds and runs correctly.
If you did not change the iris_root_path = /opt/iris
in iris.cfg
, then you will need to run the below commands with sudo
.
# Run Pyinstaller and set the path argument to include the virtual environment directory that holds all of Iris' dependencies
sudo pyinstaller --paths=venv/lib/python3.7/site-packages/ --add-data=iris.cfg:. --clean main.py
# Run Iris executable
sudo ./dist/main/main
# To rebuild the Iris executable, we first remove the directories it produced and then run the commands
sudo ./clean.sh
sudo pyinstaller --paths=venv/lib/python3.7/site-packages/ --add-data=iris.cfg:. --clean main.py
sudo ./dist/main/main
Code in the project should follow PEP8 standards, with the exception that lines can be up to 120 characters. The linter will check this for you.
Please also add type hints/annotations to the code that you write (follows PEP 484 & PEP 526 standards, mypy will ensure this).
Guidelines:
- All code that should be tested, is tested. Tests should be included in the same PR as your change. All tests should be written using pytest.
- All code should be type hinted/annotated and checked with mypy
- All methods should be documented. It should be clear the parameters expected, and what results a consumer might get.
- All methods should return values. Avoid manipulation of parameters without explicitly returning the value.
- Metric naming conventions: https://prometheus.io/docs/practices/naming/