I just want to let you know about a new addition coming to the nightly build - as soon as Stefan has approved the pull request and merged with the master code.
Here's some information describing what this all means.
Background
The previous value item logger always wrote to a text file. If the file became large, it also became a lot slower in viewing a graph of the data.
So the value item logger has been enhanced to log not only to individual files but also to a database! This will speed up the graph view many times.
I've chosen H2 as the database (I'm not associated with them), and you can find more information here: http://www.h2database.com/html/main.html.
All home items capable of logging their value (must implement the ValueItem class) and has a LoggerComponent object (pretty much every thermometer and moist item), will continue log to the file configured in the LogFile field. The name of the file is unchanged - so nothing will break.
But it is enhanced so you can prefix the name with file: for clarity and it will still log to a file. And if you prefix with jdbc:h2, it will log to a database instead. Configuring the individual LogFile field is what I'd like to call a local logger configuration. I suggest that you leave this field, as-is.
Now, the good part is that the Server Settings page has a new field, GlobalLogger, which is where you enable logging of all ValueItem home items - the global logger configuration. Simply configure the field the same way as mentioned earlier; either file: or jdbc:h2.
What this means is that it is now possible to let your home item optionally log locally and/or optionally log globally.
Here are some examples of how one would configure this field:
GlobalLogger
jdbc:h2:tcp://localhost/nhs_values.log
file:global_values.log, or simply global_values.log
Let's break that database configuration down:
- jdbc:h2 - prefix that states a database logger is to be configured
- :tcp://localhost/ - important as it sets up a connection with a new home item named H2DatabaseTCPServer running locally to the NetHomeServer - more on that later.
- nhs_values.log - the name of the database file name. There is currently one important table in this database and the name is VALUELOGGER.
The table will hold all home item values, and it can become large. But it will be a lot faster than those text files.
H2 Console
It is useful to be able to have a look at the database, and H2 allows us to do that by using a database console.
You can download their console from here: http://www.h2database.com/html/download.html.
On my Mac I double click the downloaded file: h2-1.4.190.jar, which launches the console. I can then see a small icon in the menu bar with some options to launch the H2 Console.
The address to the console is on my setup http://192.168.168.107:8082/. Yours might be different...
The fields I use are:
"Generic H2 Server"
Driver Class: "org.h2.Driver"
JDBC URL: "jdbc:h2:tcp://localhost/nhs_values.log"
User name and password are both set to "sa". These passwords will probably be configurable in a later release of the H2 integration.
H2DatabaseTCPServer
This is a new Home Item that is required in order to log to the database. Make sure to create one, and it is available in the Ports section.
You can leave out the port number on creating the item, as H2 will assign one for you - the port number is displayed when created. You can tweak it if you need to. The H2 TCP database server will run in its own process space locally to the NetHomeServer. The ConnectionString will expand to the ip adress shown in the home item, where as it is probably enough by setting the jdbc:h2 connection to localhost. You may have to elaborate with this depending on your environment. I guess some of you may want to have the database running on another machine - which I haven't tried yet - so please share your experiences with the rest of us.
With the H2DatabaseTCPServer and the GlobalLogger configured, you should be able to start viewing any incoming values of home items. However, you will not find many on startup, which brings us to the next section.
Import all local text files to the global logger
Yes, this is supported by a new button, Update Global Logger, also found on the Server Settings page.
When clicked, it will find all home items that have a configured LogFile that is a text file, and then import all values to the global logger.
No duplicates will be imported, so you can click this button at anytime and it will import any new values from the text file that are not in the database.
Be aware of that the import may take a considerable long time, especially on a raspi device.
On my Mac, it's a lot faster of course, but it depends on the size of the log files.
What I do is to connect via ssh to the raspi device and then tail the log file, like so: tail -f /var/log/nethome/HomeManager0.log. This will let me know how the import progresses.
So, a recap:
- Upgrade to the nightly build that includes the new Value Item Logger and restart your server.
- Create a H2DatabaseTCPServer item
- Configure the GlobalLogger
- Important: Do either one of the following:
1 Click to view at least one home item graph
2 Let some values be stored to the database. This varies as a new startup of the net home server will not logg values until the next coming hour.
Your best bet is the alternative #1.
In any case... this will automagically create the VALUELOGGER table and you can see this yourself in the log showing up as something similar to "Enabled global logging of type: LoggerComponentH2Database with descriptor: jdbc:h2:tcp://localhost/nhs_values.log". - With the table created, you should now be able to import all previous log files into the database.
- Refer to the logs for debugging/info messages.
- Use the H2 database console
Tip! Start the console after starting NetHomeServer or you won't be able to connect correctly. And if the console is started before the NetHomeServer, the port will probably already be occupied by the console as it will be started as the TCPServer. Check the NetHomeServer logs for messages.
https://github.com/SourceCodeSourcerer/ ... dbc_logger
If you have any comments, please leave a note here at the forum.
I also hope that this can be a trigger for some of you who wish to build upon this new enhancement and continue contribute to this great open source project!
Cheers!
/Peter