… I did some experiments on how to get the interactive grafana charts working locally and via myopenhab.org; after some experiments with nginx I found that there is an other approach that does not require nginx and is easier for my use case It is possible to redirect/rewrite requests based on path using a proxy servlet. A mechanism used by OH internally (jetty):
openhab> http:list
ID │ Servlet │ Servlet-Name │ State │ Alias │ Url
────┼───────────────────────────┼─────────────────────────┼─────────────┼─────────────────────┼────────────────────────
60 │ Whiteboard$1 │ cxf-servlet │ Deployed │ │ [/*]
78 │ ProxyServlet │ ServletModel-2 │ Deployed │ /grafana │ [/grafana/*]
152 │ AudioServlet │ ServletModel-6 │ Deployed │ /audio │ [/audio/*]
171 │ ChangePasswordPageServlet │ ServletModel-11 │ Deployed │ /changePassword │ [/changePassword/*]
171 │ CreateAPITokenPageServlet │ ServletModel-12 │ Deployed │ /createApiToken │ [/createApiToken/*]
171 │ AuthorizePageServlet │ ServletModel-9 │ Deployed │ /auth │ [/auth/*]
187 │ EventWebSocketServlet │ ServletModel-17 │ Deployed │ /ws │ [/ws/*]
215 │ ChartServlet │ ServletModel-20 │ Deployed │ /chart │ [/chart/*]
215 │ AsyncProxyServlet │ ServletModel-23 │ Deployed │ /proxy │ [/proxy/*]
216 │ IconServlet │ ServletModel-26 │ Deployed │ /icon │ [/icon/*]
218 │ UIServlet │ ServletModel-29 │ Deployed │ / │ [/]
263 │ AsyncServlet │ ServletModel-32 │ Deployed │ /upnpcallback │ [/upnpcallback/*]
286 │ ResourceServlet │ /connectspotify/img:web │ Deployed │ /connectspotify/img │ [/connectspotify/img/*]
286 │ SpotifyAuthServlet │ ServletModel-35 │ Deployed │ /connectspotify │ [/connectspotify/*]
303 │ RRD4jChartServlet │ ServletModel-39 │ Deployed │ /rrdchart.png │ [/rrdchart.png/*]
It is possible to register such a redirect manually in karaf with the following command:
openhab> http:proxy-add /grafana https://localhost:3000
Note: Grafana is runing on port 3000 on the same machine. It is configured to use https with a self signed certificate. The certificate was imported in the certificate store of the machine.
Some additional configuration in grafana is required - as jetty now acts as proxy for us:
[server]
# Protocol (http, https, h2, socket)
protocol = https
# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
root_url = http://localhost:8080/grafana
serve_from_sub_path = true
cert_file = /etc/grafana/grafana.crt
cert_key = /etc/grafana/grafana.key
You’ll need to prepend the uri generated by grafana for the chart with grafana
:
With this I’m able to load the graphs in the browser locally & from remote. In the android application the graphs work/load locally - but not yet from remote - browser works fine … I’ll have a look into this if I find the time :-).