├── VERSION ├── anern_monitoring ├── __init__.py ├── anern_inverter │ ├── __init__.py │ └── inverter.py └── app.py ├── setup.cfg ├── requirements.txt ├── .gitignore ├── grafana ├── config.monitoring └── provisioning │ ├── dashboards │ ├── dashboard.yml │ └── power_monitoring.json │ └── datasources │ └── datasource.yml ├── Dockerfile ├── setup.py ├── prometheus └── prometheus.yml ├── Makefile ├── compose.yml └── LICENSE /VERSION: -------------------------------------------------------------------------------- 1 | 0.1 -------------------------------------------------------------------------------- /anern_monitoring/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /anern_monitoring/anern_inverter/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | aiohttp==3.8.3 2 | pyserial==3.5 3 | gunicorn==20.1.0 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | venv 2 | .env 3 | build 4 | dist 5 | *.build 6 | *.dist 7 | __pycache__ 8 | *.egg-info 9 | .idea -------------------------------------------------------------------------------- /grafana/config.monitoring: -------------------------------------------------------------------------------- 1 | GF_SECURITY_ADMIN_USER=admin 2 | GF_SECURITY_ADMIN_PASSWORD=foobar 3 | GF_USERS_ALLOW_SIGN_UP=false -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM library/python:3.9-slim 2 | 3 | WORKDIR /app 4 | ADD . /app 5 | 6 | RUN python setup.py install 7 | 8 | EXPOSE 8081 9 | -------------------------------------------------------------------------------- /grafana/provisioning/dashboards/dashboard.yml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | providers: 4 | - name: 'Prometheus' 5 | orgId: 1 6 | folder: '' 7 | type: file 8 | disableDeletion: false 9 | editable: true 10 | options: 11 | path: /etc/grafana/provisioning/dashboards -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | 4 | def _get_version(): 5 | with open('VERSION') as fd: 6 | return fd.read().strip() 7 | 8 | 9 | install_requires = [ 10 | 'aiohttp==3.8.3', 11 | 'pyserial==3.5', 12 | 'gunicorn==20.1.0', 13 | ] 14 | 15 | setup( 16 | name='anern_monitoring', 17 | version=_get_version(), 18 | include_package_data=True, 19 | install_requires=install_requires, 20 | packages=find_packages(), 21 | ) 22 | -------------------------------------------------------------------------------- /prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 1m 3 | scrape_timeout: 10s 4 | evaluation_interval: 15s 5 | alerting: 6 | alertmanagers: 7 | - static_configs: 8 | - targets: [ ] 9 | scheme: http 10 | timeout: 10s 11 | api_version: v1 12 | scrape_configs: 13 | - job_name: anern_monitoring 14 | honor_timestamps: true 15 | metrics_path: /metrics 16 | scheme: http 17 | static_configs: 18 | - targets: 19 | - 'anern_monitoring:8081' 20 | - job_name: prometheus 21 | static_configs: 22 | - targets: 23 | - 'localhost:9090' -------------------------------------------------------------------------------- /anern_monitoring/app.py: -------------------------------------------------------------------------------- 1 | from aiohttp import web 2 | 3 | from .anern_inverter.inverter import Inverter 4 | 5 | _inverter = None 6 | 7 | 8 | async def health(request): 9 | return web.Response(text="

Async Rest API using aiohttp : Health OK

", 10 | content_type='text/html') 11 | 12 | 13 | def get_inverter() -> Inverter: 14 | global _inverter 15 | if _inverter is None: 16 | _inverter = Inverter('/dev/ttyUSB0') 17 | return _inverter 18 | 19 | 20 | async def get_metrics(request): 21 | inverter = get_inverter() 22 | data = inverter.get_qpigs() 23 | return web.Response( 24 | text='\n'.join([f'{key} {value}' for key, value in data.items()]), 25 | content_type='text/plain' 26 | ) 27 | 28 | 29 | def init(): 30 | app = web.Application() 31 | app.router.add_get("/", health) 32 | app.router.add_get("/metrics", get_metrics) 33 | return app 34 | 35 | 36 | monitoring_app = init() 37 | 38 | if __name__ == "__main__": 39 | web.run_app(monitoring_app, port=8000) 40 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: deps install clean build_clean dist_clean tests dist docker 2 | 3 | ENV=.env 4 | PYTHON_VERSION=3 5 | PYTHON=python${PYTHON_VERSION} 6 | SITE_PACKAGES=${ENV}/lib/${PYTHON}/site-packages 7 | IN_ENV=. ${ENV}/bin/activate; 8 | PACKAGE_VERSION=$(shell cat VERSION) 9 | 10 | default: ${ENV} deps 11 | 12 | ${ENV}: 13 | @echo "Creating Python environment..." >&2 14 | @${PYTHON} -m venv ${ENV} 15 | @echo "Updating pip..." >&2 16 | @${IN_ENV} ${PYTHON} -m pip install -U pip setuptools 17 | 18 | ${SITE_PACKAGES}/aiohttp: ${ENV} 19 | @${IN_ENV} ${PYTHON} -m pip install -r requirements.txt 20 | 21 | ${SITE_PACKAGES}/anern_monitoring: ${ENV} install 22 | 23 | deps: ${SITE_PACKAGES}/aiohttp 24 | 25 | install: default 26 | @${IN_ENV} ${PYTHON} -m pip install -e . 27 | 28 | wheel: ${ENV} 29 | @${IN_ENV} ${PYTHON} -m pip install -U wheel 30 | @${IN_ENV} ${PYTHON} setup.py bdist_wheel 31 | 32 | dist: wheel 33 | 34 | dist_clean: 35 | @rm -rf dist 36 | 37 | build_clean: 38 | @rm -rf build 39 | 40 | clean: build_clean dist_clean 41 | @rm -rf ${ENV} dist build __pycache__ *.egg-info 42 | 43 | docker: build_clean dist_clean wheel 44 | @docker build -t anern_monitoring:${PACKAGE_VERSION} . 45 | @docker tag anern_monitoring:${PACKAGE_VERSION} anern_monitoring:latest -------------------------------------------------------------------------------- /compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.2' 2 | 3 | services: 4 | anern_monitoring: 5 | build: . 6 | privileged: true 7 | volumes: 8 | - ./:/app 9 | - /dev:/dev 10 | command: gunicorn anern_monitoring.app:monitoring_app -b :8081 --worker-class aiohttp.GunicornWebWorker --reload --access-logfile - 11 | ports: 12 | - "8081:8081" 13 | 14 | prometheus: 15 | image: prom/prometheus:latest 16 | volumes: 17 | - ./prometheus:/etc/prometheus 18 | - ~/prometheus_data:/prometheus 19 | command: 20 | - '--config.file=/etc/prometheus/prometheus.yml' 21 | - '--storage.tsdb.path=/prometheus' 22 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 23 | - '--web.console.templates=/usr/share/prometheus/consoles' 24 | links: 25 | - anern_monitoring 26 | ports: 27 | - 9090:9090 28 | 29 | grafana: 30 | image: grafana/grafana 31 | user: '472' 32 | restart: always 33 | environment: 34 | GF_INSTALL_PLUGINS: 'grafana-clock-panel,grafana-simple-json-datasource' 35 | volumes: 36 | - ~/grafana_data:/var/lib/grafana 37 | - ./grafana/provisioning/:/etc/grafana/provisioning/ 38 | env_file: 39 | - ./grafana/config.monitoring 40 | ports: 41 | - 3000:3000 42 | depends_on: 43 | - prometheus -------------------------------------------------------------------------------- /grafana/provisioning/datasources/datasource.yml: -------------------------------------------------------------------------------- 1 | # config file version 2 | apiVersion: 1 3 | 4 | # list of datasources that should be deleted from the database 5 | deleteDatasources: 6 | - name: Prometheus 7 | orgId: 1 8 | 9 | # list of datasources to insert/update depending 10 | # whats available in the database 11 | datasources: 12 | # name of the datasource. Required 13 | - name: Prometheus 14 | # datasource type. Required 15 | type: prometheus 16 | # access mode. direct or proxy. Required 17 | access: proxy 18 | # org id. will default to orgId 1 if not specified 19 | orgId: 1 20 | # url 21 | url: http://prometheus:9090 22 | # database password, if used 23 | password: 24 | # database user, if used 25 | user: 26 | # database name, if used 27 | database: 28 | # enable/disable basic auth 29 | basicAuth: false 30 | # basic auth username, if used 31 | basicAuthUser: 32 | # basic auth password, if used 33 | basicAuthPassword: 34 | # enable/disable with credentials headers 35 | withCredentials: 36 | # mark as default datasource. Max one per org 37 | isDefault: true 38 | # fields that will be converted to json and stored in json_data 39 | jsonData: 40 | graphiteVersion: "1.1" 41 | tlsAuth: false 42 | tlsAuthWithCACert: false 43 | # json object of data that will be encrypted. 44 | secureJsonData: 45 | tlsCACert: "..." 46 | tlsClientCert: "..." 47 | tlsClientKey: "..." 48 | version: 1 49 | # allow users to edit datasources from the UI. 50 | editable: true -------------------------------------------------------------------------------- /anern_monitoring/anern_inverter/inverter.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | import re 3 | import time 4 | from threading import Lock 5 | 6 | import serial 7 | 8 | 9 | class BasicCommand: 10 | command: bytes = b'' 11 | response_fmt: re.Pattern = re.compile('') 12 | response_typing: dict = {} 13 | 14 | @staticmethod 15 | def compute_crc(message: str) -> bytes: 16 | crc = 0 17 | crc_ta = [ 18 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 19 | 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef 20 | ] 21 | 22 | for c in message: 23 | c = ord(c) 24 | 25 | t_da = ctypes.c_uint8(crc >> 8) 26 | da = t_da.value >> 4 27 | crc <<= 4 28 | index = da ^ (c >> 4) 29 | crc ^= crc_ta[index] 30 | t_da = ctypes.c_uint8(crc >> 8) 31 | da = t_da.value >> 4 32 | crc <<= 4 33 | index = da ^ (c & 0x0f) 34 | crc ^= crc_ta[index] 35 | 36 | crc_low = ctypes.c_uint8(crc).value 37 | crc_high = ctypes.c_uint8(crc >> 8).value 38 | 39 | if crc_low in (0x28, 0x0d, 0x0a): 40 | crc_low += 1 41 | 42 | if crc_high in (0x28, 0x0d, 0x0a): 43 | crc_high += 1 44 | 45 | return bytes((crc_high, crc_low)) 46 | 47 | def fmt_command(self) -> bytes: 48 | crc = self.compute_crc(self.command.decode('utf8')) 49 | return self.command + crc + b'\r' 50 | 51 | 52 | class QPIRI(BasicCommand): 53 | command = b'QPIRI' 54 | 55 | 56 | class QPIGS(BasicCommand): 57 | command = b'QPIGS' 58 | response_fmt = re.compile( 59 | r'(?P\d{3}\.\d{1}) ' # V 60 | r'(?P\d{2}\.\d{1}) ' # Hz 61 | r'(?P\d{3}\.\d{1}) ' # V 62 | r'(?P\d{2}\.\d{1}) ' # Hz 63 | r'(?P\d{4}) ' # VA 64 | r'(?P\d{4}) ' # W 65 | r'(?P\d{3}) ' # % 66 | r'(?P\d{3}) ' # V 67 | r'(?P\d{2}\.\d{2}) ' # V 68 | r'(?P\d{3}) ' # A 69 | r'(?P\d{3}) ' # % 70 | r'(?P\d{4}) ' # C 71 | r'(?P\d{2}\.\d{1}) ' # A 72 | r'(?P\d{3}\.\d{1}) ' # C 73 | r'(?P\d{2}\.\d{2}) ' # V 74 | r'(?P\d{5}) ' # A 75 | r'(?P\d{8}) ' # 76 | r'(?P\d{2}) ' # 77 | r'(?P\d{2}) ' # 78 | r'(?P\d{5}) ' # W 79 | r'(?P\d{3})' # 80 | ) 81 | response_typing = { 82 | 'grid_voltage': float, 83 | 'grid_frequency': float, 84 | 'ac_output_voltage': float, 85 | 'ac_output_frequency': float, 86 | 'ac_output_apparent_power': int, 87 | 'ac_output_active_power': int, 88 | 'ac_output_load': int, 89 | 'bus_voltage': int, 90 | 'battery_voltage': float, 91 | 'battery_charging_current': int, 92 | 'battery_percent': int, 93 | 'heat_sink_temperature': int, 94 | 'pv_current': float, 95 | 'pv_voltage': float, 96 | 'scc_voltage': float, 97 | 'battery_discharge_current': int, 98 | 'smth_1': str, 99 | 'smth_2': int, 100 | 'smth_3': int, 101 | 'pv_power': int, 102 | 'smth_4': int, 103 | } 104 | 105 | 106 | class Inverter: 107 | BAUD = 2400 108 | PARITY = serial.PARITY_NONE 109 | TIMEOUT = 1 110 | 111 | _comm_port = None 112 | 113 | def __init__(self, serial_device: str) -> None: 114 | self.serial_device: str = serial_device 115 | self._lock: Lock = Lock() 116 | 117 | @property 118 | def comm_port(self): 119 | if self._comm_port is None: 120 | self._comm_port = serial.Serial( 121 | port=self.serial_device, 122 | baudrate=self.BAUD, 123 | parity=self.PARITY, 124 | timeout=self.TIMEOUT 125 | ) 126 | return self._comm_port 127 | 128 | def _parse_response(self, response: bytes, command_cls: BasicCommand) -> dict: 129 | if not response.startswith(b'('): 130 | raise RuntimeError('Got bad response from inverter') 131 | if not response.endswith(b'\r'): 132 | raise RuntimeError('Got bad response from inverter') 133 | 134 | stripped_response = response[1:-3].decode('utf-8') 135 | response_fmt = command_cls.response_fmt 136 | response_typing = command_cls.response_typing 137 | response_crc = BasicCommand.compute_crc(stripped_response) 138 | 139 | parsed_response = response_fmt.match(stripped_response) 140 | if parsed_response is None: 141 | raise RuntimeError('Inverter response does not match expected format') 142 | 143 | return { 144 | key: response_typing[key](value) 145 | for key, value in parsed_response.groupdict().items() 146 | } 147 | 148 | def get_qpigs(self) -> dict: 149 | qpigs = QPIGS() 150 | with self._lock: 151 | self.comm_port.write(qpigs.fmt_command()) 152 | time.sleep(0.5) 153 | response = self.comm_port.readline() 154 | return self._parse_response(response, qpigs) 155 | 156 | def get_qpiri(self) -> bytes: 157 | qpiri_command = QPIRI() 158 | with self._lock: 159 | self.comm_port.write(qpiri_command.fmt_command()) 160 | time.sleep(0.5) 161 | response = self.comm_port.readline() 162 | return response.strip() 163 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /grafana/provisioning/dashboards/power_monitoring.json: -------------------------------------------------------------------------------- 1 | { 2 | "annotations": { 3 | "list": [ 4 | { 5 | "builtIn": 1, 6 | "datasource": { 7 | "type": "grafana", 8 | "uid": "-- Grafana --" 9 | }, 10 | "enable": true, 11 | "hide": true, 12 | "iconColor": "rgba(0, 211, 255, 1)", 13 | "name": "Annotations & Alerts", 14 | "target": { 15 | "limit": 100, 16 | "matchAny": false, 17 | "tags": [], 18 | "type": "dashboard" 19 | }, 20 | "type": "dashboard" 21 | } 22 | ] 23 | }, 24 | "editable": true, 25 | "fiscalYearStartMonth": 0, 26 | "graphTooltip": 0, 27 | "id": 2, 28 | "links": [], 29 | "liveNow": false, 30 | "panels": [ 31 | { 32 | "datasource": { 33 | "type": "prometheus", 34 | "uid": "PBFA97CFB590B2093" 35 | }, 36 | "description": "Power usage", 37 | "fieldConfig": { 38 | "defaults": { 39 | "color": { 40 | "mode": "palette-classic" 41 | }, 42 | "custom": { 43 | "axisCenteredZero": false, 44 | "axisColorMode": "text", 45 | "axisLabel": "", 46 | "axisPlacement": "auto", 47 | "barAlignment": 0, 48 | "drawStyle": "line", 49 | "fillOpacity": 0, 50 | "gradientMode": "none", 51 | "hideFrom": { 52 | "legend": false, 53 | "tooltip": false, 54 | "viz": false 55 | }, 56 | "lineInterpolation": "smooth", 57 | "lineWidth": 1, 58 | "pointSize": 5, 59 | "scaleDistribution": { 60 | "type": "linear" 61 | }, 62 | "showPoints": "auto", 63 | "spanNulls": false, 64 | "stacking": { 65 | "group": "A", 66 | "mode": "none" 67 | }, 68 | "thresholdsStyle": { 69 | "mode": "off" 70 | } 71 | }, 72 | "mappings": [], 73 | "thresholds": { 74 | "mode": "absolute", 75 | "steps": [ 76 | { 77 | "color": "green", 78 | "value": null 79 | }, 80 | { 81 | "color": "red", 82 | "value": 80 83 | } 84 | ] 85 | }, 86 | "unit": "kwatth" 87 | }, 88 | "overrides": [] 89 | }, 90 | "gridPos": { 91 | "h": 8, 92 | "w": 12, 93 | "x": 0, 94 | "y": 0 95 | }, 96 | "id": 8, 97 | "interval": "1m", 98 | "options": { 99 | "legend": { 100 | "calcs": [ 101 | "sum" 102 | ], 103 | "displayMode": "table", 104 | "placement": "right", 105 | "showLegend": true 106 | }, 107 | "tooltip": { 108 | "mode": "single", 109 | "sort": "none" 110 | } 111 | }, 112 | "targets": [ 113 | { 114 | "datasource": { 115 | "type": "prometheus", 116 | "uid": "PBFA97CFB590B2093" 117 | }, 118 | "editorMode": "code", 119 | "expr": "ac_output_active_power{instance=\"anern_monitoring:8081\"} / 60 / 1000", 120 | "legendFormat": "Power consumption (kWh)", 121 | "range": true, 122 | "refId": "A" 123 | }, 124 | { 125 | "datasource": { 126 | "type": "prometheus", 127 | "uid": "PBFA97CFB590B2093" 128 | }, 129 | "editorMode": "code", 130 | "expr": "pv_power{instance=\"anern_monitoring:8081\"} / 60 / 1000", 131 | "hide": false, 132 | "legendFormat": "Power generation (PV)", 133 | "range": true, 134 | "refId": "B" 135 | }, 136 | { 137 | "datasource": { 138 | "type": "prometheus", 139 | "uid": "PBFA97CFB590B2093" 140 | }, 141 | "editorMode": "code", 142 | "exemplar": false, 143 | "expr": "ac_output_active_power{instance=\"anern_monitoring:8081\"} / 60 / 1000 - pv_power{instance=\"anern_monitoring:8081\"} / 60 / 1000", 144 | "format": "time_series", 145 | "hide": false, 146 | "instant": false, 147 | "legendFormat": "Difference", 148 | "range": true, 149 | "refId": "C" 150 | } 151 | ], 152 | "title": "Power usage vs generation", 153 | "transformations": [], 154 | "type": "timeseries" 155 | }, 156 | { 157 | "datasource": { 158 | "type": "prometheus", 159 | "uid": "PBFA97CFB590B2093" 160 | }, 161 | "description": "Power consumption vs generation", 162 | "fieldConfig": { 163 | "defaults": { 164 | "color": { 165 | "mode": "palette-classic" 166 | }, 167 | "custom": { 168 | "axisCenteredZero": false, 169 | "axisColorMode": "text", 170 | "axisLabel": "", 171 | "axisPlacement": "auto", 172 | "barAlignment": 0, 173 | "drawStyle": "line", 174 | "fillOpacity": 0, 175 | "gradientMode": "none", 176 | "hideFrom": { 177 | "legend": false, 178 | "tooltip": false, 179 | "viz": false 180 | }, 181 | "lineInterpolation": "smooth", 182 | "lineWidth": 1, 183 | "pointSize": 5, 184 | "scaleDistribution": { 185 | "type": "linear" 186 | }, 187 | "showPoints": "auto", 188 | "spanNulls": false, 189 | "stacking": { 190 | "group": "A", 191 | "mode": "none" 192 | }, 193 | "thresholdsStyle": { 194 | "mode": "off" 195 | } 196 | }, 197 | "mappings": [], 198 | "thresholds": { 199 | "mode": "absolute", 200 | "steps": [ 201 | { 202 | "color": "green", 203 | "value": null 204 | }, 205 | { 206 | "color": "red", 207 | "value": 80 208 | } 209 | ] 210 | }, 211 | "unit": "watt" 212 | }, 213 | "overrides": [] 214 | }, 215 | "gridPos": { 216 | "h": 8, 217 | "w": 12, 218 | "x": 12, 219 | "y": 0 220 | }, 221 | "id": 2, 222 | "interval": "1m", 223 | "options": { 224 | "legend": { 225 | "calcs": [ 226 | "lastNotNull" 227 | ], 228 | "displayMode": "table", 229 | "placement": "right", 230 | "showLegend": true 231 | }, 232 | "tooltip": { 233 | "mode": "single", 234 | "sort": "none" 235 | } 236 | }, 237 | "targets": [ 238 | { 239 | "datasource": { 240 | "type": "prometheus", 241 | "uid": "PBFA97CFB590B2093" 242 | }, 243 | "editorMode": "builder", 244 | "expr": "ac_output_active_power{instance=\"anern_monitoring:8081\"}", 245 | "legendFormat": "Power load", 246 | "range": true, 247 | "refId": "A" 248 | }, 249 | { 250 | "datasource": { 251 | "type": "prometheus", 252 | "uid": "PBFA97CFB590B2093" 253 | }, 254 | "editorMode": "builder", 255 | "expr": "pv_power{instance=\"anern_monitoring:8081\"}", 256 | "hide": false, 257 | "legendFormat": "PV Power generation", 258 | "range": true, 259 | "refId": "B" 260 | } 261 | ], 262 | "title": "Power load vs generation", 263 | "type": "timeseries" 264 | }, 265 | { 266 | "datasource": { 267 | "type": "prometheus", 268 | "uid": "PBFA97CFB590B2093" 269 | }, 270 | "description": "Battery capacity", 271 | "fieldConfig": { 272 | "defaults": { 273 | "color": { 274 | "mode": "palette-classic" 275 | }, 276 | "custom": { 277 | "axisCenteredZero": false, 278 | "axisColorMode": "text", 279 | "axisLabel": "", 280 | "axisPlacement": "auto", 281 | "barAlignment": 0, 282 | "drawStyle": "line", 283 | "fillOpacity": 0, 284 | "gradientMode": "none", 285 | "hideFrom": { 286 | "legend": false, 287 | "tooltip": false, 288 | "viz": false 289 | }, 290 | "lineInterpolation": "smooth", 291 | "lineWidth": 1, 292 | "pointSize": 5, 293 | "scaleDistribution": { 294 | "type": "linear" 295 | }, 296 | "showPoints": "auto", 297 | "spanNulls": false, 298 | "stacking": { 299 | "group": "A", 300 | "mode": "none" 301 | }, 302 | "thresholdsStyle": { 303 | "mode": "off" 304 | } 305 | }, 306 | "mappings": [], 307 | "thresholds": { 308 | "mode": "absolute", 309 | "steps": [ 310 | { 311 | "color": "green", 312 | "value": null 313 | }, 314 | { 315 | "color": "red", 316 | "value": 80 317 | } 318 | ] 319 | }, 320 | "unit": "percent" 321 | }, 322 | "overrides": [] 323 | }, 324 | "gridPos": { 325 | "h": 8, 326 | "w": 12, 327 | "x": 0, 328 | "y": 8 329 | }, 330 | "id": 6, 331 | "interval": "1m", 332 | "options": { 333 | "legend": { 334 | "calcs": [ 335 | "lastNotNull" 336 | ], 337 | "displayMode": "table", 338 | "placement": "right", 339 | "showLegend": true 340 | }, 341 | "tooltip": { 342 | "mode": "single", 343 | "sort": "none" 344 | } 345 | }, 346 | "targets": [ 347 | { 348 | "datasource": { 349 | "type": "prometheus", 350 | "uid": "PBFA97CFB590B2093" 351 | }, 352 | "editorMode": "builder", 353 | "expr": "battery_percent{instance=\"anern_monitoring:8081\"}", 354 | "legendFormat": "Battery capacity", 355 | "range": true, 356 | "refId": "A" 357 | } 358 | ], 359 | "title": "Battery capacity", 360 | "type": "timeseries" 361 | }, 362 | { 363 | "datasource": { 364 | "type": "prometheus", 365 | "uid": "PBFA97CFB590B2093" 366 | }, 367 | "description": "Grid voltage", 368 | "fieldConfig": { 369 | "defaults": { 370 | "color": { 371 | "mode": "palette-classic" 372 | }, 373 | "custom": { 374 | "axisCenteredZero": false, 375 | "axisColorMode": "text", 376 | "axisLabel": "", 377 | "axisPlacement": "auto", 378 | "barAlignment": 0, 379 | "drawStyle": "line", 380 | "fillOpacity": 0, 381 | "gradientMode": "none", 382 | "hideFrom": { 383 | "legend": false, 384 | "tooltip": false, 385 | "viz": false 386 | }, 387 | "lineInterpolation": "smooth", 388 | "lineWidth": 1, 389 | "pointSize": 5, 390 | "scaleDistribution": { 391 | "type": "linear" 392 | }, 393 | "showPoints": "auto", 394 | "spanNulls": false, 395 | "stacking": { 396 | "group": "A", 397 | "mode": "none" 398 | }, 399 | "thresholdsStyle": { 400 | "mode": "off" 401 | } 402 | }, 403 | "mappings": [], 404 | "thresholds": { 405 | "mode": "absolute", 406 | "steps": [ 407 | { 408 | "color": "green", 409 | "value": null 410 | }, 411 | { 412 | "color": "red", 413 | "value": 80 414 | } 415 | ] 416 | }, 417 | "unit": "volt" 418 | }, 419 | "overrides": [] 420 | }, 421 | "gridPos": { 422 | "h": 8, 423 | "w": 12, 424 | "x": 12, 425 | "y": 8 426 | }, 427 | "id": 4, 428 | "interval": "1m", 429 | "options": { 430 | "legend": { 431 | "calcs": [ 432 | "lastNotNull" 433 | ], 434 | "displayMode": "table", 435 | "placement": "right", 436 | "showLegend": true 437 | }, 438 | "tooltip": { 439 | "mode": "single", 440 | "sort": "none" 441 | } 442 | }, 443 | "targets": [ 444 | { 445 | "datasource": { 446 | "type": "prometheus", 447 | "uid": "PBFA97CFB590B2093" 448 | }, 449 | "editorMode": "builder", 450 | "expr": "grid_voltage{instance=\"anern_monitoring:8081\"}", 451 | "legendFormat": "Grid voltage", 452 | "range": true, 453 | "refId": "A" 454 | } 455 | ], 456 | "title": "Grid voltage", 457 | "type": "timeseries" 458 | } 459 | ], 460 | "schemaVersion": 37, 461 | "style": "dark", 462 | "tags": [], 463 | "templating": { 464 | "list": [] 465 | }, 466 | "time": { 467 | "from": "now-12h", 468 | "to": "now" 469 | }, 470 | "timepicker": {}, 471 | "timezone": "", 472 | "title": "Power monitoring", 473 | "uid": "l2a2zy04k", 474 | "version": 14, 475 | "weekStart": "" 476 | } --------------------------------------------------------------------------------