diff --git a/README.md b/README.md index 877aff5..4c2441d 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ python exporter.py --help ### Install/Run 1. edit the docker-compose.yml file and put there the correct IP - (port and scrape interval are optional values) + (other values are optional) 2. from command line run: ``` @@ -86,8 +86,10 @@ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' good curl http://:8787 ```
-
-## TBD +### Supported parameters -- option to disable default python metrics +`--inverter ` - [required] IP address of the iverter. To get the IP Address, you can run the `inverter_scan.py` script. +`--port ` - [optional][default: 8787] port, on which the exporter should expose the metrics +`--interval ` - [optional][default: 30] interval between scrapings in seconds. +`--energy-price ` - [optional][default: 0.15] energy price per kwh (in eur ) diff --git a/src/exporter.py b/src/exporter.py index d164998..001d0c2 100644 --- a/src/exporter.py +++ b/src/exporter.py @@ -16,17 +16,19 @@ def checkArgs(argv): global EXPORTER_PORT global POLLING_INTERVAL global INVERTER_IP + global ENERGY_PRICE # set default values EXPORTER_PORT = 8787 POLLING_INTERVAL = 30 + ENERGY_PRICE = 0.15 INVERTER_IP = "" # help - arg_help = "{0} --port --interval --inverter ".format(argv[0]) + arg_help = "{0} --port --interval --inverter --energy-price ".format(argv[0]) try: - opts, args = getopt.getopt(argv[1:], "hp:t:i:", ["help", "port=", "interval=", "inverter="]) + opts, args = getopt.getopt(argv[1:], "hp:t:i:", ["help", "port=", "interval=", "inverter=", "energy-price="]) except: print(arg_help) sys.exit(2) @@ -41,6 +43,8 @@ def checkArgs(argv): POLLING_INTERVAL = arg elif opt in ("-i", "--inverter"): INVERTER_IP = arg + elif opt in ("-e", "--energy-price"): + ENERGY_PRICE = arg # check if Inverter IP is set if not INVERTER_IP: @@ -50,8 +54,9 @@ def checkArgs(argv): class InverterMetrics: - def __init__(self, g, i, POLLING_INTERVAL): + def __init__(self, g, i, POLLING_INTERVAL,ENERGY_PRICE): self.POLLING_INTERVAL = POLLING_INTERVAL + self.ENERGY_PRICE = ENERGY_PRICE self.metricsCount = 0 self.g = g self.i = i @@ -69,6 +74,9 @@ async def create_collector_registers(): elif sensor.id_ in runtime_data and sensor.id_ != "timestamp" and type(runtime_data[sensor.id_]) != int: self.i.append(Info(sensor.id_, sensor.name)) + # add additional energy-price + self.g.append(Gauge("energy_price", "Energy price per KW")) + asyncio.run(create_collector_registers()) @@ -93,7 +101,9 @@ async def fetch_inverter(): self.g[countID].set(str(runtime_data[sensor.id_])) countID+=1 - self.metricsCount=len(self.g)-1 + # set value for additional energy-price + self.g[countID].set(float(ENERGY_PRICE)) + self.metricsCount=len(self.g) asyncio.run(fetch_inverter()) @@ -109,9 +119,11 @@ def main(): print("polling interval:\t\t"+str(POLLING_INTERVAL)+"s") print("inverter scrape IP:\t\t"+str(INVERTER_IP)) + print("energy price: \t\t\t"+str(ENERGY_PRICE)+"eur") inverter_metrics = InverterMetrics( POLLING_INTERVAL=int(POLLING_INTERVAL), + ENERGY_PRICE=ENERGY_PRICE, g=[], i=[] )