@cryptotaxi247 / netdata-1 / commits / 95407a625

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.

Andrew Maguire committed Nov 30, 2020 at 13:57 UTC 95407a625c6a55f157cdf8b0e59096d178098d41
7 files changed +178
collectors/python.d.plugin/Makefile.am
+1
@@ -40,6 +40,7 @@ dist_pythonconfig_DATA = \
40 $(NULL)
41
42 include adaptec_raid/Makefile.inc
43 +include alarms/Makefile.inc
44 include am2320/Makefile.inc
45 include apache/Makefile.inc
46 include beanstalk/Makefile.inc
collectors/python.d.plugin/alarms/Makefile.inc new
+13
@@ -0,0 +1,13 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +# THIS IS NOT A COMPLETE Makefile
4 +# IT IS INCLUDED BY ITS PARENT'S Makefile.am
5 +# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT
6 +
7 +# install these files
8 +dist_python_DATA += alarms/alarms.chart.py
9 +dist_pythonconfig_DATA += alarms/alarms.conf
10 +
11 +# do not install these files, but include them in the distribution
12 +dist_noinst_DATA += alarms/README.md alarms/Makefile.inc
13 +
collectors/python.d.plugin/alarms/README.md new
+56
@@ -0,0 +1,56 @@
1 +<!--
2 +title: "Alarms"
3 +custom_edit_url: https://github.com/netdata/netdata/edit/master/collectors/python.d.plugin/alarms/README.md
4 +-->
5 +
6 +# Alarms - graphing Netdata alarm states over time
7 +
8 +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).
9 +
10 +```
11 +{
12 + 'CLEAR': 0,
13 + 'WARNING': 1,
14 + 'CRITICAL': 2
15 +}
16 +```
17 +
18 +## Charts
19 +
20 +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.
21 +
22 +![alt text](https://github.com/andrewm4894/random/blob/master/images/netdata/netdata-alarms-collector.jpg)
23 +
24 +## Configuration
25 +
26 +Enable the collector and restart Netdata.
27 +
28 +```bash
29 +cd /etc/netdata/
30 +sudo ./edit-config python.d.conf
31 +# Set `alarms: no` to `alarms: yes`
32 +sudo systemctl restart netdata
33 +```
34 +
35 +If needed, edit the `python.d/alarms.conf` configuration file using `edit-config` from the your agent's [config
36 +directory](/docs/configure/nodes.md), which is usually at `/etc/netdata`.
37 +
38 +```bash
39 +cd /etc/netdata # Replace this path with your Netdata config directory, if different
40 +sudo ./edit-config python.d/alarms.conf
41 +```
42 +
43 +The `alarms` specific part of the `alarms.conf` file should look like this:
44 +
45 +```yaml
46 +# what url to pull data from
47 +local:
48 + url: 'http://127.0.0.1:19999/api/v1/alarms?all'
49 + # define how to map alarm status to numbers for the chart
50 + status_map:
51 + CLEAR: 0
52 + WARNING: 1
53 + CRITICAL: 2
54 +```
55 +
56 +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
collectors/python.d.plugin/alarms/alarms.chart.py new
+50
@@ -0,0 +1,50 @@
1 +# -*- coding: utf-8 -*-
2 +# Description: alarms netdata python.d module
3 +# Author: andrewm4894
4 +# SPDX-License-Identifier: GPL-3.0-or-later
5 +
6 +from json import loads
7 +
8 +from bases.FrameworkServices.UrlService import UrlService
9 +
10 +update_every = 10
11 +disabled_by_default = False
12 +
13 +DEFAULT_STATUS_MAP = {'CLEAR': 0, 'WARNING': 1, 'CRITICAL': 2}
14 +
15 +ORDER = [
16 + 'alarms',
17 +]
18 +
19 +CHARTS = {
20 +}
21 +
22 +
23 +class Service(UrlService):
24 + def __init__(self, configuration=None, name=None):
25 + UrlService.__init__(self, configuration=configuration, name=name)
26 + self.order = ORDER
27 + self.definitions = CHARTS
28 + self.url = self.configuration.get('url', 'http://127.0.0.1:19999/api/v1/alarms?all')
29 + self.status_map = self.configuration.get('status_map', DEFAULT_STATUS_MAP)
30 + self.chart_title = f"Alarms ({', '.join([f'{k}={self.status_map[k]}' for k in self.status_map])})"
31 +
32 + def validate_charts(self, name, data, algorithm='absolute', multiplier=1, divisor=1):
33 + for dim in data:
34 + if name not in self.charts:
35 + chart_params = [name] + ['alarms', self.chart_title, 'status', 'alarms', 'alarms.status', 'line']
36 + self.charts.add_chart(params=chart_params)
37 + if dim not in self.charts[name]:
38 + self.charts[name].add_dimension([dim, dim, algorithm, multiplier, divisor])
39 +
40 + def _get_data(self):
41 + raw_data = self._get_raw_data()
42 + if raw_data is None:
43 + return None
44 + raw_data = loads(raw_data)
45 + alarms = raw_data.get('alarms', {})
46 + data = {a: self.status_map[alarms[a]['status']] for a in alarms if alarms[a]['status'] in self.status_map}
47 + self.validate_charts('alarms', data)
48 + data['alarms_num'] = len(data)
49 +
50 + return data
collectors/python.d.plugin/alarms/alarms.conf new
+50
@@ -0,0 +1,50 @@
1 +# netdata python.d.plugin configuration for example
2 +#
3 +# This file is in YaML format. Generally the format is:
4 +#
5 +# name: value
6 +#
7 +# There are 2 sections:
8 +# - global variables
9 +# - one or more JOBS
10 +#
11 +# JOBS allow you to collect values from multiple sources.
12 +# Each source will have its own set of charts.
13 +#
14 +# JOB parameters have to be indented (using spaces only, example below).
15 +
16 +# ----------------------------------------------------------------------
17 +# Global Variables
18 +# These variables set the defaults for all JOBs, however each JOB
19 +# may define its own, overriding the defaults.
20 +
21 +# update_every sets the default data collection frequency.
22 +# If unset, the python.d.plugin default is used.
23 +update_every: 5
24 +
25 +# priority controls the order of charts at the netdata dashboard.
26 +# Lower numbers move the charts towards the top of the page.
27 +# If unset, the default for python.d.plugin is used.
28 +# priority: 60000
29 +
30 +# penalty indicates whether to apply penalty to update_every in case of failures.
31 +# Penalty will increase every 5 failed updates in a row. Maximum penalty is 10 minutes.
32 +# penalty: yes
33 +
34 +# autodetection_retry sets the job re-check interval in seconds.
35 +# The job is not deleted if check fails.
36 +# Attempts to start the job are made once every autodetection_retry.
37 +# This feature is disabled by default.
38 +# autodetection_retry: 0
39 +
40 +# ----------------------------------------------------------------------
41 +# JOBS (data collection sources)
42 +
43 +# what url to pull data from
44 +local:
45 + url: 'http://127.0.0.1:19999/api/v1/alarms?all'
46 + # define how to map alarm status to numbers for the chart
47 + status_map:
48 + CLEAR: 0
49 + WARNING: 1
50 + CRITICAL: 2
collectors/python.d.plugin/python.d.conf
+1
@@ -29,6 +29,7 @@ gc_interval: 300
29
30 # apache_cache has been replaced by web_log
31 # adaptec_raid: yes
32 +# alarms: yes
33 # am2320: yes
34 apache_cache: no
35 # beanstalk: yes
web/gui/dashboard_info.js
+7
@@ -570,6 +570,13 @@ netdataDashboard.menu = {
570 icon: '<i class="fas fa-comments"></i>',
571 info: 'Summary, namespaces and topics performance data for the <b><a href="http://pulsar.apache.org/">Apache Pulsar</a></b> pub-sub messaging system.'
572 },
573 +
574 + 'alarms': {
575 + title: 'Alarms',
576 + icon: '<i class="fas fa-bell"></i>',
577 + info: 'Charts showing alarm status over time. More details <a href="https://github.com/netdata/netdata/blob/master/collectors/python.d.plugin/alarms/README.md" target="_blank">here</a>.'
578 + },
579 +
580 };
581
582