Client
-
A InfluxDB Client providing a support for APIs to write and query data.
Example:
See morelet options: InfluxDBClient.InfluxDBOptions = InfluxDBClient.InfluxDBOptions( bucket: "my-bucket", org: "my-org", precision: .ns) let client = InfluxDBClient(url: "http://localhost:8086", token: "my-token", options: options) ... client.close()
Declaration
Swift
public class InfluxDBClient
-
The asynchronous API to Write time-series data into InfluxDB 2.x.
Example:
See more// // Record defined as String // let recordString = "demo,type=string value=1i" try await client.makeWriteAPI().write(record: recordString) // For Success write print("Successfully written data:\n\n\(recordString)") // // Record defined as Data Point // let recordPoint = InfluxDBClient .Point("demo") .addTag(key: "type", value: "point") .addField(key: "value", value: .int(2)) // // Record defined as Data Point with Timestamp // let recordPointDate = InfluxDBClient .Point("demo") .addTag(key: "type", value: "point-timestamp") .addField(key: "value", value: .int(2)) .time(time: .date(Date())) try await client.makeWriteAPI().write(points: [recordPoint, recordPointDate]) // For Success write print("Successfully written data:\n\n\([recordPoint, recordPointDate])") // // Record defined as Tuple // let recordTuple: InfluxDBClient.Point.Tuple = (measurement: "demo", tags: ["type": "tuple"], fields: ["value": .int(3)], time: nil) try await client.makeWriteAPI().write(tuple: recordTuple) // For Success write print("Successfully written data:\n\n\(recordTuple)")
Declaration
Swift
public class WriteAPI
-
The asynchronous API to Query InfluxDB 2.x.
Example:
Query into sequence of
FluxRecord
let query = """ from(bucket: "my-bucket") |> range(start: -10m) |> filter(fn: (r) => r["_measurement"] == "cpu") |> filter(fn: (r) => r["cpu"] == "cpu-total") |> filter(fn: (r) => r["_field"] == "usage_user" or r["_field"] == "usage_system") |> last() """ print("\nQuery to execute:\n\(query)\n") let records = try await client.queryAPI.query(query: query) print("Query results:") try records.forEach { print(" > \($0.values["_field"]!): \($0.values["_value"]!)") }
Query into
Data
See morelet response = try await client.queryAPI.queryRaw(query: query) let csv = String(decoding: response, as: UTF8.self) print("InfluxDB response: \(csv)") client.close()
Declaration
Swift
public class QueryAPI
-
Delete time series data from InfluxDB 2.x.
Example:
See morelet predicateRequest = DeletePredicateRequest( start: Date(timeIntervalSince1970: 0), stop: Date(), predicate: "_measurement=\"server\" AND production=\"no\"") try await client.deleteAPI.delete(predicate: predicateRequest, bucket: "my-bucket", org: "my-org") print("Successfully data data by:\n\n\(predicateRequest)")
Declaration
Swift
public class DeleteAPI
-
Query influx using the Flux language
See moreDeclaration
Swift
public struct Query : Codable
-
Dialect are options to change the default CSV output format; https://www.w3.org/TR/2015/REC-tabular-metadata-20151217/#dialect-descriptions
See moreDeclaration
Swift
public struct Dialect : Codable
-
The delete predicate request.
See moreDeclaration
Swift
public struct DeletePredicateRequest : Codable