Last active
May 27, 2025 21:37
-
-
Save platinummonkey/8c9d51f97dc16e1a058eb28d72afe885 to your computer and use it in GitHub Desktop.
RedSea Reefmat Datadog Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| init_config: {} | |
| instances: | |
| - url: http://192.168.1.100/dashboard # Replace with your device's IP | |
| timeout: 5 | |
| tags: | |
| - location:reef_room | |
| - tank:310g_display | |
| - system:redsea_reefmat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datadog_checks.base import AgentCheck | |
| import requests | |
| class RedSeaReefMatCheck(AgentCheck): | |
| def __init__(self, name, init_config, instances): | |
| super(RedSeaReefMatCheck, self).__init__(name, init_config, instances) | |
| instance = self.instances[0] | |
| self.url = instance.get('url', 'http://127.0.0.1/dashboard') | |
| self.timeout = instance.get('timeout', 5) | |
| self.custom_tags = instance.get('tags', []) | |
| def check(self, _): | |
| try: | |
| response = requests.get(self.url, timeout=self.timeout) | |
| response.raise_for_status() | |
| data = response.json() | |
| except Exception as e: | |
| self.log.error(f"Error fetching ReefMat data: {e}") | |
| self.service_check("redsea_reefmat.can_connect", self.CRITICAL, tags=self.custom_tags) | |
| return | |
| self.service_check("redsea_reefmat.can_connect", self.OK, tags=self.custom_tags) | |
| # Boolean status flags | |
| self.gauge("redsea_reefmat.internet_connected", int(data.get("is_internet_connected", False)), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.ec_sensor_connected", int(data.get("is_ec_sensor_connected", False)), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.unclean_sensor", int(data.get("unclean_sensor", False)), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.auto_advance", int(data.get("auto_advance", False)), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.is_advancing", int(data.get("is_advancing", False)), tags=self.custom_tags) | |
| # Usage and lifecycle | |
| self.gauge("redsea_reefmat.remaining_length", data.get("remaining_length", 0), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.today_usage", data.get("today_usage", 0), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.daily_average_usage", data.get("daily_average_usage", 0), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.total_usage", data.get("total_usage", 0), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.days_till_end_of_roll", data.get("days_till_end_of_roll", 0), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.cumulative_steps", data.get("cumulative_steps", 0), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.lifetime_steps", data.get("lifetime_steps", 0), tags=self.custom_tags) | |
| # EC metrics | |
| self.gauge("redsea_reefmat.internal_ec_average", data.get("internal_ec_average", 0), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.external_ec_average", data.get("external_ec_average", 0), tags=self.custom_tags) | |
| # Roll level as tag | |
| roll_level = data.get("roll_level", "unknown") | |
| self.gauge("redsea_reefmat.roll_level", 1, tags=self.custom_tags + [f"roll_level:{roll_level}"]) | |
| # Material info | |
| material = data.get("material", {}) | |
| self.gauge("redsea_reefmat.material_external_diameter", material.get("external_diameter", 0), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.material_thickness", material.get("thickness", 0), tags=self.custom_tags) | |
| self.gauge("redsea_reefmat.material_is_partial", int(material.get("is_partial", False)), tags=self.custom_tags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment