package tezt-tezos

  1. Overview
  2. Docs
On This Page
  1. InfluxQL

Send and retrieve data points from InfluxDB.

type credentials = {
  1. username : string;
  2. password : string;
}

Credentials used to authenticate to the database.

type config =
  1. | V1_8 of {
    1. url : Uri.t;
    2. database : string;
    3. credentials : credentials option;
    4. measurement_prefix : string;
    5. tags : (string * string) list;
    6. timeout : float;
    }

InfluxDB configuration.

url is the base URL of the InfluxDB API.

database is the name of the InfluxDB database to read from and write to.

credentials are used to authenticate to this database. If not provided, it will try to connect without authenticating (insecure mode).

measurement_prefix is prepended to all measurement names when sending data points and in SELECT queries.

tags is added to the tags of all data points when sending data points.

val config_of_json : Tezt_wrapper.JSON.t -> config

Read an InfluxDB configuration from a JSON value.

type measurement = string

Measurement names for data points.

type tag = string

Tag names for data points.

type field = string

Field names for data points.

type field_value =
  1. | Float of float
  2. | String of string

Field values for data points.

type timestamp = float

Unix timestamps as returned by Unix.gettimeofday.

type data_point = private {
  1. measurement : measurement;
  2. tags : (tag * string) list;
  3. first_field : field * field_value;
  4. other_fields : (field * field_value) list;
  5. timestamp : timestamp;
}

Data points (see function data_point).

val data_point : ?tags:(tag * string) list -> ?other_fields:(field * field_value) list -> ?timestamp:timestamp -> measurement -> (field * field_value) -> data_point

Create a data point.

Usage: data_point measurement key_value

Data points are composed of:

  • a name measurement;
  • a possibly-empty list of tags to complete the name;
  • a non-empty list of (key, value) fields, composed of key_value and other_fields;
  • a UNIX timestamp (default value is now). See the documentation of InfluxDB for more information about those components.
  • raises Invalid_arg

    if one of the tags, tag values, fields, field values, or measurement contains a newline character.

val add_tag : tag -> string -> data_point -> data_point

Add a tag to a data point.

  • raises Invalid_arg

    if the tag or the value contains a newline character.

val show_data_point : data_point -> string

Convert a data point to a string for display purposes.

val write : config -> data_point list -> unit Lwt.t

Push data points to InfluxDB.

Return Error message if the data could not be sent, where message is a human-readable error message.

InfluxQL

This section provides a select type that is an AST of InfluxQL SELECT queries, and a function to perform those queries.

See the documentation of InfluxQL here: https://docs.influxdata.com/influxdb/v1.8/query_language/explore-data

type time_interval =
  1. | Ns of int
    (*

    nanoseconds

    *)
  2. | U of int
    (*

    microseconds

    *)
  3. | Ms of int
    (*

    milliseconds

    *)
  4. | S of int
    (*

    seconds

    *)
  5. | M of int
    (*

    minutes

    *)
  6. | H of int
    (*

    hours

    *)
  7. | D of int
    (*

    days

    *)
  8. | W of int
    (*

    weeks

    *)
  9. | Grafana_interval

Time interval specifications for InfluxQL queries.

Grafana_interval denotes $__interval, a placeholder that Grafana replaces with an interval which is proportional to the selected time window size. Use this in a GROUP BY clause. Example: ~group_by: (Time {interval = Grafana_interval; tag = None; fill = Some Previous}). If you try to actually query a select with this, query raises Invalid_arg.

type func =
  1. | COUNT
  2. | DISTINCT
  3. | INTEGRAL of time_interval
  4. | MEAN
  5. | MEDIAN
  6. | MODE
  7. | SPREAD
  8. | STDDEV
  9. | SUM

Functions for InfluxQL SELECT queries.

val column_name_of_func : func -> string

Get the name of the column for a given function in query results.

type argument =
  1. | All
  2. | Field of string

Arguments of functions for InfluxQL SELECT queries.

type column =
  1. | All
  2. | Field of string
  3. | Tag of string
  4. | Function of func * argument

Columns to retrieve using InfluxQL SELECT queries.

type tag_operator =
  1. | EQ
  2. | NE

Operators for tag comparisons in WHERE clauses.

type field_operator =
  1. | EQ
  2. | NE
  3. | GT
  4. | GE
  5. | LT
  6. | LE

Operators for field comparisons in WHERE clauses.

type where =
  1. | Tag of string * tag_operator * string
  2. | Field of string * field_operator * field_value
  3. | Or of where * where
  4. | And of where * where
  5. | Grafana_time_filter

WHERE clauses of InfluxQL SELECT queries.

Grafana_time_filter denotes $timeFilter, a placeholder that Grafana replaces with a predicate on time which denotes the time window that the user selected in Grafana. If you try to actually query a select with this, query raises Invalid_arg.

type fill =
  1. | Value of float
  2. | Linear
  3. | F_none
  4. | Null
  5. | Previous

Fill argument of GROUP BY time clauses.

type group_by =
  1. | All_tags
  2. | Tags of tag list
  3. | Time of {
    1. interval : time_interval;
    2. tag : tag option;
    3. fill : fill option;
    }

GROUP BY clauses of InfluxQL SELECT queries.

type order_by =
  1. | Time_desc

ORDER BY clauses of InfluxQL SELECT queries.

type select = {
  1. columns : column list;
  2. from : from;
  3. where : where option;
  4. group_by : group_by option;
  5. order_by : order_by option;
  6. limit : int option;
  7. slimit : int option;
}

InfluxQL SELECT queries.

and from =
  1. | Measurement of string
  2. | Select of select

FROM clauses of InfluxQL SELECT queries.

val select : from:from -> ?where:where -> ?group_by:group_by -> ?order_by:order_by -> ?limit:int -> ?slimit:int -> column list -> select

Make an InfluxQL SELECT query.

val show_select : ?grafana:bool -> select -> string

Convert a SELECT query to a string for display purposes.

If grafana is true, allow Grafana_time_filter and Grafana_interval. Default is false.

  • raises Invalid_arg

    if grafana is false and the query contains Grafana_time_filter or Grafana_interval.

val prefix_measurement : config -> select -> select

Prepend the measurement of the innermost SELECT query with the configured prefix.

This is automatically done by query.

type result_data_point

Data points returned when making a SELECT query.

val show_result_data_point : result_data_point -> string

Convert a data point returned by a SELECT query to a human-readable string.

val query : config -> select -> result_data_point list list Lwt.t

Perform a SELECT query.

  • raises Invalid_arg

    if the query contains Grafana_time_filter or Grafana_interval.

val get : string -> (Tezt_wrapper.JSON.t -> 'a) -> result_data_point -> 'a

Get a value from a data point in a query result.

Example: get "count" JSON.as_int

val show_query_result : result_data_point list list -> string

Convert results from a SELECT query into a string for debugging purposes.

OCaml

Innovation. Community. Security.