Add 1-Wire temperature sensor monitoring
Multiple 1-Wire temperature sensors are auto-detected and monitored. Displayed sensor names are user-configurable.
Diomidis Spinellis committed
Jun 11, 2018 at 12:09 UTC
71a0d4d42d0aece55b71560785398bf8d9b1819e
7 files changed
+204
conf.d/Makefile.am
+1
@@ -79,6 +79,7 @@ dist_pythonconfig_DATA = \
79
python.d/traefik.conf \
80
python.d/unbound.conf \
81
python.d/varnish.conf \
82
+ python.d/w1sensor.conf \
83
python.d/web_log.conf \
84
$(NULL)
85
conf.d/python.d.conf
+1
@@ -82,3 +82,4 @@ nginx_log: no
82
unbound: no
83
# varnish: yes
84
# web_log: yes
85
+# w1sensor: yes
conf.d/python.d/w1sensor.conf
new
+74
@@ -0,0 +1,74 @@
1
+# netdata python.d.plugin configuration for w1sensor
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
+# retries sets the number of retries to be made in case of failures.
31
+# If unset, the default for python.d.plugin is used.
32
+# Attempts to restore the service are made once every update_every
33
+# and only if the module has collected values in the past.
34
+# retries: 60
35
+
36
+# autodetection_retry sets the job re-check interval in seconds.
37
+# The job is not deleted if check fails.
38
+# Attempts to start the job are made once every autodetection_retry.
39
+# This feature is disabled by default.
40
+# autodetection_retry: 0
41
+
42
+# ----------------------------------------------------------------------
43
+# JOBS (data collection sources)
44
+#
45
+# The default JOBS share the same *name*. JOBS with the same name
46
+# are mutually exclusive. Only one of them will be allowed running at
47
+# any time. This allows autodetection to try several alternatives and
48
+# pick the one that works.
49
+#
50
+# Any number of jobs is supported.
51
+#
52
+# All python.d.plugin JOBS (for all its modules) support a set of
53
+# predefined parameters. These are:
54
+#
55
+# job_name:
56
+# name: myname # the JOB's name as it will appear at the
57
+# # dashboard (by default is the job_name)
58
+# # JOBs sharing a name are mutually exclusive
59
+# update_every: 5 # the JOB's data collection frequency
60
+# priority: 60000 # the JOB's order on the dashboard
61
+# retries: 60 # the JOB's number of restoration attempts
62
+# autodetection_retry: 0 # the JOB's re-check interval in seconds
63
+#
64
+# Additionally to the above, example also supports the following:
65
+#
66
+# name_<1-Wire id>: '<human readable name>'
67
+# This allows associating a human readable name with a sensor's 1-Wire
68
+# identifier. Example:
69
+# name_00000022276e: 'Machine room'
70
+# name_00000022298f: 'Rack 12'
71
+#
72
+# ----------------------------------------------------------------------
73
+# AUTO-DETECTION JOBS
74
+# only one of them will run (they have the same name)
python.d/Makefile.am
+1
@@ -67,6 +67,7 @@ dist_python_DATA = \
67
traefik.chart.py \
68
unbound.chart.py \
69
varnish.chart.py \
70
+ w1sensor.chart.py \
71
web_log.chart.py \
72
$(NULL)
73
python.d/README.md
+14
@@ -2522,6 +2522,20 @@ No configuration is needed.
2522
2523
---
2524
2525
+# w1sensor
2526
+
2527
+Data from 1-Wire sensors.
2528
+On Linux these are supported by the wire, w1_gpio, and w1_therm modules.
2529
+Currently temperature sensors are supported and automatically detected.
2530
+
2531
+Charts are created dynamically based on the number of detected sensors.
2532
+
2533
+### configuration
2534
+
2535
+For detailed configuration information please read [`w1sensor.conf`](https://github.com/firehol/netdata/blob/master/conf.d/python.d/w1sensor.conf) file.
2536
+
2537
+---
2538
+
2539
# web_log
2540
2541
Tails the apache/nginx/lighttpd/gunicorn log files to collect real-time web-server statistics.
python.d/w1sensor.chart.py
new
+103
@@ -0,0 +1,103 @@
1
+# -*- coding: utf-8 -*-
2
+# Description: 1-wire temperature monitor netdata python.d module
3
+# Author: Diomidis Spinellis <http://www.spinellis.gr>
4
+
5
+import os
6
+import re
7
+from bases.FrameworkServices.SimpleService import SimpleService
8
+
9
+# default module values (can be overridden per job in `config`)
10
+update_every = 5
11
+
12
+# Location where 1-Wire devices can be found
13
+W1_DIR = '/sys/bus/w1/devices/'
14
+
15
+# Lines matching the following regular expression contain a temperature value
16
+RE_TEMP = re.compile(r' t=(\d+)')
17
+
18
+ORDER = ['temp']
19
+
20
+# id: {
21
+# 'options': [name, title, units, family (heading 2), context, charttype],
22
+# 'lines': [
23
+# [unique_dimension_name, name, algorithm, multiplier, divisor]
24
+# ]}
25
+CHARTS = {
26
+ 'temp': {
27
+ 'options': [
28
+ None,
29
+ '1-Wire Temperature Sensor',
30
+ 'Celsius',
31
+ 'Temperature',
32
+ 'w1sensor.temp',
33
+ 'line'
34
+ ],
35
+ # lines are constructed from check
36
+ }
37
+}
38
+
39
+# Known and supported family members
40
+# Based on linux/drivers/w1/w1_family.h and w1/slaves/w1_therm.c
41
+THERM_FAMILY = {
42
+ '10': 'W1_THERM_DS18S20',
43
+ '22': 'W1_THERM_DS1822',
44
+ '28': 'W1_THERM_DS18B20',
45
+ '3b': 'W1_THERM_DS1825',
46
+ '42': 'W1_THERM_DS28EA00',
47
+}
48
+
49
+class Service(SimpleService):
50
+ """Provide netdata service for 1-Wire sensors"""
51
+ def __init__(self, configuration=None, name=None):
52
+ SimpleService.__init__(self, configuration=configuration, name=name)
53
+ self.order = ORDER
54
+ self.definitions = CHARTS
55
+ self.probes = []
56
+
57
+ def check(self):
58
+ """Auto-detect available 1-Wire sensors, setting line definitions
59
+ and probes to be monitored."""
60
+ try:
61
+ file_names = os.listdir(W1_DIR)
62
+ except OSError as err:
63
+ self.error(err)
64
+ return False
65
+
66
+ lines = []
67
+ for file_name in file_names:
68
+ if file_name[2] != '-':
69
+ continue
70
+ if not file_name[0:2] in THERM_FAMILY:
71
+ continue
72
+
73
+ self.probes.append(file_name)
74
+ identifier = file_name[3:]
75
+ name = identifier
76
+ config_name = self.configuration.get('name_' + identifier)
77
+ if config_name:
78
+ name = config_name
79
+ lines.append(['w1sensor_temp_' + identifier, name, 'absolute',
80
+ 1, 10])
81
+ self.definitions['temp']['lines'] = lines
82
+ return len(self.probes) > 0
83
+
84
+ def get_data(self):
85
+ """Return data read from sensors."""
86
+ data = dict()
87
+
88
+ for file_name in self.probes:
89
+ file_path = W1_DIR + file_name + '/w1_slave'
90
+ identifier = file_name[3:]
91
+ try:
92
+ with open(file_path, 'r') as device_file:
93
+ for line in device_file:
94
+ matched = RE_TEMP.search(line)
95
+ if matched:
96
+ # Round to one decimal digit to filter-out noise
97
+ value = round(int(matched.group(1)) / 1000., 1)
98
+ value = int(value * 10)
99
+ data['w1sensor_temp_' + identifier] = value
100
+ except (OSError, IOError) as err:
101
+ self.error(err)
102
+ continue
103
+ return data or None
web/dashboard_info.js
+10
@@ -384,6 +384,12 @@ netdataDashboard.menu = {
384
title: 'BOINC',
385
icon: '<i class="fas fa-microchip"></i>',
386
info: 'Provides task counts for <b><a href="http://boinc.berkeley.edu/">BOINC</a></b> distributed computing clients.'
387
+ },
388
+
389
+ 'w1sensor': {
390
+ title: '1-Wire Sensors',
391
+ icon: '<i class="fas fa-thermometer-half"></i>',
392
+ info: 'Data derived from <a href="https://en.wikipedia.org/wiki/1-Wire">1-Wire</a> sensors. Currently temperature sensors are automatically detected.'
393
}
394
};
395
@@ -2142,6 +2148,10 @@ netdataDashboard.context = {
2148
2149
'boinc.process': {
2150
info: 'Counts of active tasks in each process state. <code>Executing</code> tasks are running right now. <code>Suspended</code> tasks have an associated process, but are not currently running (either because the system isn\'t processing any tasks right now, or because they have been preempted by higher priority tasks). <code>Quit</code> tasks are exiting gracefully. <code>Aborted</code> tasks exceeded some resource limit, and are being shut down. code>Copy Pending</code> tasks are waiting on a background file transfer to finish. <code>Uninitialized</code> tasks do not have an associated process yet.'
2151
+ },
2152
+
2153
+ 'w1sensor.temp': {
2154
+ info: 'Temperature derived from 1-Wire temperature sensors.'
2155
}
2156
2157
// ------------------------------------------------------------------------