tailer

package module
v0.0.0-...-fa5552c Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

README

tailer

tailer is a package for Go that tail -f the files in the watching directory, and publish to a NATS server.

Go Report Card

Installation and Usage

Install using go get github.com/clsung/tailer/cmd/tailer.

Full documentation is available at http://godoc.org/github.com/clsung/tailer

Below is an example of its usage which tail file to local nats server.

% export NATS_CLUSTER=nats://localhost:4222/
% tailer --nats /tmp

Also you can use docker image to run it. Say we want to watch /mnt/extend-disk/tmp:

% docker run -e HOSTNAME=$HOSTNAME -e NATS_CLUSTER=$NATS_CLUSTER \
	-v /mnt/extend-disk/tmp:/tmp -d clsung/tailer

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNatsExceedMaxReconnects says number of reconnect attempts exceed
	ErrNatsExceedMaxReconnects = errors.New("pubnats: exceed max reconnects")
)
View Source
var (
	// RegexNotWatch sets the file extension to avoid watching
	RegexNotWatch = regexp.MustCompile("(?:^tailer\\.|^gobzip-|^\\..+\\.swp$|\\.gz$|\\.[0-9]$)")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	FileGlob      string `json:"fileglob,omitempty"`
	Match         string `json:"match,omitempty"`
	IgnorePattern string `json:"ignore,omitempty"`
	Polling       bool   `json:"polling,omitempty"`
}

Config describe what we want and publish

type Emitter

type Emitter interface {
	Emit(msg *nats.Msg) error
	Start() error
	Stop()
}

Emitter will emit Nats messages

func NewFileEmitter

func NewFileEmitter(directory, prefix string) (Emitter, error)

NewFileEmitter return a new FileEmitter

type FileEmitter

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

FileEmitter print to file, separated by time

func (*FileEmitter) Emit

func (f *FileEmitter) Emit(m *nats.Msg) (err error)

Emit call print the nats.Msg

func (*FileEmitter) Start

func (f *FileEmitter) Start() (err error)

Start starts the fileEmitter

func (*FileEmitter) Stop

func (f *FileEmitter) Stop()

Stop stops the fileEmitter

type MessageQueue

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

MessageQueue handles the file events

func NewMessageQueue

func NewMessageQueue(maxMessages int64) *MessageQueue

NewMessageQueue returns a new MessageQueue

func (*MessageQueue) Len

func (mq *MessageQueue) Len() int64

Len returns current MessageQueue length

func (*MessageQueue) Pop

func (mq *MessageQueue) Pop() (*nats.Msg, bool)

Pop pop out a nats.Msg from queue

func (*MessageQueue) Push

func (mq *MessageQueue) Push(m *nats.Msg) int64

Push pushs the nats.Msg into queue

type NatsPublisher

type NatsPublisher struct {
	URL string
	// contains filtered or unexported fields
}

NatsPublisher will Publish messages via nats

func (*NatsPublisher) Close

func (n *NatsPublisher) Close()

Close close the channel

func (*NatsPublisher) Publish

func (n *NatsPublisher) Publish(msg []byte) error

Publish publish the message to server

func (*NatsPublisher) SetTopic

func (n *NatsPublisher) SetTopic(topic string)

SetTopic sets the publish topic

type NatsSubscriber

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

NatsSubscriber will Subscribe messages via nats

func (*NatsSubscriber) Bind

func (n *NatsSubscriber) Bind(mq *MessageQueue)

Bind to the specified message queue

func (*NatsSubscriber) Close

func (n *NatsSubscriber) Close()

Close close the channel

func (*NatsSubscriber) LastError

func (n *NatsSubscriber) LastError() (err error)

LastError stats the latest error

func (*NatsSubscriber) Subscribe

func (n *NatsSubscriber) Subscribe(topic string) error

Subscribe the topic and push to the message queue

type Publisher

type Publisher interface {
	SetTopic(topic string)
	Publish(message []byte) error
	Close()
}

Publisher will Publish messages

func NewNatsPublisher

func NewNatsPublisher(url string) (Publisher, error)

NewNatsPublisher return a Publisher using nats

type SimplePublisher

type SimplePublisher struct {
}

SimplePublisher use fmt.Println to publish

func (*SimplePublisher) Close

func (f *SimplePublisher) Close()

Close NOOP for fmt

func (*SimplePublisher) Publish

func (f *SimplePublisher) Publish(msg []byte) error

Publish call fmt.Println to print the msg

func (*SimplePublisher) SetTopic

func (f *SimplePublisher) SetTopic(topic string)

SetTopic NOOP for fmt

type SimpleSubscriber

type SimpleSubscriber struct {
}

SimpleSubscriber use fmt.Println to handle the received msg

func (*SimpleSubscriber) Bind

func (f *SimpleSubscriber) Bind(mq *MessageQueue)

Bind to the specified message queue

func (*SimpleSubscriber) Close

func (f *SimpleSubscriber) Close()

Close NOOP for fmt

func (*SimpleSubscriber) LastError

func (f *SimpleSubscriber) LastError() error

LastError stats the latest error

func (*SimpleSubscriber) Subscribe

func (f *SimpleSubscriber) Subscribe(topic string) error

Subscribe for specified topic

type StdoutEmitter

type StdoutEmitter struct {
}

StdoutEmitter use fmt.Println to publish

func (*StdoutEmitter) Emit

func (f *StdoutEmitter) Emit(msg *nats.Msg) error

Emit call fmt.Println to print the msg

func (*StdoutEmitter) Start

func (f *StdoutEmitter) Start() error

Start NOOP in stdout

func (*StdoutEmitter) Stop

func (f *StdoutEmitter) Stop()

Stop NOOP in stdout

type Subscriber

type Subscriber interface {
	Subscribe(topic string) error
	Bind(mq *MessageQueue)
	Close()
	LastError() error
}

Subscriber will Subscribe messages and do things

func NewNatsSubscriber

func NewNatsSubscriber(url string) (Subscriber, error)

NewNatsSubscriber return a Subscriber using nats

type Tailer

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

Tailer init the service functions

func NewTailer

func NewTailer(publishToNats bool, config Config) (*Tailer, error)

NewTailer makes a new Tailer

func (*Tailer) Serve

func (s *Tailer) Serve(watchDirs []string, fileGlob string)

Serve checks files in watchDirs with fileGlob pattern

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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