Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for python3 #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ docs/_build/

# PyBuilder
target/

bin
pyvenv.cfg
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ One remark: Since the DS18S20 needs 750ms to measure the temperature and convert
should set your Prometheus scrape_interval to at least *n* * 750ms. *n* is the number of DS18S20 sensors on your 1-wire
bus.


# Usage

```
python exporter.py
```

Use the `--internal` flag to montior the internal temp of the Rpi CPU instead. That requires /usr/bin/vcgencmd to be installed.

# Installation

First checkout this git repository:
Expand Down Expand Up @@ -51,4 +60,4 @@ Now you are done and can check your sensor values via:
curl localhost:8001
```

Have fun!
Have fun!
16 changes: 8 additions & 8 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import argparse

TEMP_REGEX = re.compile('t=-?([0-9]+)')
INTERNAL_TEMP_REGEX = re.compile('temp=([0-9]+\.[0-9])')
INTERNAL_TEMP_REGEX = re.compile('temp=([0-9]+\\.[0-9])')
SENSOR_PATH = "/sys/bus/w1/devices"
CRC_ERROR="Could not read sensor. Wrong CRC."
DEFAULT_VALUE_ERROR="Could not read sensor. Sensor returned default value."
Expand Down Expand Up @@ -95,16 +95,16 @@ def read_sensor(self):
else:
self.unset_missread()
return ret_val, ""
except Exception, e:
print self.id, "Ups something went wrong.", e.message
except (Exception, e):
print( self.id, "Ups something went wrong.", e.message)
if crc is not None:
print "CRC Line: ", crc
print( "CRC Line: ", crc)
if l is not None:
print "l Line: ", l
print( "l Line: ", l)
self.set_missread()
return None, e.message
except IOError, e:
print e.message
except (IOError, e):
print( e.message)
self.set_missread()
return None, e.message

Expand All @@ -119,7 +119,7 @@ def register_prometheus_gauges(export_internal_raspberry=False):
g = Gauge("sensor_temperature_in_celsius", "Local room temperature around the raspberry pi", ["sensor"])
error_g = Gauge("faulty_sensor_read", "Is 1 if the sensor could not be read.", ["sensor"])
sensors = find_sensors()
print "Found sensors:", ", ".join(map(lambda x: str(x), sensors))
print( "Found sensors:", ", ".join(map(lambda x: str(x), sensors)))
for sensor in sensors:
g.labels(str(sensor)).set_function(sensor)
sensor.set_error_gauge(error_g.labels(str(sensor)))
Expand Down
6 changes: 6 additions & 0 deletions temperature_sensor.initd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/sbin/openrc-run
command="/usr/bin/env python /opt/prometheus_temperature/exporter.py"
pidfile="/run/${RC_SVCNAME}.pid"
command_args="-p ${pidfile}"
command_background=True

2 changes: 1 addition & 1 deletion temperature_sensor.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=Simple HTTP Service to measure temperature via local w1-Sensor
Before=prometheus.service

[Service]
ExecStart=/usr/bin/python /opt/prometheus_temperature/exporter.py --internal
ExecStart=/usr/bin/python /opt/prometheus_temperature/exporter.py

[Install]
WantedBy=multi-user.target