webtail

package module
v0.47.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 17 Imported by: 1

README

webtail

Tail [log]files via websocket

English | Pусский | 日本語


Go Reference GitHub Release Build Status GitHub license

Go Coverage Test Coverage Maintainability GoCard

webtail is a web-service and golang package used for continious updated files publication via websocker to browser.

Ping stream sample

Install

go get -v github.com/LeKovr/webtail/...
Download binary

See Latest release

Docker

Starting from 0.43.2 docker images are published at GitHub Packages, so use

docker pull ghcr.io/lekovr/webtail:latest

See docker-compose.yml for usage example.

v0.43.1 is the last version available at dockerhub.

Use package in your service

package main
import (
    "github.com/LeKovr/webtail"
)

func main() {
    wt, err := webtail.New(log, cfg)
    if err != nil {
        return
    }
    go wt.Run()
    defer wt.Close()
    // ...
    http.Handle("/tail", wt)
}

See also: app.go

Note about gorilla/websocket

Starting from v0.30 this code is based on gorilla/websocket chat example. See {client,hub}.go

License

The MIT License (MIT), see LICENSE.

Copyright (c) 2016-2021 Aleksey Kovrizhkin lekovr+webtail@gmail.com

Documentation

Overview

Package webtail holds tailer service You don't need anything except Service methods

Index

Constants

View Source
const (
	MsgSubscribed        = "success"
	MsgUnSubscribed      = "success"
	MsgUnknownChannel    = "unknown channel"
	MsgNotSubscribed     = "not subscribed"
	MsgWorkerError       = "worker create error"
	MsgSubscribedAlready = "attached already"
	MsgNone              = ""
)

Returned Messages

Variables

This section is empty.

Functions

func FileServer added in v0.46.0

func FileServer(path string) http.Handler

FileServer return embedded or given fs

Types

type Client added in v0.43.1

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

Client is a middleman between the websocket connection and the hub.

type Config

type Config struct {
	Root        string `long:"root"  default:"log/"  description:"Root directory for log files"`
	Bytes       int64  `long:"bytes" default:"5000"  description:"tail from the last Nth location"`
	Lines       int    `long:"lines" default:"100"   description:"keep N old lines for new consumers"`
	MaxLineSize int    `long:"split" default:"180"   description:"split line if longer"`
	ListCache   int    `long:"cache" default:"2"      description:"Time to cache file listing (sec)"`
	Poll        bool   `long:"poll"  description:"use polling, instead of inotify"`
	Trace       bool   `long:"trace" description:"trace worker channels"`

	ClientBufferSize  int `long:"out_buf"      default:"256"  description:"Client Buffer Size"`
	WSReadBufferSize  int `long:"ws_read_buf"  default:"1024" description:"WS Read Buffer Size"`
	WSWriteBufferSize int `long:"ws_write_buf" default:"1024" description:"WS Write Buffer Size"`
}

Config defines local application flags

type Hub added in v0.43.1

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

Hub maintains the set of active clients and broadcasts messages to them

func NewHub added in v0.45.0

func NewHub(logger logr.Logger, ts *TailService, wg *sync.WaitGroup) *Hub

NewHub creates hub for client services

func (*Hub) Close added in v0.45.0

func (h *Hub) Close()

Close closes message processing

func (*Hub) Run added in v0.45.0

func (h *Hub) Run()

Run processes hub messages

type InMessage added in v0.45.0

type InMessage struct {
	Type    string `json:"type"`
	Channel string `json:"channel,omitempty"`
}

InMessage holds incoming client request

type IndexItemAttr added in v0.44.0

type IndexItemAttr struct {
	ModTime time.Time `json:"mtime"`
	Size    int64     `json:"size"`
}

IndexItemAttr holds File (index item) Attrs

type IndexItemAttrStore added in v0.44.0

type IndexItemAttrStore map[string]*IndexItemAttr

IndexItemAttrStore holds all index items

type IndexItemEvent added in v0.44.0

type IndexItemEvent struct {
	ModTime time.Time `json:"mtime"`
	Size    int64     `json:"size"`
	Name    string    `json:"name"`
	Deleted bool      `json:"deleted,omitempty"`
}

