drain

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

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 6 Imported by: 0

README

Drain

This project is an golang port of the original Drain3 project.

Drain is an online log template miner that can extract templates (clusters) from a stream of log messages in a timely manner. It employs a parse tree with fixed depth to guide the log group search process, which effectively avoids constructing a very deep and unbalanced tree.

Example

package main

import (
	"fmt"

	"github.com/faceair/drain"
)

func main() {
	logger := drain.New(drain.DefaultConfig())

	for _, line := range []string{
		"connected to 10.0.0.1",
		"connected to 10.0.0.2",
		"connected to 10.0.0.3",
		"Hex number 0xDEADBEAF",
		"Hex number 0x10000",
		"user davidoh logged in",
		"user eranr logged in",
	} {
		logger.Train(line)
	}

	for _, cluster := range logger.Clusters() {
		println(cluster.String())
	}

	cluster := logger.Match("user faceair logged in")
	if cluster == nil {
		println("no match")
	} else {
		fmt.Printf("cluster matched: %s", cluster.String())
	}
}

Output:

id={1} : size={3} : connected to <*>
id={2} : size={2} : Hex number <*>
id={3} : size={2} : user <*> logged in
cluster matched: id={3} : size={2} : user <*> logged in

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	LogClusterDepth int
	SimTh           float64
	MaxChildren     int
	ExtraDelimiters []string
	MaxClusters     int
	ParamString     string
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() *Config

type Drain

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

func New

func New(config *Config) *Drain

func (*Drain) Clusters

func (d *Drain) Clusters() []*LogCluster

func (*Drain) Match

func (d *Drain) Match(content string) *LogCluster

Match against an already existing cluster. Match shall be perfect (sim_th=1.0). New cluster will not be created as a result of this call, nor any cluster modifications.

func (*Drain) Train

func (d *Drain) Train(content string) *LogCluster

type LogCluster

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

func (*LogCluster) GetTemplate

func (c *LogCluster) GetTemplate() string

func (*LogCluster) String

func (c *LogCluster) String() string

type LogClusterCache

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

func (*LogClusterCache) Get

func (c *LogClusterCache) Get(key int) *LogCluster

func (*LogClusterCache) Set

func (c *LogClusterCache) Set(key int, cluster *LogCluster)

func (*LogClusterCache) Values

func (c *LogClusterCache) Values() []*LogCluster

type Node

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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