Skip to content

Commit

Permalink
Merge pull request #50 from k1LoW/unixtime
Browse files Browse the repository at this point in the history
Support parse 'unixtime'
  • Loading branch information
k1LoW authored Oct 10, 2019
2 parents 3a3d6b3 + fc1c2a1 commit 88d8ef5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ targetSets:
description: app log
type: regexp
regexp: 'time:([^\t]+)'
timeFormat: 'Jan 02 15:04:05'
timeFormat: 'Jan 02 15:04:05' # Golang time format and 'unixtime'
timeZone: '+0900'
sources:
- 'ssh://app-1.example.com/var/log/ltsv.log*'
Expand Down
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func buildReadCommand(path string, st, et *time.Time, timeFormat, timeZone strin
findStart := st.Format("2006-01-02 15:04:05 MST")

cmd := fmt.Sprintf("sudo find %s/ -type f -name '%s' -newermt '%s' | xargs sudo ls -tr | xargs sudo zcat -f | grep -a '%s'", dir, base, findStart, string(matches))
if timeFormat == "unixtime" {
cmd = fmt.Sprintf("sudo find %s/ -type f -name '%s' -newermt '%s' | xargs sudo ls -tr | xargs sudo zcat -f", dir, base, findStart)
}

return cmd
}
Expand Down
7 changes: 6 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package parser
import (
"context"
"fmt"
"strconv"
"time"

"github.com/k1LoW/harvest/client"
Expand All @@ -27,8 +28,12 @@ type Parser interface {
Parse(ctx context.Context, cancel context.CancelFunc, lineChan <-chan client.Line, tz string, st *time.Time, et *time.Time) <-chan Log
}

// parseTime ...
func parseTime(tf string, tz string, content string) (*time.Time, error) {
if tf == "unixtime" {
ui, _ := strconv.ParseInt(content, 10, 64)
ut := time.Unix(ui, 0)
return &ut, nil
}
if tz == "" {
t, err := time.Parse(fmt.Sprintf("2006-01-02 %s", tf), fmt.Sprintf("%s %s", time.Now().Format("2006-01-02"), content))
return &t, err
Expand Down

0 comments on commit 88d8ef5

Please sign in to comment.