InfluxDB+Grafana persistence and graphing

As far as I can tell, that query looks OK. However the “default” written in bold makes me wonder. I guess that this problem is above my knowledge. Maybe @theo can help.

Did some testing using my setup (InfluxDB with a user-named retention policy).
I used this rule:

rule “NewTest”
when
Item TestSomething changed
then
val StartOfDay =now.withTimeAtStartOfDay
val StoredValue =MyItem.minimumSince(StartOfDay,“influxdb”)
logInfo(“NewTest”,“StoredValue= {}”, StoredValue.state)
end

I’m not getting and error, only this this log-entry:

18:01:46.908 [INFO ] [lipse.smarthome.model.script.NewTest] - StoredValue= 1.209

I didn’t check the debug-output of the influxdb-binding (because I don’t know the exact name of the package :blush:)

I couldn’t get it to log right either. I just put all of OH into trace mode and grepped the logs.

When I have some time I might try making a new retention policy, though I hate to lose all that historical data.

I would also hate to lose my data. @ThomDietrich posted in reply #84 in this thread a method to copy data from one database or retention policy to another.

1 Like

I should move that information to the first article…

@rlkoshak could you please execute this query using the influx client:
select value from default.Weather_Temperature where time > 1479193200s limit 2147483647

I’m not sure at all. Could you please open an issue for this feature request.

Interesting…

I ran the query through the REST API (apparently the Web UI is deprecated and broken) and I’m getting the exact same error.

curl -GET 'http://openhab:password@localhost:8086/query?db=openhab_db' --data-urlencode 'q=select value from default.Weather_Temperature where time > 1479193200s limit 2147483647'
{"error":"error parsing query: found DEFAULT, expected identifier at line 1, char 19"}

If I modify the query to remove the “default.” I get expected results (assuming I’m reading the meaning of the original query correctly, I’m not certain I know what the limit does).

curl -GET 'http://openhab:password@localhost:8086/query?db=openhab_db' --data-urlencode 'q=select value from default.Weather_Temperature where time > 1479193200s limit 2147483647'

Could test this query (limit removed from the query to default.Weather_Temperature):

curl -GET 'http://openhab:password@localhost:8086/query?db=openhab_db' --data-urlencode 'q=select value from default.Weather_Temperature where time > 1479193200s'
curl -GET 'http://openhab:Hes10d27@localhost:8086/query?db=openhab_db' --data-urlencode 'q=select value from default.Weather_Temperature where time > 1479193200s'
{"error":"error parsing query: found DEFAULT, expected identifier at line 1, char 19"}

And again, if I remove the “.default” I get results.

Just a wild guess: there is no retention policy “default” for “Weather_Temperature”. Can you do a:

SHOW RETENTION POLICIES ON Weather_Temperature

Hmmm. When I run the query like that I get

{"results":[{"error":"database not found: Weather_Temperature"}]}

When I run it using openhab_db instead of Weather_Temperature I get

curl -GET 'http://openhab:Hes10d27@localhost:8086/query?db=openhab_db&pretty=true' --data-urlencode 'q=SHOW RETENTION POLICIES ON openhab_db'
{
    "results": [
        {
            "series": [
                {
                    "columns": [
                        "name",
                        "duration",
                        "shardGroupDuration",
                        "replicaN",
                        "default"
                    ],
                    "values": [
                        [
                            "default",
                            "0s",
                            "168h0m0s",
                            1,
                            true
                        ]
                    ]
                }
            ]
        }
    ]
}

Based on the InfluxDB docs, the ON clause only appears to work on a DB, not a field. But based on the previous queries I know for sure that Weather_Temperature is in openhab_db and my reading of the Retention Policy docs is that one can only apply a policy to an entire DB, not individual fields.

In Grafana, in order to chart this value the query is:

which collapses to:

I got the same problem with my setup. I need to use RetentionPolicie=default in my influxDB v1.0 setup. without i get all sorts of errors. But i can’t get measurements out the DB with the REST api (error parsing query: found DEFAULT, expected identifier at line 1, char 19) Do you already know how to fix the problem?

Same here! :wink:

Not yet. I’ve temporarily worked around it for now by keeping track of the info I need in vars and vals. Charting and saving the data works fine.

I’m pretty much using rrd4j everywhere else for this sort of thing.

I suspect that if you created a non-default retention policy it will work. See @opus’s posts above for details on how to do that and @ThomDietrich posted how to move your data from your current one to the new one so you won’t lose anything. I’ve just not got around to it yet.

Since the queries build by the openHAB REST API do reflect the retention-policy now, I’m questioning the reason for using a DEFAULT retention policy. You need to set the correct name anyway! But I’m still a newbie on this topic.

Because that is what the default RP was called when I initially set up InfluxDB. For those who followed this tutorial when it was first posted, we are stuck saving all our stuff to “default”. It will require a significant amount of work to create and migrate everything to new RP and update Grafana to pull from the correct RP.

2 Likes

If you change default to “default” it works

curl -GET 'http://openhab:password@localhost:8086/query?db=openhab_db' --data-urlencode 'q=select value from "default".Weather_Temperature where time > 1479193200s'

im guessing the name default RP in influx is handled specially to require “” since its name and has nothing to do which is default RP in influx.

1 Like

Unfortunately changing it to "default" in influxdb.cfg does not work. I get the following error for each commit.

2016-11-28 12:08:00.048 [ERROR] [org.influxdb.impl.BatchProcessor    ] - Batch could not be sent. Data will be lost
java.lang.RuntimeException: {"error":"retention policy not found: \"default\""}
1 Like

@techmike there was already a similar issue I added the idea to. [influxdb] Feature request: option to replace _ with . in item names for influxdb · Issue #4830 · openhab/openhab1-addons · GitHub