diff --git a/.gitignore b/.gitignore index 154af801d27ce962f91022e07a33878784d46c1f..e3410ed77f763b2affc7d65b0768e93b32fbcfc0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.vscode /eloparser_docker.code-workspace eloparser_public.code-workspace +powerflux.code-workspace /composer.phar /CHANGELOG.md /src/php_app/app.json diff --git a/README.md b/README.md index fcf6b852cb629549f99b04f4a584bfc040546b23..c17871bd68373ce68077d8b094dada8da3743cb8 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# eloparser +# PowerFlux ## Fetches data and writes to a InfluxDB database - Meter readings from Eloverblik (Power consumption per hour) - Spot prices from Energidataservice ->**Version: v0.54** +>**Version: v0.55** --- ### JSON Output from update.php @@ -28,7 +28,7 @@ Various info will be available, for use in Annotations in Grafana or for whateve ### [Install using Docker Compose (Recommended)](#install-using-docker-compose-recommended) -#### For the full stack - PHP app, webserver (nginx), database (InfluxDB) and data visualization (Grafana): +#### For the full stack - PHP app, webserver (nginx), database (InfluxDB) and data visualization (Grafana) 1. Insert your refresh token as a environment variable in docker-compose.yml 2. Run Docker Compose on docker-compose.yml @@ -39,9 +39,9 @@ Various info will be available, for use in Annotations in Grafana or for whateve - JSON output from PHP app is available on -##### Already got InfluxDB and Grafana? +#### Already got InfluxDB and Grafana? -##### docker-compose_nginxphp.yml provides a stack with only nginx and the PHP app and has environment variables set up ready for use in Portainer. +- Use docker-compose_nginxphp.yml - It provides a stack with only nginx and the PHP app and has environment variables set up ready for use in Portainer. ### [Manual installation](#manual-installation) @@ -49,7 +49,7 @@ Various info will be available, for use in Annotations in Grafana or for whateve 2. Run get_ancient.php to get "ancient" data (all years before current) - preferably in CLI to avoid problems with timeouts \ Please note that you only have to run get_ancient.php 1 time. Unless you have a time machine its unlikely that your power usage back in etc 2015 changes :D -3. Run update.php *(etc every 6 hours in a cronjob for continuously data retrieval)* +3. Run update.php *(etc every 1 hour in a cronjob to ensure continuously data retrieval)* --- @@ -58,7 +58,7 @@ Please note that you only have to run get_ancient.php 1 time. Unless you have a ### [Example of correct settings.json](#example-of-correct-settingsjson) -#### Not relevant if you use Docker. +#### Not relevant if you use Docker ```json { @@ -104,16 +104,19 @@ Please note that you only have to run get_ancient.php 1 time. Unless you have a ## Notes -[^first]: update.php will attempt to fetch new data from Eloverblik every 8 hours (*updateinterval* in Configuration class), for the latest entry in the InfluxDB database to the current date. Please note that Eloverblik will always provide data with 2~ days delay. \ -You can call this code every few seconds if you like to, it will only do calls to Eloverblik after 8 hours has passed since last successful request. \ +[^first]: update.php will attempt to fetch new data from Eloverblik every 6 hours (*updateinterval* in Configuration class), for the latest entry in the InfluxDB database to the current date. Please note that Eloverblik will always provide data with 2~ days delay. \ +You can call this code every few seconds if you like to, it will only do calls to Eloverblik after 6 hours has passed since last successful request. \ Docker version runs update.php every minute (a bit overkill yes). -- The code has been tested on Linux and Windows, on Windows you need to escape the paths specified in update.php, with \ or just use / instead, example: ```D:\\aFolder\anotherOne\\test1\\``` and ```D:/aFolder/anotherOne/test1/```should work. +- The PHP code and the Docker stack has been tested on Linux(Debian & Photon OS) and Windows 10 (x86-64). +- On Windows you need to escape the paths specified in update.php, with \ or just use / instead, example: ```D:\\aFolder\anotherOne\\test1\\``` and ```D:/aFolder/anotherOne/test1/```should work. -## Grafana and InfluxDB (Suggestion for manual installation) +## Grafana and InfluxDB (Suggestions for manual installation) If you want to use InfluxQL with InfluxDB 2.0+ you may need to create a DBRP mapping. \ List buckets with: ```influx v1 dbrp list``` \ Create bucket mapping with: ```influx v1 dbrp create --bucket-id yourBucketID --db yourBucket --rp autogen``` \ - \ -This only applies to InfluxQL, for Flux queries you don't need to do anything. \ No newline at end of file + \ +This only applies to InfluxQL, for Flux queries you don't need to do anything. + + Grafana - JSON source plugin, etc for use of JSON output: Infinity plugin - \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index d17699427b9bb84928b9c6623d39a6bcb7b48096..3f31eb47218572d15110e8cb37de8bd737c0b8a6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,9 +7,9 @@ services: dockerfile: ./ct_nginx/Dockerfile working_dir: /app volumes: - - vol_eloparser:/app + - vol_powerflux:/app networks: - - elostack + - powerfluxstack ports: - "8181:80" @@ -20,9 +20,9 @@ services: context: ./src dockerfile: ./ct_php-fpm/Dockerfile volumes: - - vol_eloparser:/app + - vol_powerflux:/app networks: - - elostack + - powerfluxstack environment: REFRESH_TOKEN: "yourRefreshTokenfromEloverblik" #For Portainer: ${REFRESH_TOKEN} INFLUXDB_URL: "http://influxdb:8086" #For Portainer: ${INFLUXDB_URL} @@ -39,7 +39,7 @@ services: - vol_influxdb_config:/etc/influxdb2 - vol_influxdb_data:/var/lib/influxdb2 networks: - - elostack + - powerfluxstack environment: INFLUXD_LOG_LEVEL: "info" INFLUXD_REPORTING_DISABLED: "true" @@ -64,7 +64,7 @@ services: volumes: - vol_grafana:/var/lib/grafana networks: - - elostack + - powerfluxstack environment: GF_ANALYTICS_REPORTING_ENABLED: "false" GF_AUTH_ANONYMOUS_ENABLED: "false" #You can switch this to true if you want to enable anonymous access (no login required). @@ -78,10 +78,10 @@ services: - influxdb volumes: - vol_eloparser: + vol_powerflux: vol_influxdb_config: vol_influxdb_data: vol_grafana: networks: - elostack: \ No newline at end of file + powerfluxstack: \ No newline at end of file diff --git a/docker-compose_nginxphp.yml b/docker-compose_nginxphp.yml index bad523c2dfab716278874762246d55777ba6a4e0..3c15f9deec24e9781fc8da48b1128ae47c834fe1 100644 --- a/docker-compose_nginxphp.yml +++ b/docker-compose_nginxphp.yml @@ -7,9 +7,9 @@ services: dockerfile: ./ct_nginx/Dockerfile working_dir: /app volumes: - - vol_eloparser:/app + - vol_powerflux:/app networks: - - elostack + - powerfluxstack ports: - "8181:80" @@ -20,9 +20,9 @@ services: context: ./src dockerfile: ./ct_php-fpm/Dockerfile volumes: - - vol_eloparser:/app + - vol_powerflux:/app networks: - - elostack + - powerfluxstack environment: REFRESH_TOKEN: ${REFRESH_TOKEN} # Portainer uses this to replace it with values from webinterface INFLUXDB_URL: ${INFLUXDB_URL} # If you don't want that see docker-compose.yml for a example of setting the values directly in here @@ -31,7 +31,7 @@ services: INFLUXDB_ORG: ${INFLUXDB_ORG} volumes: - vol_eloparser: + vol_powerflux: networks: - elostack: \ No newline at end of file + powerfluxstack: \ No newline at end of file diff --git a/src/ct_grafana/template_dashboard.json b/src/ct_grafana/template_dashboard.json index 8a7d324a448d3ddaaecbdb53c4de9c92d9020ac1..8743753ea8662f0e16c75e23d30126b200e6bc95 100644 --- a/src/ct_grafana/template_dashboard.json +++ b/src/ct_grafana/template_dashboard.json @@ -422,7 +422,7 @@ }, "timepicker": {}, "timezone": "", - "title": "Template Dashboard (Eloverblik)", + "title": "Template Dashboard (PowerFlux)", "uid": "lS1LLcv4k", "version": 1, "weekStart": "" diff --git a/src/ct_nginx/nginx.conf b/src/ct_nginx/nginx.conf index 75f07aa6ca6a9070d206f7e073cec027b6045e8f..3f41f0243b44df28cd4823ae0c9b909fa72ce701 100644 --- a/src/ct_nginx/nginx.conf +++ b/src/ct_nginx/nginx.conf @@ -1,7 +1,7 @@ server { listen 80 default; - client_max_body_size 128M; + client_max_body_size 16M; access_log /var/log/nginx/app_access.log; diff --git a/src/php_app/app/Elo/Common.php b/src/php_app/app/powerflux/Common.php similarity index 98% rename from src/php_app/app/Elo/Common.php rename to src/php_app/app/powerflux/Common.php index 137f49847ddc310400ef9d3b53e8d28b04709561..46b0bc376e26e7b4ae39548d6747fae628b659d2 100644 --- a/src/php_app/app/Elo/Common.php +++ b/src/php_app/app/powerflux/Common.php @@ -1,6 +1,6 @@ $yearstart->format($format), "stop"=> $yearend->format($format) ) ); } - //tmp fix + //tmp fix - Todo: Rework above if ( Common::getTimeDate(str: end($r)["start"], format: "Y") !== Common::getTimeDate(format: "Y") ) { $thisyear = Common::getDateTime("now"); $thisyear = $thisyear->modify("first day of January"); @@ -111,8 +111,6 @@ $end = $end->modify("+1 day"); //Tomorrow array_push($r, array("start"=>$thisyear->format($format), "stop"=> $end->format($format) ) ); } - - return $r ?? null; } @@ -238,11 +236,6 @@ array_push($r, array("start"=>$thisyear->format($format), "stop"=> $end->format( return null; } - public static function getDeviations(?int $deviation, $ts1, $ts2): ?int - { - return null; - } - /** * Get time difference in seconds between two Unix timestamps. //Todo, remove */ diff --git a/src/php_app/app/Elo/Configuration.php b/src/php_app/app/powerflux/Configuration.php similarity index 96% rename from src/php_app/app/Elo/Configuration.php rename to src/php_app/app/powerflux/Configuration.php index 31225fdc518fdadf56ab8ff5a4c26a0d8fcd7940..1f09bf55a1c6728994081854e84133c44df0e6c0 100644 --- a/src/php_app/app/Elo/Configuration.php +++ b/src/php_app/app/powerflux/Configuration.php @@ -1,15 +1,15 @@ = 10) { return $str; } @@ -105,7 +105,7 @@ public static function isValidBucket($str): string { } } } - return $r ?? null; //ErrorOutput::handleError(ERRORCODES::INFLUX_GETLATEST); + return $r ?? null; } public static function doAncientPeriods($periods, $meter) { @@ -128,8 +128,6 @@ public static function isValidBucket($str): string { } - - /** Writes meter readings to InfluxDB database. * */ diff --git a/src/php_app/app/Elo/Parser.php b/src/php_app/app/powerflux/Parser.php similarity index 98% rename from src/php_app/app/Elo/Parser.php rename to src/php_app/app/powerflux/Parser.php index c2d501f5cb202e5054e264f86f93ba2fff5ee040..5ddb483444b09b40e0ef74c5f7b0e05d82c5ab92 100644 --- a/src/php_app/app/Elo/Parser.php +++ b/src/php_app/app/powerflux/Parser.php @@ -1,9 +1,9 @@ array("meteringPoint" => array( $meterid ) )), JSON_PRETTY_PRINT); diff --git a/src/php_app/app/Elo/Prices.php b/src/php_app/app/powerflux/Prices.php similarity index 99% rename from src/php_app/app/Elo/Prices.php rename to src/php_app/app/powerflux/Prices.php index 1ae524d84c43bfa88d27f72bbefd1d9d0dc106a8..5dee8fc36bad628db4894d73c055c84fd6215766 100644 --- a/src/php_app/app/Elo/Prices.php +++ b/src/php_app/app/powerflux/Prices.php @@ -1,6 +1,6 @@