Client for influxdb
Start application
application:ensure_all_started(influxdb).Client Options: Write protocol http or udp
%% http
Option = [ {host, "127.0.0.1"}
, {port, 8086}
, {protocol, http}
, {https_enabled, false}
, {pool, influxdb_client_pool}
, {pool_size, 8}
, {pool_type, random}
, {version, v1},
, {path, undefined}
, {username, <<"uname">>}
, {password, <<"pwd">>}
, {database, <<"mydb">>}
, {precision, <<"ms">>}].- The client supports the
v1andv2API versions of InfluxDB. Usingv1by default, the version automatically chooses the write endpoint path(forv1, it's/write). - The optional
pathoption specifies the write endpoint path manually. The other TSDB supporting the InfluxDB writing protocol may have different write endpoint paths. You can configure it with this option. - For
v1, whenusernameand/orpasswordare provided, the client uses theAuthorization: Basic ...header by default rather than putting them in the URL query string. This also applies toping_with_auth. - If a
v1database requires URL credentials instead, set{v1_auth_transport, query_string}to opt in to sendingusernameandpasswordasuandpquery parameters. The default is{v1_auth_transport, header}. - Security note: sending credentials in the URL query string is less safe than using the
Authorizationheader because URLs may be captured by access logs, proxies, caches, and error reporting systems. Prefer{v1_auth_transport, header}whenever possible, and enable TLS ({https_enabled, true}) when credentials are sent over the network.
%% udp
Option = [ {host, "127.0.0.1"}
, {port, 8089}
, {protocol, udp}
, {pool, influxdb_client_pool}
, {pool_size, 8}
, {pool_type, random}].Start client
{ok, Client} = influxdb:start_client(Option).Make sure client alive
true = influxdb:is_alive(Client).Test data
Points = [#{<<"fields">> => #{<<"temperature">> => 1},
<<"measurement">> => <<"sample">>,
<<"tags">> =>
#{<<"from">> => <<"mqttx_4b963a8e">>,<<"host">> => <<"serverA">>,
<<"qos">> => 0,<<"region">> => <<"hangzhou">>},
<<"timestamp">> => 1619775142098},
#{<<"fields">> => #{<<"temperature">> => 2},
<<"measurement">> => <<"sample">>,
<<"tags">> =>
#{<<"from">> => <<"mqttx_4b963a8e">>,<<"host">> => <<"serverB">>,
<<"qos">> => 0,<<"region">> => <<"ningbo">>},
<<"timestamp">> => 1619775142098}].Write to influxdb
influxdb:write(Client, Points).If your pool_type is hash
Key = any_key_you_need.
influxdb:write(Client, Key, Points).Stop Client
influxdb:stop_client(Client).