mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-26 15:29:04 +01:00
Allow selection of timestamp precision in HttpSink
This commit is contained in:
parent
a37f6603c8
commit
226e8425cb
@ -45,6 +45,9 @@ type HttpSinkConfig struct {
|
|||||||
|
|
||||||
// Maximum number of retries to connect to the http server (default: 3)
|
// Maximum number of retries to connect to the http server (default: 3)
|
||||||
MaxRetries int `json:"max_retries,omitempty"`
|
MaxRetries int `json:"max_retries,omitempty"`
|
||||||
|
|
||||||
|
// Timestamp precision
|
||||||
|
Precision string `json:"precision,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type key_value_pair struct {
|
type key_value_pair struct {
|
||||||
@ -141,7 +144,7 @@ func (s *HttpSink) Write(m lp.CCMetric) error {
|
|||||||
|
|
||||||
// Check that encoding worked
|
// Check that encoding worked
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Encoding failed: %v", err)
|
return fmt.Errorf("encoding failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.config.flushDelay == 0 {
|
if s.config.flushDelay == 0 {
|
||||||
@ -268,6 +271,7 @@ func NewHttpSink(name string, config json.RawMessage) (Sink, error) {
|
|||||||
s.config.Timeout = "5s"
|
s.config.Timeout = "5s"
|
||||||
s.config.FlushDelay = "5s"
|
s.config.FlushDelay = "5s"
|
||||||
s.config.MaxRetries = 3
|
s.config.MaxRetries = 3
|
||||||
|
s.config.Precision = "ns"
|
||||||
cclog.ComponentDebug(s.name, "Init()")
|
cclog.ComponentDebug(s.name, "Init()")
|
||||||
|
|
||||||
// Read config
|
// Read config
|
||||||
@ -315,6 +319,19 @@ func NewHttpSink(name string, config json.RawMessage) (Sink, error) {
|
|||||||
cclog.ComponentDebug(s.name, "Init(): flushDelay", t)
|
cclog.ComponentDebug(s.name, "Init(): flushDelay", t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
precision := influx.Nanosecond
|
||||||
|
if len(s.config.Precision) > 0 {
|
||||||
|
switch s.config.Precision {
|
||||||
|
case "s":
|
||||||
|
precision = influx.Second
|
||||||
|
case "ms":
|
||||||
|
precision = influx.Millisecond
|
||||||
|
case "us":
|
||||||
|
precision = influx.Microsecond
|
||||||
|
case "ns":
|
||||||
|
precision = influx.Nanosecond
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create http client
|
// Create http client
|
||||||
s.client = &http.Client{
|
s.client = &http.Client{
|
||||||
@ -326,7 +343,7 @@ func NewHttpSink(name string, config json.RawMessage) (Sink, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configure influx line protocol encoder
|
// Configure influx line protocol encoder
|
||||||
s.encoder.SetPrecision(influx.Nanosecond)
|
s.encoder.SetPrecision(precision)
|
||||||
s.extended_tag_list = make([]key_value_pair, 0)
|
s.extended_tag_list = make([]key_value_pair, 0)
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
|
@ -18,7 +18,8 @@ The `http` sink uses POST requests to a HTTP server to submit the metrics in the
|
|||||||
"timeout": "5s",
|
"timeout": "5s",
|
||||||
"idle_connection_timeout" : "5s",
|
"idle_connection_timeout" : "5s",
|
||||||
"flush_delay": "2s",
|
"flush_delay": "2s",
|
||||||
"batch_size": 1000
|
"batch_size": 1000,
|
||||||
|
"precision": "s"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -34,3 +35,4 @@ The `http` sink uses POST requests to a HTTP server to submit the metrics in the
|
|||||||
- `idle_connection_timeout`: Timeout for idle connections (default '120s'). Should be larger than the measurement interval to keep the connection open
|
- `idle_connection_timeout`: Timeout for idle connections (default '120s'). Should be larger than the measurement interval to keep the connection open
|
||||||
- `flush_delay`: Batch all writes arriving in during this duration (default '1s', batching can be disabled by setting it to 0)
|
- `flush_delay`: Batch all writes arriving in during this duration (default '1s', batching can be disabled by setting it to 0)
|
||||||
- `batch_size`: Maximal batch size. If `batch_size` is reached before the end of `flush_delay`, the metrics are sent without further delay
|
- `batch_size`: Maximal batch size. If `batch_size` is reached before the end of `flush_delay`, the metrics are sent without further delay
|
||||||
|
- `precision`: Precision of the timestamp. Valid values are 's', 'ms', 'us' and 'ns'. (default is 'ns')
|
Loading…
Reference in New Issue
Block a user