diff options
author | Andrew Maguire <andrewm4894@gmail.com> | 2020-11-30 13:57:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-30 13:57:58 +0000 |
commit | 95407a625c6a55f157cdf8b0e59096d178098d41 (patch) | |
tree | e65e3bb6bfc98ea64f7648d29b5da03c485f916e /collectors | |
parent | 3d86cf62cd716ba30ea6e1b0d6e23e3a41a7b06b (diff) |
Alarms collector (#10042)
Adding a simple python based Alarms collector to read from active alarms via /api/v1/alarms and add any active warning alarms to the alarms chart as per a status_map that maps alarm states to integers.
Diffstat (limited to 'collectors')
-rw-r--r-- | collectors/python.d.plugin/Makefile.am | 1 | ||||
-rw-r--r-- | collectors/python.d.plugin/alarms/Makefile.inc | 13 | ||||
-rw-r--r-- | collectors/python.d.plugin/alarms/README.md | 56 | ||||
-rw-r--r-- | collectors/python.d.plugin/alarms/alarms.chart.py | 50 | ||||
-rw-r--r-- | collectors/python.d.plugin/alarms/alarms.conf | 50 | ||||
-rw-r--r-- | collectors/python.d.plugin/python.d.conf | 1 |
6 files changed, 171 insertions, 0 deletions
diff --git a/collectors/python.d.plugin/Makefile.am b/collectors/python.d.plugin/Makefile.am index 176bd3cb01..57247b1f61 100644 --- a/collectors/python.d.plugin/Makefile.am +++ b/collectors/python.d.plugin/Makefile.am @@ -40,6 +40,7 @@ dist_pythonconfig_DATA = \ $(NULL) include adaptec_raid/Makefile.inc +include alarms/Makefile.inc include am2320/Makefile.inc include apache/Makefile.inc include beanstalk/Makefile.inc diff --git a/collectors/python.d.plugin/alarms/Makefile.inc b/collectors/python.d.plugin/alarms/Makefile.inc new file mode 100644 index 0000000000..c2de117249 --- /dev/null +++ b/collectors/python.d.plugin/alarms/Makefile.inc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +# THIS IS NOT A COMPLETE Makefile +# IT IS INCLUDED BY ITS PARENT'S Makefile.am +# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT + +# install these files +dist_python_DATA += alarms/alarms.chart.py +dist_pythonconfig_DATA += alarms/alarms.conf + +# do not install these files, but include them in the distribution +dist_noinst_DATA += alarms/README.md alarms/Makefile.inc + diff --git a/collectors/python.d.plugin/alarms/README.md b/collectors/python.d.plugin/alarms/README.md new file mode 100644 index 0000000000..2143d69a74 --- /dev/null +++ b/collectors/python.d.plugin/alarms/README.md @@ -0,0 +1,56 @@ +<!-- +title: "Alarms" +custom_edit_url: https://github.com/netdata/netdata/edit/master/collectors/python.d.plugin/alarms/README.md +--> + +# Alarms - graphing Netdata alarm states over time + +This collector creates an 'Alarms' menu with one line plot showing alarm states over time. Alarm states are mapped to integer values according to the below default mapping. Any alarm status types not in this mapping will be ignored (Note: This mapping can be changed by editing the `status_map` in the `alarms.conf` file). If you would like to learn more about the different alarm statuses check out the docs [here](https://learn.netdata.cloud/docs/agent/health/reference#alarm-statuses). + +``` +{ + 'CLEAR': 0, + 'WARNING': 1, + 'CRITICAL': 2 +} +``` + +## Charts + +Below is an example of the chart produced when running `stress-ng --all 2` for a few minutes. You can see the various warning and critical alarms raised. + +![alt text](https://github.com/andrewm4894/random/blob/master/images/netdata/netdata-alarms-collector.jpg) + +## Configuration + +Enable the collector and restart Netdata. + +```bash +cd /etc/netdata/ +sudo ./edit-config python.d.conf +# Set `alarms: no` to `alarms: yes` +sudo systemctl restart netdata +``` + +If needed, edit the `python.d/alarms.conf` configuration file using `edit-config` from the your agent's [config +directory](/docs/configure/nodes.md), which is usually at `/etc/netdata`. + +```bash +cd /etc/netdata # Replace this path with your Netdata config directory, if different +sudo ./edit-config python.d/alarms.conf +``` + +The `alarms` specific part of the `alarms.conf` file should look like this: + +```yaml +# what url to pull data from +local: + url: 'http://127.0.0.1:19999/api/v1/alarms?all' + # define how to map alarm status to numbers for the chart + status_map: + CLEAR: 0 + WARNING: 1 + CRITICAL: 2 +``` + +It will default to pulling all alarms at each time step from the Netdata rest api at `http://127.0.0.1:19999/api/v1/alarms?all`
\ No newline at end of file diff --git a/collectors/python.d.plugin/alarms/alarms.chart.py b/collectors/python.d.plugin/alarms/alarms.chart.py new file mode 100644 index 0000000000..39b2cfc5cf --- /dev/null +++ b/collectors/python.d.plugin/alarms/alarms.chart.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Description: alarms netdata python.d module +# Author: andrewm4894 +# SPDX-License-Identifier: GPL-3.0-or-later + +from json import loads + +from bases.FrameworkServices.UrlService import UrlService + +update_every = 10 +disabled_by_default = False + +DEFAULT_STATUS_MAP = {'CLEAR': 0, 'WARNING': 1, 'CRITICAL': 2} + +ORDER = [ + 'alarms', +] + +CHARTS = { +} + + +class Service(UrlService): + def __init__(self, configuration=None, name=None): + UrlService.__init__(self, configuration=configuration, name=name) + self.order = ORDER + self.definitions = CHARTS + self.url = self.configuration.get('url', 'http://127.0.0.1:19999/api/v1/alarms?all') + self.status_map = self.configuration.get('status_map', DEFAULT_STATUS_MAP) + self.chart_title = f"Alarms ({', '.join([f'{k}={self.status_map[k]}' for k in self.status_map])})" + + def validate_charts(self, name, data, algorithm='absolute', multiplier=1, divisor=1): + for dim in data: + if name not in self.charts: + chart_params = [name] + ['alarms', self.chart_title, 'status', 'alarms', 'alarms.status', 'line'] + self.charts.add_chart(params=chart_params) + if dim not in self.charts[name]: + self.charts[name].add_dimension([dim, dim, algorithm, multiplier, divisor]) + + def _get_data(self): + raw_data = self._get_raw_data() + if raw_data is None: + return None + raw_data = loads(raw_data) + alarms = raw_data.get('alarms', {}) + data = {a: self.status_map[alarms[a]['status']] for a in alarms if alarms[a]['status'] in self.status_map} + self.validate_charts('alarms', data) + data['alarms_num'] = len(data) + + return data diff --git a/collectors/python.d.plugin/alarms/alarms.conf b/collectors/python.d.plugin/alarms/alarms.conf new file mode 100644 index 0000000000..e851f4e15b --- /dev/null +++ b/collectors/python.d.plugin/alarms/alarms.conf @@ -0,0 +1,50 @@ +# netdata python.d.plugin configuration for example +# +# This file is in YaML format. Generally the format is: +# +# name: value +# +# There are 2 sections: +# - global variables +# - one or more JOBS +# +# JOBS allow you to collect values from multiple sources. +# Each source will have its own set of charts. +# +# JOB parameters have to be indented (using spaces only, example below). + +# ---------------------------------------------------------------------- +# Global Variables +# These variables set the defaults for all JOBs, however each JOB +# may define its own, overriding the defaults. + +# update_every sets the default data collection frequency. +# If unset, the python.d.plugin default is used. +update_every: 5 + +# priority controls the order of charts at the netdata dashboard. +# Lower numbers move the charts towards the top of the page. +# If unset, the default for python.d.plugin is used. +# priority: 60000 + +# penalty indicates whether to apply penalty to update_every in case of failures. +# Penalty will increase every 5 failed updates in a row. Maximum penalty is 10 minutes. +# penalty: yes + +# autodetection_retry sets the job re-check interval in seconds. +# The job is not deleted if check fails. +# Attempts to start the job are made once every autodetection_retry. +# This feature is disabled by default. +# autodetection_retry: 0 + +# ---------------------------------------------------------------------- +# JOBS (data collection sources) + +# what url to pull data from +local: + url: 'http://127.0.0.1:19999/api/v1/alarms?all' + # define how to map alarm status to numbers for the chart + status_map: + CLEAR: 0 + WARNING: 1 + CRITICAL: 2 diff --git a/collectors/python.d.plugin/python.d.conf b/collectors/python.d.plugin/python.d.conf index ec09a67f52..b5a4754e52 100644 --- a/collectors/python.d.plugin/python.d.conf +++ b/collectors/python.d.plugin/python.d.conf @@ -29,6 +29,7 @@ gc_interval: 300 # apache_cache has been replaced by web_log # adaptec_raid: yes +# alarms: yes # am2320: yes apache_cache: no # beanstalk: yes |