Documentation
¶
Overview ¶
Package logs collects system logs: file tails (with offsets kept per inode and multiline joining), journald, the Windows Event Log and a syslog receiver, all forwarded as OTLP logs.
Index ¶
- func KafkaRecord(out sink.Sink, r *kgo.Record)
- func Run(ctx context.Context, raw json.RawMessage, stateDir string, out sink.Sink) error
- func RunDocker(ctx context.Context, c DockerLogs, stateDir string, out sink.Sink) error
- func RunJournald(ctx context.Context, path, stateDir string, out sink.Sink) error
- func RunKafka(ctx context.Context, c KafkaLogs, out sink.Sink) error
- func RunSyslog(ctx context.Context, c SyslogConf, out sink.Sink) error
- func RunTail(ctx context.Context, specs []TailSpec, stateDir string, out sink.Sink) error
- func RunWinEvents(ctx context.Context, _ WinEvent, _ sink.Sink) error
- func Severity(body string) string
- type Config
- type DockerLogs
- type Entry
- type Journal
- type KafkaLogs
- type Multiline
- type Record
- type State
- type SyslogConf
- type TailSpec
- type Tailer
- type WinEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KafkaRecord ¶
KafkaRecord writes one record as a log line.
func RunJournald ¶
RunJournald follows the journal with `journalctl -o json -f`. It keeps the __CURSOR of the last record in <stateDir>/journald.cursor (written atomically, at most every 5 s and when the process ends) and resumes with --after-cursor, so a restart neither loses the downtime nor replays more than a few seconds. The binary path is local config only. Off Linux it waits.
func RunWinEvents ¶
RunWinEvents has nothing to read off Windows.
Types ¶
type Config ¶
type Config struct {
Enabled *bool `json:"enabled"`
Files []TailSpec `json:"files"`
Journal *Journal `json:"journald"`
WinEvt *WinEvent `json:"windows_events"`
Syslog *SyslogConf `json:"syslog"`
Docker *DockerLogs `json:"docker"`
Kafka *KafkaLogs `json:"kafka"`
}
Config is the logs module's config. Only Enabled can be set remotely (Interval has no meaning here); every path, command and listen address is local-file only.
type DockerLogs ¶
type DockerLogs struct {
Host string `json:"host"` // unix:///var/run/docker.sock (default) or http(s)://
Labels map[string]string `json:"labels"` // only containers carrying every label (server-side filter)
// RequireLabels makes empty Labels follow nothing instead of every container (shared hosts).
RequireLabels bool `json:"require_labels"`
// MaxRecordsPerSec caps records per container; the excess is dropped and reported as a WARN
// record. 0 (default) means no cap, so a busy workload never loses logs unless asked.
MaxRecordsPerSec int `json:"max_records_per_second"`
}
DockerLogs selects the engine and containers.
type Entry ¶
type Entry struct {
Off int64 `json:"off"`
Size int64 `json:"size"` // size when last read
MTime int64 `json:"mtime"` // mtime (unix ns) when last read
Seen int64 `json:"seen"` // unix seconds the file was last matched
}
Entry is what is remembered per file identity.
type Journal ¶
type Journal struct {
Path string `json:"journalctl_path"` // default "journalctl"
}
Journal enables the journald reader.
type KafkaLogs ¶
type KafkaLogs struct {
Brokers []string `json:"brokers"`
Topics []string `json:"topics"`
Group string `json:"group"` // default wt-agent-logs
TLS bool `json:"tls"`
SASL *struct {
Username string `json:"username"`
Password string `json:"password"`
} `json:"sasl_plain"`
}
KafkaLogs is the consumer's configuration. The SASL password may be a secret reference.
type Multiline ¶
type Multiline struct {
StartPattern string `json:"start_pattern"`
MaxLines int `json:"max_lines"` // default 500
MaxWait string `json:"max_wait"` // default 2s: a pending record is flushed after this much quiet
}
Multiline joins the lines of one record (a stack trace) per file input: `multiline: {start_pattern, max_lines, max_wait}`. A line matching StartPattern begins a new record. It supersedes the older flat `multiline_start` key, which still works.
type Record ¶
type Record struct {
Severity string // DEBUG, INFO, WARN or ERROR
Body string
At time.Time
Attrs map[string]string
Cursor string // journald __CURSOR
}
Record is one log record before export.
func ParseEventXML ¶
ParseEventXML converts a rendered event (EvtRenderEventXml) into a record. The body is the provider, the event id and the event data; the localized message text is not resolved.
func ParseJournalLine ¶
ParseJournalLine parses one line of `journalctl -o json`.
type State ¶
type State struct {
Off map[string]Entry `json:"offsets"`
// contains filtered or unexported fields
}
State persists, per file identity (device+inode, or volume+index on Windows), the offset up to which records were delivered, so a restart resumes exactly there and a rename keeps its place. Size and mtime expose a reused inode: a "new" file that is smaller or older than what was last read under that identity starts at 0. It is written (fsync) only when something changed.
type SyslogConf ¶
SyslogConf makes the agent a syslog receiver. Addresses come from the local file only. The listener is unauthenticated: bind it to loopback or a trusted interface, and use a port above 1024 for an unprivileged agent.
type TailSpec ¶
type TailSpec struct {
Path string `json:"path"` // a filepath.Glob pattern
// MultilineStart is a regex that matches the first line of a record; lines that do not match
// are joined to the previous record (stack traces). Empty: one line, one record.
MultilineStart string `json:"multiline_start"`
// Multiline is the fuller form (pattern, line cap, quiet period); see multiline.go.
Multiline *Multiline `json:"multiline"`
// FromBeginning reads files found at startup from their first byte (default: from the end).
// Files that appear later are always read whole.
FromBeginning bool `json:"from_beginning"`
Labels map[string]string `json:"labels"`
// MaxFiles raises the per-pattern file cap (default 200, at most 5000); the Kubernetes node
// agent needs it for nodes with many containers.
MaxFiles int `json:"max_files"`
}
TailSpec is one file pattern to follow. All of it comes from the agent's own config file.