Giter VIP home page Giter VIP logo

ocaml-influxdb's Introduction

ocaml-influxdb

OCaml interface to the time series database InfluxDB.

Not production ready!. The library must be more tested.

Examples.

All requests are done with the module Influxdb.Client.

(* Create a client for the database "foo" for an InfluxDB client running on port
   8087 (no HTTP request is done, it's only a record.
*)
let client = Influxdb.Client.create ~port:8087 ~database:"foo" () in
(* Create the database foo on the InfluxDB instance. *)
Influxdb.Client.create_database client "foo" >>=
(* Create a retention policy for 4 weeks *)
Influxdb.Client.create_retention_policy ~name:"1month" ~duration:"4w" client >>=
(* Create some points for the measurement cpu_load_short and write them *)
let measurement = Influxdb.Measurement.t_of_string "cpu_load_short" in
let fields = [Influxdb.Field.t_of_key_and_value "value" (Influxdb.Field.value_of_float 0.64)] in
let tags = [Influxdb.Tag.t_of_key_and_value "host" "server02";
            Influxdb.Tag.t_of_key_and_value "region" "us-west"] in
let time = Influxdb.Datetime.to_t ~year:2017 ~month:1 ~day:13 
    ~hour:12 ~minute:5 ~second:20 ~nanosecond:15678 in
let p = [Influxdb.Point.to_t measurement fields tags time] in
let time = Influxdb.Datetime.to_t ~year:2016 ~month:1 ~day:13
    ~hour:12 ~minute:5 ~second:20 ~nanosecond:15678 in
let p = Influxdb.Point.to_t measurement fields tags time :: p in
let time = Influxdb.Datetime.to_t ~year:2016 ~month:2 ~day:13
    ~hour:12 ~minute:5 ~second:20 ~nanosecond:15678 in
let p = Influxdb.Point.to_t measurement fields tags time :: p in
let time = Influxdb.Datetime.to_t ~year:2017 ~month:2 ~day:12 
    ~hour:12 ~minute:5 ~second:20 ~nanosecond:15678 in
let p = Influxdb.Point.to_t measurement fields tags time :: p in
let time = Influxdb.Datetime.to_t ~year:2016 ~month:2 ~day:12 
    ~hour:12 ~minute:52 ~second:20 ~nanosecond:15678 in
let p = Influxdb.Point.to_t measurement fields tags time :: p in
Influxdb.Client.write_points client p >>= fun _ ->
(* Get points with WHERE expression. Remove the parameter ~where for all points. *)
let from_time = Influxdb.Datetime.to_t ~year:2016 ~month:2 ~day:13 ~hour:12 ~minute:5 ~second:20 ~nanosecond:15678 in
let until_time = Influxdb.Datetime.to_t ~year:2017 ~month:2 ~day:13 ~hour:12 ~minute:5 ~second:20 ~nanosecond:15678 in
let open Influxdb.Where in
let where = [Time(GreaterOrEqual, from_time); Time(LessOrEqual, until_time)] in
let measurement = Influxdb.Measurement.t_of_string "cpu_load_short" in
Influxdb.Client.get_points client ~where measurement >>= fun points ->
Printf.printf "-- Number of points: %d\n" (List.length points);
List.iter print_endline (List.map Influxdb.Point.line_of_t points); Lwt.return ()

ocaml-influxdb's People

Contributors

dannywillems avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vbmithr

ocaml-influxdb's Issues

Improve codes with caches.

For example, we can keep tags and fields in memory when calling multiple times the get_points function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.