@cryptotaxi247 / netdata-1 / commits / 3fdf18dcb

add support for am2320 sensor (#7024)

* add support for am2320 sensor add support for am2320 temperature and humidity sensor * Rename readme.md to README.md * updated README.md to include proper sections updated README.md to include proper sections * readme updated and file name corrected readme updated with missing formatting and information. AM2320.chart.py filename corrected. * changed simple service import chnaged simple service import location * updated README.md to remove the reference of moving the script file. * requested changes - Moved header from README.md to am2320.chart.py - Added Alarm for am2320 to health.d - Changed exception to value error in am2320.chart.py * typo changed mae to make in comment * Add title and icon for AM2320 Sensor Add title and icon for AM2320 Sensor * typo corrected changed Save to save * added I2C group to installer Added netdata to the I2C group during install or update. Removed instruction to add netdate to I2C group from README.md * change tab to spaces change tab to spaces

Tom Buck committed Oct 22, 2019 at 21:08 UTC 3fdf18dcb6d847e1157316d8f7b8ed6426565ecf
10 files changed +205 -1
collectors/python.d.plugin/Makefile.am
+1
@@ -37,6 +37,7 @@ dist_pythonconfig_DATA = \
37 $(NULL)
38
39 include adaptec_raid/Makefile.inc
40 +include am2320/Makefile.inc
41 include apache/Makefile.inc
42 include beanstalk/Makefile.inc
43 include bind_rndc/Makefile.inc
collectors/python.d.plugin/am2320/Makefile.inc new
+8
@@ -0,0 +1,8 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +# install these files
4 +dist_python_DATA += am2320/am2320.chart.py
5 +dist_pythonconfig_DATA += am2320/am2320.conf
6 +
7 +# do not install these files, but include them in the distribution
8 +dist_noinst_DATA += am2320/README.md am2320/Makefile.inc
collectors/python.d.plugin/am2320/README.md new
+37
@@ -0,0 +1,37 @@
1 +# AM2320
2 +This module will display a graph of the temperture and humity from a AM2320 sensor.
3 +
4 +**Requirements:**
5 + - Adafruit Circuit Python AM2320 library
6 + - Adafruit AM2320 I2C sensor
7 + - Python 3 (Adafruit libraries are not Python 2.x compatible)
8 +
9 +
10 +It produces the following charts:
11 +1. **Temperature**
12 +2. **Humidity**
13 +
14 +## configuration
15 +
16 +Raspbery Pi Instructions:
17 +
18 +Hardware install:
19 +Connect the am2320 to the Raspbery Pi I2C pins
20 +
21 +Raspberry Pi 3B/4 Pins:
22 +
23 +- Board 3.3V (pin 1) to sensor VIN (pin 1)
24 +- Board SDA (pin 3) to sensor SDA (pin 2)
25 +- Board GND (pin 6) to sensor GND (pin 3)
26 +- Board SCL (pin 5) to sensor SCL (pin 4)
27 +
28 +You may also need to add two I2C pullup resistors if your board does not already have them. The Raspberry Pi does have internal pullup resistors but it doesnt hurt to add them anyway. You can use 2.2K - 10K but we will just use 10K. The resistors go from VDD to SCL and SDA each.
29 +
30 +Software install:
31 +- `sudo pip3 install adafruit-circuitpython-am2320`
32 +- edit `/etc/netdata/netdata.conf`
33 +- find `[plugin:python.d]`
34 +- add `command options = -ppython3`
35 +- save the file.
36 +- restart the netdata service.
37 +- check the dashboard.
collectors/python.d.plugin/am2320/am2320.chart.py new
+69
@@ -0,0 +1,69 @@
1 +# _*_ coding: utf-8 _*_
2 +# Description: AM2320 netdata module
3 +# Author: tommybuck
4 +# SPDX-License-Identifier: GPL-3.0-or-Later
5 +
6 +try:
7 + import board
8 + import busio
9 + import adafruit_am2320
10 + HAS_AM2320 = True
11 +except ImportError:
12 + HAS_AM2320 = False
13 +
14 +
15 +from bases.FrameworkServices.SimpleService import SimpleService
16 +
17 +
18 +ORDER = [
19 + 'temperature',
20 + 'humidity',
21 +]
22 +
23 +CHARTS = {
24 + 'temperature': {
25 + 'options': [None, 'Temperature', 'celsius', 'temperature', 'am2320.temperature', 'line'],
26 + 'lines': [
27 + ['temperature']
28 + ]
29 + },
30 + 'humidity': {
31 + 'options': [None, 'Relative Humidity', 'percentage', 'humidity', 'am2320.humidity', 'line'],
32 + 'lines': [
33 + ['humidity']
34 + ]
35 + }
36 +}
37 +
38 +
39 +class Service(SimpleService):
40 + def __init__(self, configuration=None, name=None):
41 + SimpleService.__init__(self, configuration=configuration, name=name)
42 + self.order = ORDER
43 + self.definitions = CHARTS
44 + self.am = None
45 +
46 + def check(self):
47 + if not HAS_AM2320:
48 + self.error("Could not find the adafruit-circuitpython-am2320 package.")
49 + return False
50 +
51 + try:
52 + i2c = busio.I2C(board.SCL, board.SDA)
53 + self.am = adafruit_am2320.AM2320(i2c)
54 + except ValueError as error:
55 + self.error("error on creating I2C shared bus : {0}".format(error))
56 + return False
57 +
58 + return True
59 +
60 + def get_data(self):
61 + try:
62 + return {
63 + 'temperature': self.am.temperature,
64 + 'humidity': self.am.relative_humidity,
65 + }
66 +
67 + except (OSError, RuntimeError) as error:
68 + self.error(error)
69 + return None
collectors/python.d.plugin/am2320/am2320.conf new
+68
@@ -0,0 +1,68 @@
1 +# netdata python.d.plugin configuration for am2320 temperture/humity sensor
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: 1
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 +# The default JOBS share the same *name*. JOBS with the same name
44 +# are mutually exclusive. Only one of them will be allowed running at
45 +# any time. This allows autodetection to try several alternatives and
46 +# pick the one that works.
47 +#
48 +# Any number of jobs is supported.
49 +#
50 +# All python.d.plugin JOBS (for all its modules) support a set of
51 +# predefined parameters. These are:
52 +#
53 +# job_name:
54 +# name: myname # the JOB's name as it will appear at the
55 +# # dashboard (by default is the job_name)
56 +# # JOBs sharing a name are mutually exclusive
57 +# update_every: 1 # the JOB's data collection frequency
58 +# priority: 60000 # the JOB's order on the dashboard
59 +# penalty: yes # the JOB's penalty
60 +# autodetection_retry: 0 # the JOB's re-check interval in seconds
61 +#
62 +# Additionally to the above, example also supports the following:
63 +#
64 +# - none
65 +#
66 +# ----------------------------------------------------------------------
67 +# AUTO-DETECTION JOBS
68 +# only one of them will run (they have the same name)
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 +# am2320: yes
33 apache_cache: no
34 # beanstalk: yes
35 # bind_rndc: yes
health/Makefile.am
+1
@@ -22,6 +22,7 @@ dist_userhealthconfig_DATA = \
22 healthconfigdir=$(libconfigdir)/health.d
23 dist_healthconfig_DATA = \
24 health.d/adaptec_raid.conf \
25 + health.d/am2320.conf \
26 health.d/apache.conf \
27 health.d/apcupsd.conf \
28 health.d/backend.conf \
health/health.d/am2320.conf new
+12
@@ -0,0 +1,12 @@
1 +# make sure am2320 is sending stats
2 +
3 +template: am2320_last_collected_secs
4 + on: am2320.temperature
5 + calc: $now - $last_collected_t
6 + units: seconds ago
7 + every: 10s
8 + warn: $this > (($status >= $WARNING) ? ($update_every) : ( 5 * $update_every))
9 + crit: $this > (($status == $CRITICAL) ? ($update_every) : (60 * $update_every))
10 + delay: down 5m multiplier 1.5 max 1h
11 + info: number of seconds since the last successful data collection
12 + to: webmaster
\ No newline at end of file
packaging/makeself/install-or-update.sh
+1 -1
@@ -84,7 +84,7 @@ fi
84 # -----------------------------------------------------------------------------
85 progress "Attempt to create user/group netdata/netadata"
86
87 -NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
87 +NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody I2C"
88 NETDATA_ADDED_TO_GROUPS=""
89 # Default user/group
90 NETDATA_USER="root"
web/gui/dashboard_info.js
+7
@@ -516,7 +516,14 @@ netdataDashboard.menu = {
516 title: 'HDFS',
517 icon: '<i class="fas fa-folder-open"></i>',
518 info: 'Provides <b><a href="https://hadoop.apache.org/docs/r3.2.0/hadoop-project-dist/hadoop-hdfs/HdfsDesign.html">Hadoop Distributed File System</a></b> performance statistics. Module collects metrics over <code>Java Management Extensions</code> through the web interface of an <code>HDFS</code> daemon.'
519 + },
520 +
521 + 'am2320': {
522 + title: 'AM2320 Sensor',
523 + icon: '<i class="fas fa-thermometer-half"></i>',
524 + info: 'Readings from the external AM2320 Sensor.'
525 }
526 +
527 };
528
529