Search code examples
jqueryajaxinfluxdb

Retrieve data from InfluxDB with javascript (client-side, using a browser)


I want to build a static html page which retrieves data from influxDB. Is there any jquery/ajax solution or even a js library to do this? I've tried to use influent, an InfluxDB driver for Javascript apps which says it can work in browser but I had no success when I tried to use influent.js


Solution

  • I captured with the developer tools the http requests that Grafana sends in order to create graphs and tried to do the same with jQuery get():

    // something like this
    $.get("http://localhost:8086/query?db=mydb&epoch=ms&q=SELECT+mean(value)+FROM+%22cpu_load_short%22+WHERE+time+%3E+1443610329s+and+time+%3C+1443629449s+GROUP+BY+time(30s)").done(
       function (data) { console.log(data);
    });
    

    InfluxDB returns JSON which I later handle and create a graph. See influxDB - Querying data