llogtail

package module
v0.0.0-...-580cabe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 22 Imported by: 0

README

llogtail

A lightweight log collector based on inotify

Documentation

Index

Constants

View Source
const (
	MaxBufferSize = 4 * MB
	MB            = 1024 * 1024
	KB            = 1024
)
View Source
const (
	LogFileRenameRotate = LogFileEvent(1) << iota // rename rotate: rename old log into a archived one, and then create a new file serving log
	LogFileModify
	LogFileChomd
	LogFileRemove
	LogFileDiscover        = LogFileEvent(1) << 62
	LogFileEventNotEncoded = LogFileEvent(1) << 63
	WindowSize             = 32
	SignContentSize        = 1024
)

Variables

View Source
var (
	ErrNoProgress = errors.New("Buffer Read From Line, No Prgress")
)

Functions

func ExectionTimeCost

func ExectionTimeCost(title string, start time.Time)

func InitLogger

func InitLogger(opt *LogOption)

func Retry

func Retry(times int, interval time.Duration, method func() error) error

func UnsafeSliceToString

func UnsafeSliceToString(b []byte) string

func UnsafeStringToSlice

func UnsafeStringToSlice(s string) (b []byte)

zero-copy slice convert to string

func WalkDirs

func WalkDirs(dir string, depth int, filter func(p string) bool, hook func(fs fs.FileInfo)) ([]string, error)

WalkDirs walks dir with depth, and filter matched dir filter,p is dir or file name hook is called when a file is matched

Types

type BlockingBuffer

type BlockingBuffer struct {
	// contains filtered or unexported fields
}

BlockingBuffer is a thread-safe buffer, with blocking api. It block itself when data is full

func NewBlockingBuffer

func NewBlockingBuffer(bufferSize int) *BlockingBuffer

func (*BlockingBuffer) Close

func (b *BlockingBuffer) Close()

func (*BlockingBuffer) Fetch

func (b *BlockingBuffer) Fetch() []byte

Fetch fetch data in buf and notify Waited Write

func (*BlockingBuffer) IfFullThenWait

func (b *BlockingBuffer) IfFullThenWait()

func (*BlockingBuffer) ReadLinesFrom

func (b *BlockingBuffer) ReadLinesFrom(reader *os.File, lineSep string) (int, error)

ReadLinesFrom make sure buffer read at least a line or none.

type Event

type Event struct {
	// contains filtered or unexported fields
}

func (Event) String

func (e Event) String() string

type FileMeta

type FileMeta struct {
	Inode uint64   `josn:"inode"`
	Dev   uint64   `json:"dev"`
	Hash  [16]byte `json:"hash"`
	// contains filtered or unexported fields
}

type FileSink

type FileSink struct {
	Sink
	// contains filtered or unexported fields
}

func (*FileSink) Close

func (s *FileSink) Close() error

func (*FileSink) Open

func (s *FileSink) Open(path string) error

func (*FileSink) Push

func (s *FileSink) Push(fpath string, content []byte) error

type FileSinkConf

type FileSinkConf struct {
	Dst string `json:"dst"`
}

type LogCollector

type LogCollector struct {
	// contains filtered or unexported fields
}

func NewLogCollector

func NewLogCollector() *LogCollector

TODO(link.xk): add some option: filter interval, buffer size

func (*LogCollector) Close

func (lc *LogCollector) Close() error

TODO(link.xk): make sure all resource has been released

func (*LogCollector) Init

func (lc *LogCollector) Init(conf LogConf) error

Init plz make sure log is existed, otherwise init return a error and will not collect logs. Once Log File is register, it cannot be changed or added. Log path registers only when it inits.

func (*LogCollector) Join

func (lc *LogCollector) Join()

func (*LogCollector) Run

func (lc *LogCollector) Run() error

type LogConf

type LogConf struct {
	Dir     string           `json:"dir"`
	Pattern string           `json:"pattern"`
	LineSep string           `json:"lineSeperator"`
	Sink    SinkConf         `json:"sink"`
	Watcher LogWatcherOption `json:"watcher"`
}

func ReadLogCollectorConf

func ReadLogCollectorConf(path string) (*LogConf, error)

type LogFileEvent

type LogFileEvent uint64

func (LogFileEvent) String

func (e LogFileEvent) String() string

type LogMeta

type LogMeta struct {
	Dir     string
	Pattern string

	LogInfo os.FileInfo
	// contains filtered or unexported fields
}

type LogOption

type LogOption struct {
	Verbose bool
	Level   logging.Level
}

type LogReader

type LogReader struct {
	// contains filtered or unexported fields
}

type LogWatchOption

type LogWatchOption struct {
	FilterInterval time.Duration
	PollerInterval time.Duration
}

type LogWatcher

type LogWatcher struct {
	EventC chan *Event
	// contains filtered or unexported fields
}

LogWatcher watch log files based on fsnotify. It mainly consists of a event-watcher and a event transform pattern, transform fsnotify event into LogFileEvent. Basically, it listens inotify event of log files, transforming into LogFileEvent, and pass to upper collector to cope with. The frequency of sending a event is determined by filterInterval and event kind change. It manages two goroutines in event-driven and poller mode. Event-Driven goroutine handle event from fsnotify.Watcher while poller gorotine which is trggered much less frequently, handles operations needing resume after some time, such as removeing a file by mistake.

Commonly speaking, Log File is watched as fellows: Step 1, Register File And add into fsnotify watcher. File Pattern supports glob. Note that log file's path is settled, and any other operation related with log's path will only use the determined path, rather than reseatch files.And a Discover Event is generated for each determined log file. Step 2, Watcher Events. Event is passed to LogWatcher via a chan. LogWatcher will transform raw event into LogFileEvent based on some pattern(linux only at now) or File's status. Specially, when file is removed, we consider it a mistake and put path into poller quere so that it will be rewatcher when poller triggers. Step 3: Send Event.

func NewLogWatcher

func NewLogWatcher(option *LogWatchOption) *LogWatcher

func (*LogWatcher) Close

func (lw *LogWatcher) Close()

func (*LogWatcher) Init

func (lw *LogWatcher) Init() error

func (*LogWatcher) RegisterAndWatch

func (lw *LogWatcher) RegisterAndWatch(dir, pattern string) error

RegisterAndWatch find files and register and watch them

func (*LogWatcher) RunEventHandler

func (lw *LogWatcher) RunEventHandler()

start event handler goroutine.

type LogWatcherOption

type LogWatcherOption struct {
	FilterInterval int `json:"filter"` // in sec
	PollerInterval int `json:"poller"` // in byte
}

type Sink

type Sink interface {
	Open(string) error
	Push(fpath string, content []byte) error
	Close() error
}

func NewFileSink

func NewFileSink() Sink

type SinkConf

type SinkConf struct {
	Typ  SinkType `json:"type"`
	Conf string   `json:"config"`
}

type SinkType

type SinkType string
const (
	FileSinkType SinkType = "file"
)

type TaskState

type TaskState uint64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL