Skip to content

Commit

Permalink
Merge branch 'static_values' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
gustonator committed Feb 5, 2023
2 parents a816fb4 + dff3789 commit 377ae43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand All @@ -86,8 +86,10 @@ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' good
curl http://<IP>:8787
```
</br>
</br>

## TBD
### Supported parameters

- option to disable default python metrics
`--inverter <inverterIP>` - [required] IP address of the iverter. To get the IP Address, you can run the `inverter_scan.py` script.
`--port <desired port>` - [optional][default: 8787] port, on which the exporter should expose the metrics
`--interval <interval (s)>` - [optional][default: 30] interval between scrapings in seconds.
`--energy-price <value>` - [optional][default: 0.15] energy price per kwh (in eur )
20 changes: 16 additions & 4 deletions src/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <exporter port [default:8787]> --interval <scrape interval (seconds) [default:30]> --inverter <inverter IP>".format(argv[0])
arg_help = "{0} --port <exporter port [default:8787]> --interval <scrape interval (seconds) [default:30]> --inverter <inverter IP> --energy-price <price per KWh in eur [default: 0.15>".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)
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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())


Expand All @@ -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())

Expand All @@ -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=[]
)
Expand Down

0 comments on commit 377ae43

Please sign in to comment.