refactoring based on pr review
parent
d653e41712
commit
c0404e577e
|
@ -3,6 +3,7 @@ package graphite
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -87,21 +88,13 @@ func (p *Parser) Parse(line string) (influxdb.Point, error) {
|
|||
fieldValues[name] = v
|
||||
|
||||
// Parse timestamp.
|
||||
//unixTime, err := strconv.ParseInt(fields[2], 10, 64)
|
||||
unixTime, err := strconv.ParseFloat(fields[2], 64)
|
||||
if err != nil {
|
||||
return influxdb.Point{}, err
|
||||
}
|
||||
|
||||
var timestamp time.Time
|
||||
// Check if we have fractional seconds
|
||||
if float64(int64(unixTime)) != unixTime {
|
||||
nanoseconds := int64((unixTime - float64(int64(unixTime))) * float64(time.Second))
|
||||
seconds := int64(unixTime)
|
||||
timestamp = time.Unix(seconds, nanoseconds)
|
||||
} else {
|
||||
timestamp = time.Unix(int64(unixTime), 0)
|
||||
}
|
||||
timestamp := time.Unix(int64(unixTime), int64((unixTime-math.Floor(unixTime))*float64(time.Second)))
|
||||
|
||||
point := influxdb.Point{
|
||||
Name: name,
|
||||
|
|
Loading…
Reference in New Issue