[SOLVED] InfluxDB Database Size to show As Number Item?

Hi,

I have been using Grafana for Trending & Historical Data. But i am curious about database size increasing due to multiple sensors.

I have installed systeminfo Binding that gives me total size / Diskspace usage / CPU Load etc.

But how to Define Influx DB Size in Openhab Items so i can use it for showing in Sitemap and also store as Historical Data to see rate of Increase in database size.

Please guide.

The system command:
sudo du -sh /var/lib/influxdb/data/openhab_db
Will return the size of the database in Megabytes:

example:

openhab@openhab:~$ sudo du -sh /var/lib/influxdb/data/openhab_db
25M	/var/lib/influxdb/data/openhab_db

So you could do in rules:

var String databaseQueryString = executeCommandLine("sudo du -sh /var/lib/influxdb/data/openhab_db")
var String databaseSizeString = databaseQueryString.split(" ").get(0).replace("M", "")
var Number databaseSize = Float::parseFloat(databaseSizeString) as Number

Thanks…

will try and update…

2018-07-28 22:44:04.115 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Influx DB Size Data Collection’: cannot invoke method public java.lang.String[] java.lang.String.split(java.lang.String) on null

I am getting error

my rules

rule "Influx DB Size Data Collection"
when
    Time cron "0 0/1 * * * ?"
then
	var String databaseQueryString = executeCommandLine("sudo du -sh /var/lib/influxdb/data/openhab_db")
	var String databaseSizeString = databaseQueryString.split(" ").get(0).replace("M", "")
	var Number databaseSize = Float::parseFloat(databaseSizeString) as Number
end

Did you try sudo du -sh /var/lib/influxdb/data/openhab_db on the command line?
Does it work?

Yes it works but ask for password on command line (putty). But i am afraid with openhab rules how it will provide password ?

Change the permission of the /var/lib/influxdb/data/openhab_db folder

In putty:
sudo chmod -R 755 /var/lib/influxdb/data/openhab_db

Then you should able to execute:
du -sh /var/lib/influxdb/data/openhab_db without sudo

Still getting below same error

2018-07-29 11:33:03.761 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Influx DB Size Data Collection': cannot invoke method public java.lang.String[] java.lang.String.split(java.lang.String) on null

That works for me:

rule "Influx DB Size Data Collection"
when
    Time cron "0 0/1 * * * ?"
then
    var String databaseQueryString = executeCommandLine("du -sh /var/lib/influxdb/data/openhab_db", 1000)
    logInfo("TEST1", databaseQueryString)
    var String databaseSizeString = databaseQueryString.split("\t").get(0)
    databaseSizeString = databaseSizeString.replace("M", "")
    logInfo("TEST1", databaseSizeString)
    var Number databaseSize = Float::parseFloat(databaseSizeString) as Number
    logInfo("TEST1", databaseSize.toString)
end

Returns in logs:

2018-07-29 09:19:00.562 [INFO ] [eclipse.smarthome.model.script.TEST1] - 25M	/var/lib/influxdb/data/openhab_db
2018-07-29 09:19:00.565 [INFO ] [eclipse.smarthome.model.script.TEST1] - 25
2018-07-29 09:19:00.569 [INFO ] [eclipse.smarthome.model.script.TEST1] - 25.0
1 Like

But I wouldn’t worry too much about the size of the db, after persisting hundreds of items for 7 months now, my database is only 25M in size

Thanks it worked… but how to apply that local variable to item Databasesize ? i doubt it should be global variable to copy variable value to item ?

Thanks…for help…

Databasesize.postUpdate(databaseSize)

Anything special needed ?

Rules File

Databasesize.postUpdate(databaseSize)

Item File

Number DatabaseSize   "DB Size [%.1f MB]"

Not getting any value. Just Blank.

You need to create a rule
Just that line in a rule file will not do anything

Correct…i had already put that in rule… like below

rule "Influx DB Size Data Collection"
when
    Time cron "0 0/1 * * * ?"
then
    var String databaseQueryString = executeCommandLine("du -sh /var/lib/influxdb/data/openhab_db", 1000)
    logInfo("TEST1", databaseQueryString)
    var String databaseSizeString = databaseQueryString.split("\t").get(0)
    databaseSizeString = databaseSizeString.replace("M", "")
    logInfo("TEST1", databaseSizeString)
    var Number databaseSize = Float::parseFloat(databaseSizeString) as Number
    logInfo("TEST1", databaseSize.toString)
    Databasesize.postUpdate(databaseSize)
end

Try:

Databasesize.postUpdate(databaseSize.toString)