dmesg

package
v0.4.4-rc.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package dmesg provides the functionality to poll the dmesg log.

Index

Constants

View Source
const (
	DefaultCacheExpiration    = 5 * time.Minute
	DefaultCachePurgeInterval = 10 * time.Minute
)
View Source
const EventKeyLogLine = "log_line"

Variables

View Source
var DefaultDmesgScanCommands = [][]string{
	{"dmesg --decode --time-format=iso --nopager --buffer-size 163920"},
}
View Source
var DefaultWatchCommands = [][]string{
	{"dmesg --decode --time-format=iso --nopager --buffer-size 163920 -w || true"},

	{"dmesg --decode --time-format=iso --nopager --buffer-size 163920 || true"},

	{"dmesg --decode --time-format=iso --nopager --buffer-size 163920 -W || true"},
}

Functions

func ParseCtimeWithError

func ParseCtimeWithError(line []byte) (time.Time, []byte, error)

ParseCtimeWithError Parses the timestamp from "dmesg --ctime" output lines. Returns a zero time if the timestamp is not found or the timestamp is invalid. Returns an error if the timestamp is not found or the timestamp is invalid.

func ParseISOtimeWithError added in v0.1.9

func ParseISOtimeWithError(line []byte) (time.Time, []byte, error)

ParseISOtimeWithError parses the timestamp from "dmesg --time-format=iso" output lines. ref. "The definition of the iso timestamp is: YYYY-MM-DD<T>HH:MM:SS,<microseconds>←+><timezone offset from UTC>."

func ParseShortISOtimeWithError added in v0.3.8

func ParseShortISOtimeWithError(line []byte) (time.Time, []byte, error)

ParseShortISOtimeWithError parses the timestamp from "journalctl -o short-iso" output lines.

Types

type LogLine added in v0.4.0

type LogLine struct {
	Timestamp time.Time
	Facility  string
	Level     string
	Content   string

	// Error is set when a dmesg command fails.
	Error string
}

func ParseDmesgLine added in v0.4.0

func ParseDmesgLine(line string) LogLine

parses the timestamp from "dmesg --time-format=iso" output lines. "The definition of the iso timestamp is: YYYY-MM-DD<T>HH:MM:SS,<microseconds>←+><timezone offset from UTC>."

func (LogLine) IsEmpty added in v0.4.0

func (l LogLine) IsEmpty() bool

type LogLineProcessor added in v0.4.4

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

func NewLogLineProcessor added in v0.4.4

func NewLogLineProcessor(ctx context.Context, dmesgWatcher Watcher, matchFunc MatchFunc, eventsStore events_db.Store) (*LogLineProcessor, error)

Creates a new log line processor where it streams logs from the dmesg watcher, uses the match function, and inserts the events into the events store. If the dmesg watcher is not provided, it will create a default one.

func (*LogLineProcessor) Close added in v0.4.4

func (w *LogLineProcessor) Close()

func (*LogLineProcessor) Get added in v0.4.4

func (w *LogLineProcessor) Get(ctx context.Context, since time.Time) ([]components.Event, error)

Returns the event in the descending order of timestamp (latest event first).

type MatchFunc added in v0.4.4

type MatchFunc func(line string) (eventName string, message string)

type Watcher added in v0.4.0

type Watcher interface {
	// Watch returns a channel that emits log lines.
	// The channel is closed on (1) process exit, (2) on calling "Close" method
	Watch() <-chan LogLine
	// Closes the existing/ongoing watch/stream routines.
	// Safe to call multiple times.
	Close()
}

func NewWatcher added in v0.4.0

func NewWatcher() (Watcher, error)

func NewWatcherWithCommands added in v0.4.0

func NewWatcherWithCommands(cmds [][]string) (Watcher, error)

Jump to

Keyboard shortcuts

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