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

Add metrics for Shutter Contact #10

Open
wants to merge 6 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
25 changes: 23 additions & 2 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from homematicip.home import Home, EventType
from homematicip.device import WallMountedThermostatPro, TemperatureHumiditySensorWithoutDisplay, \
TemperatureHumiditySensorOutdoor, TemperatureHumiditySensorDisplay, ShutterContact, HeatingThermostat, \
PlugableSwitchMeasuring
PlugableSwitchMeasuring, WindowState

logging.basicConfig(level=logging.INFO, format='%(asctime)-15s %(message)s', datefmt="%Y-%m-%d %H:%M:%S")

Expand Down Expand Up @@ -137,6 +137,12 @@ def __init_metrics(self):
labelnames=labelnames,
namespace=namespace
)
self.metric_contact_open = prometheus_client.Gauge(
name='contact_open',
documentation='Shutter contact open (1 for open 0 for closed)',
labelnames=labelnames,
namespace=namespace
)
self.metric_device_event = prometheus_client.Counter(
name='device_event',
documentation='events triggered by a device',
Expand Down Expand Up @@ -193,6 +199,19 @@ def __collect_heating_metrics(self, room, device):
device.automaticValveAdaptionNeeded, device.temperatureOffset, device.valvePosition)
)

def __collect_shutter_metrics(self, room, device):
logging.info(
"found device: room: {}, label: {}, device_type: {}, firmware_version: {}, last_status_update: {}, permanently_reachable: {}"
.format(room, device.label, device.deviceType.lower(), device.firmwareVersion, device.lastStatusUpdate,
device.permanentlyReachable)
)

shutter_open = 0
if device.windowState != WindowState.CLOSED:
shutter_open = 1

self.metric_contact_open.labels(room=room, device_label=device.label).set(shutter_open)

def __collect_device_info_metrics(self,room, device):
logging.info(
"found device: room: {}, label: {}, device_type: {}, firmware_version: {}, last_status_update: {}, permanently_reachable: {}"
Expand Down Expand Up @@ -269,14 +288,16 @@ def collect(self):
elif isinstance(d, PlugableSwitchMeasuring):
logging.info("Device of type PlugableSwitchMeasuring")
self.__collect_power_metrics(g.label, d)
elif isinstance(d, ShutterContact):
self.__collect_shutter_metrics(g.label, d)

except Exception as e:
logging.warning(
"collecting status from device(s) failed with: {1}".format(str(e))
)
finally:
logging.info('waiting {}s before next collection cycle'.format(self.__collect_interval_seconds))
time.sleep(self.__collect_interval_seconds)
time.sleep(int(self.__collect_interval_seconds))


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
homematicip ~= 0.11.0
prometheus_client >= 0.8.0
homematicip ~= 0.13.0
prometheus_client >= 0.9.0