IndexItemEvent holds messages from indexer

type IndexMessage added in v0.45.0

type IndexMessage struct {
	Type  string         `json:"type"`
	Data  IndexItemEvent `json:"data"`
	Error string         `json:"error,omitempty"`
}

IndexMessage holds outgoing message item for file index

type Message added in v0.43.1

type Message struct {
	Client  *Client
	Message []byte
}

Message holds received message and sender

type Service added in v0.43.1

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

Service holds WebTail service

func New added in v0.43.1

func New(log logr.Logger, cfg *Config) (*Service, error)

New creates WebTail service

func (*Service) Close added in v0.45.0

func (wt *Service) Close()

Close stops a message hub

func (*Service) Run added in v0.43.1

func (wt *Service) Run()

Run runs a message hub

func (*Service) ServeHTTP added in v0.44.0

func (wt *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

Handle handles websocket requests from the peer

type StatsMessage added in v0.45.0

type StatsMessage struct {
	Type string            `json:"type"`
	Data map[string]uint64 `json:"data,omitempty"`
}

StatsMessage holds outgoing app stats

type TailAttr added in v0.45.0

type TailAttr struct {
	// Store for last Config.Lines lines
	Buffer [][]byte

	// Quit worker process
	Quit chan struct{}

	// Skip 1st line when read file not from start
	IsHeadTrimmed bool
}

TailAttr holds tail worker attributes

type TailMessage added in v0.45.0

type TailMessage struct {
	Type    string `json:"type"`
	Channel string `json:"channel,omitempty"`
	Data    string `json:"data,omitempty"`
}

TailMessage holds outgoing file tail row

type TailService added in v0.45.0

type TailService struct {
	Config *Config
	// contains filtered or unexported fields
}

TailService holds Worker hub operations

func NewTailService added in v0.45.0

func NewTailService(logger logr.Logger, cfg *Config) (*TailService, error)

NewTailService creates tailer service

func (*TailService) ChannelExists added in v0.45.0

func (ts *TailService) ChannelExists(channel string) bool

ChannelExists checks if channel allowed to attach

func (*TailService) IndexItem added in v0.45.0

func (ts *TailService) IndexItem(key string) *IndexItemAttr

IndexItem returns index item

func (*TailService) IndexKeys added in v0.45.0

func (ts *TailService) IndexKeys() []string

IndexKeys returns sorted index keys

func (*TailService) IndexUpdate added in v0.45.0

func (ts *TailService) IndexUpdate(msg *IndexItemEvent)

IndexUpdate updates TailService index item

func (*TailService) IndexerRun added in v0.45.0

func (ts *TailService) IndexerRun(out chan *IndexItemEvent, wg *sync.WaitGroup)

IndexerRun runs indexer

func (*TailService) SetTrace added in v0.45.0

func (ts *TailService) SetTrace(mode string)

SetTrace turns on/off logging of incoming workers messages

func (*TailService) TailerAppend added in v0.45.0

func (ts *TailService) TailerAppend(channel string, data []byte) bool

TailerAppend adds a line into worker buffer

func (*TailService) TailerBuffer added in v0.45.0

func (ts *TailService) TailerBuffer(channel string) [][]byte

TailerBuffer returns worker buffer

func (*TailService) TailerRun added in v0.45.0

func (ts *TailService) TailerRun(channel string, out chan *TailMessage, readyChan chan struct{}, wg *sync.WaitGroup) error

TailerRun creates and runs tail worker

func (*TailService) TraceEnabled added in v0.45.0

func (ts *TailService) TraceEnabled() bool

TraceEnabled returns trace state

func (*TailService) WorkerExists added in v0.45.0

func (ts *TailService) WorkerExists(channel string) bool

WorkerExists checks if worker already registered

func (*TailService) WorkerStop added in v0.45.0

func (ts *TailService) WorkerStop(channel string)

WorkerStop stops worker (tailer or indexer)

type TraceMessage added in v0.45.0

type TraceMessage struct {
	Type    string `json:"type"`
	Enabled bool   `json:"enabled"`
}

TraceMessage holds outgoing trace state

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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