Author: Paolo Lulli <paolo@lulli.net>
Timestamp on metric lines
client/main.go | 15 +++++++++++----
diff --git a/client/main.go b/client/main.go index 67bcaf7e96eb7fc6d041665c60cf0c72c4bcacf6..436186c55859746dc52407008aef752362cec370 100644 --- a/client/main.go +++ b/client/main.go @@ -150,9 +150,8 @@ err := json.Unmarshal(dataJson, &eventListModel) if err == nil { for _, event := range eventListModel { - unixTimeUTC := time.Unix(event.Etime/1000, 0) - unitTimeInRFC3339 := unixTimeUTC.Format(time.RFC3339) - fmt.Printf("%s %s\n", unitTimeInRFC3339, event.Name) + eventTime := formattedUtcTimeInSec(event.Etime) + fmt.Printf("%s %s\n", eventTime, event.Name) } } else { fmt.Println(err) @@ -240,7 +239,7 @@ } sort.Strings(keys) for _, k := range keys { - fmt.Printf("\"%v\"%s", k, recordSeparator) + fmt.Printf("\"%s\"%s", k, recordSeparator) } fmt.Printf("%s", rowSeparator) for _, row := range metricListModel { @@ -248,6 +247,9 @@ rowMap, errNoValue := loadBase64ValueAsMap(row) if errNoValue { return } + + metricTime := formattedUtcTimeInSec(metric.Mtime) + fmt.Printf("%s%s", metricTime, recordSeparator) for _, k := range keys { fmt.Printf("\"%v\"%s", rowMap[k], recordSeparator) } @@ -272,6 +274,11 @@ listResponse := yatsClient.PositionList(*sourceOption, fromTimestamp, toTimestamp) fmt.Printf("%s", listResponse) os.Exit(0) } +} + +func formattedUtcTimeInSec(int64Ts int64) string { + unixTimeUTC := time.Unix(int64Ts/1000, 0) + return unixTimeUTC.Format(time.RFC3339) } func loadBase64ValueAsMap(metric MetricModel) (map[string]any, bool) {