Stability | experimental |
---|---|
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Database.InfluxDB
Contents
Description
- write :: Timestamp time => WriteParams -> Line time -> IO ()
- writeBatch :: (Timestamp time, Foldable f) => WriteParams -> f (Line time) -> IO ()
- writeByteString :: WriteParams -> ByteString -> IO ()
- data WriteParams
- writeParams :: Database -> WriteParams
- retentionPolicy :: Lens' WriteParams (Maybe Key)
- data Line time = Line !Key !(Map Key Text) !(Map Key FieldValue) !(Maybe time)
- measurement :: Lens' (Line time) Key
- tagSet :: Lens' (Line time) (Map Key Text)
- fieldSet :: Lens' (Line time) (Map Key FieldValue)
- timestamp :: Lens' (Line time) (Maybe time)
- data FieldValue
- = FieldInt !Int64
- | FieldFloat !Double
- | FieldString !Text
- | FieldBool !Bool
- | FieldNull
- class Timestamp time where
- precisionScale :: Fractional a => Precision ty -> a
- precisionName :: Precision ty -> Text
- data Query
- query :: QueryResults a => QueryParams -> Query -> IO (Vector a)
- queryChunked :: QueryResults a => QueryParams -> Optional Int -> Query -> FoldM IO (Vector a) r -> IO r
- formatQuery :: Format Query r -> r
- (%) :: Format b c -> Format a b -> Format a c
- data QueryParams
- queryParams :: Database -> QueryParams
- authentication :: HasCredentials a => Lens' a (Maybe Credentials)
- class QueryResults a where
- parseResultsWith :: (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a) -> Value -> Parser (Vector a)
- getField :: Text -> Vector Text -> Array -> Parser Value
- getTag :: Monad m => Text -> HashMap Text Text -> m Text
- parseTimestamp :: Precision ty -> Value -> Parser POSIXTime
- parseFieldValue :: Value -> Parser FieldValue
- parseKey :: Key -> Vector Text -> Array -> Parser Key
- manage :: QueryParams -> Query -> IO ()
- data Precision ty where
- Nanosecond :: Precision ty
- Microsecond :: Precision ty
- Millisecond :: Precision ty
- Second :: Precision ty
- Minute :: Precision ty
- Hour :: Precision ty
- RFC3339 :: Precision QueryRequest
- data Database
- data Key
- data Server
- host :: Lens' Server Text
- port :: Lens' Server Int
- ssl :: Lens' Server Bool
- localServer :: Server
- data Credentials
- user :: Lens' Credentials Text
- password :: Lens' Credentials Text
- data InfluxException
- class HasServer a where
- class HasDatabase a where
- class HasPrecision ty a | a -> ty where
- class HasManager a where
Writing data
InfluxDB has two ways to write data into it, via HTTP and UDP. This module only exports functions for the HTTP API. For UDP, you can use a qualified import:
import qualified Database.InfluxDB.Write.UDP as UDP
writeBatch :: (Timestamp time, Foldable f) => WriteParams -> f (Line time) -> IO () Source #
writeByteString :: WriteParams -> ByteString -> IO () Source #
Write a raw ByteString
Write parameters
data WriteParams Source #
The full set of parameters for the HTTP writer.
Instances
HasCredentials WriteParams Source # | |
HasManager WriteParams Source # |
|
HasDatabase WriteParams Source # |
|
HasServer WriteParams Source # |
|
HasPrecision WriteRequest WriteParams Source # |
|
writeParams :: Database -> WriteParams Source #
Smart constructor for WriteParams
Default parameters:
retentionPolicy :: Lens' WriteParams (Maybe Key) Source #
Target retention policy for the write.
InfluxDB writes to the default
retention policy if this parameter is set
to Nothing
.
>>>
let p = writeParams "foo"
>>>
let p' = p & retentionPolicy .~ Just "two_hours"
>>>
p' ^. retentionPolicy
Just "two_hours"
The Line protocol
Placeholder for the Line Protocol
See https://docs.influxdata.com/influxdb/v1.0/write_protocols/line_protocol_tutorial/ for the concrete syntax.
measurement :: Lens' (Line time) Key Source #
Name of the measurement that you want to write your data to.
tagSet :: Lens' (Line time) (Map Key Text) Source #
Tag(s) that you want to include with your data point. Tags are optional in
the Line Protocol, so you can set it empty
.
fieldSet :: Lens' (Line time) (Map Key FieldValue) Source #
Field(s) for your data point. Every data point requires at least one field
in the Line Protocol, so it shouldn't be empty
.
timestamp :: Lens' (Line time) (Maybe time) Source #
Timestamp for your data point. You can put whatever type of timestamp that
is an instance of the Timestamp
class.
data FieldValue Source #
Constructors
FieldInt !Int64 | |
FieldFloat !Double | |
FieldString !Text | |
FieldBool !Bool | |
FieldNull |
Instances
class Timestamp time where Source #
A Timestamp
is something that can be converted to a valid
InfluxDB timestamp, which is represented as a 64-bit integer.
precisionScale :: Fractional a => Precision ty -> a Source #
precisionName :: Precision ty -> Text Source #
Querying data
query :: QueryResults a => QueryParams -> Query -> IO (Vector a) Source #
Query data from InfluxDB.
It may throw InfluxException
.
Arguments
:: QueryResults a | |
=> QueryParams | |
-> Optional Int | Chunk size By |
-> Query | |
-> FoldM IO (Vector a) r | |
-> IO r |
Same as query
but it instructs InfluxDB to stream chunked responses
rather than returning a huge JSON object. This can be lot more efficient than
query
if the result is huge.
It may throw InfluxException
.
Query constructor
formatQuery :: Format Query r -> r Source #
Query parameters
data QueryParams Source #
The full set of parameters for the query API
Instances
HasCredentials QueryParams Source # | |
HasManager QueryParams Source # |
|
HasDatabase QueryParams Source # |
|
HasServer QueryParams Source # |
|
HasPrecision QueryRequest QueryParams Source # | Returning JSON responses contain timestamps in the specified precision/format.
|
queryParams :: Database -> QueryParams Source #
Smart constructor for QueryParams
Default parameters:
authentication :: HasCredentials a => Lens' a (Maybe Credentials) Source #
Parsing results
class QueryResults a where Source #
Minimal complete definition
Methods
parseResults :: Precision QueryRequest -> Value -> Parser (Vector a) Source #
Instances
QueryResults Void Source # | |
QueryResults ShowSeries Source # | |
QueryResults ShowQuery Source # | |
((~) * a Value, (~) * b Value) => QueryResults (a, b) Source # | |
((~) * a Value, (~) * b Value, (~) * c Value) => QueryResults (a, b, c) Source # | |
((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value) => QueryResults (a, b, c, d) Source # | |
((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value) => QueryResults (a, b, c, d, e) Source # | |
((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value, (~) * f Value) => QueryResults (a, b, c, d, e, f) Source # | |
((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value, (~) * f Value, (~) * g Value) => QueryResults (a, b, c, d, e, f, g) Source # | |
((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value, (~) * f Value, (~) * g Value, (~) * h Value) => QueryResults (a, b, c, d, e, f, g, h) Source # | |
Arguments
:: (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a) | A parser that takes
to construct a value. |
-> Value | |
-> Parser (Vector a) |
Parse a JSON response
Get a field value from a column name
Get a tag value from a tag name
parseTimestamp :: Precision ty -> Value -> Parser POSIXTime Source #
Parse either a POSIX timestamp or RFC3339 formatted timestamp.
parseFieldValue :: Value -> Parser FieldValue Source #
Database management
Common data types and classes
data Precision ty where Source #
Predefined set of time precision.
RFC3339
is only available for QueryRequest
s.
Constructors
Nanosecond :: Precision ty | POSIX time in ns |
Microsecond :: Precision ty | POSIX time in μs |
Millisecond :: Precision ty | POSIX time in ms |
Second :: Precision ty | POSIX time in s |
Minute :: Precision ty | POSIX time in minutes |
Hour :: Precision ty | POSIX time in hours |
RFC3339 :: Precision QueryRequest | Nanosecond precision time in a human readable format, like
|
Database name
String type that is used for measurements, tag keys and field keys.
localServer :: Server Source #
data Credentials Source #
User credentials
Exception
data InfluxException Source #
Exceptions used in this library.
In general, the library tries to convert exceptions from the dependent libraries to the following types of errors.
Constructors
ServerError String | Server side error. You can expect to get a successful response once the issue is resolved on the server side. |
BadRequest String Request | Client side error. You need to fix your query to get a successful response. |
IllformedJSON String ByteString | Unexpected JSON response. This can happen e.g. when the response from InfluxDB is incompatible with what this library expects due to an upstream format change etc. |
Instances
class HasServer a where Source #
Minimal complete definition
Instances
HasServer PingParams Source # | |
HasServer WriteParams Source # |
|
HasServer QueryParams Source # |
|
class HasDatabase a where Source #
Minimal complete definition
Instances
HasDatabase WriteParams Source # |
|
HasDatabase QueryParams Source # |
|
HasDatabase ShowQuery Source # |
|
class HasPrecision ty a | a -> ty where Source #
Minimal complete definition
Instances
HasPrecision QueryRequest QueryParams Source # | Returning JSON responses contain timestamps in the specified precision/format.
|
HasPrecision WriteRequest WriteParams Source # | Timestamp precision. In the UDP API, all timestamps are sent in nanosecond but you can specify lower precision. The writer just rounds timestamps to the specified precision. |
HasPrecision WriteRequest WriteParams Source # |
|
class HasManager a where Source #
Minimal complete definition
Methods
manager :: Lens' a (Either ManagerSettings Manager) Source #
HTTP manager settings or a manager itself.
If it's set to ManagerSettings
, the library will create a Manager
from
the settings for you.
Instances
HasManager PingParams Source # | |
HasManager WriteParams Source # |
|
HasManager QueryParams Source # |
|