engine

package
v0.6.29 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// metrics prefix
	MetricsPrefix = "gudgeon-"
	// metrics names are prefixed by the metrics prefix and delim
	TotalRules             = "active-rules"
	TotalQueries           = "total-session-queries"
	TotalLifetimeQueries   = "total-lifetime-queries"
	TotalIntervalQueries   = "total-interval-queries"
	CachedQueries          = "cached-queries"
	BlockedQueries         = "blocked-session-queries"
	BlockedLifetimeQueries = "blocked-lifetime-queries"
	BlockedIntervalQueries = "blocked-interval-queries"
	QueriesPerSecond       = "session-queries-ps"
	BlocksPerSecond        = "session-blocks-ps"
	QueryTime              = "query-time"
	QueryTimeAvg           = "query-time-avg"
	// cache entries
	CurrentCacheEntries = "cache-entries"
	// runtime metrics
	GoRoutines         = "goroutines"
	Threads            = "process-threads"
	CurrentlyAllocated = "allocated-bytes"    // heap allocation in go runtime stats
	UsedMemory         = "process-used-bytes" // from the process api
	// cpu metrics
	CPUHundredsPercent = "cpu-hundreds-percent" // 17 == 0.17 percent, expressed in integer terms
	// worker metrics (should be qualified with -workertype, ie: "gudgeon-workers-tcp")
	Workers = "workers"
)

Variables

This section is empty.

Functions

func CacheMulticastMessages added in v0.6.1

func CacheMulticastMessages(cache *gocache.Cache, msgChan chan *dns.Msg)

func Download added in v0.1.9

func Download(engine Engine, config *config.GudgeonConfig, list *config.GudgeonList) error

func MulticastMdnsListen added in v0.6.1

func MulticastMdnsListen(msgChan chan *dns.Msg, closeChan chan bool)

func MulticastMdnsQuery added in v0.6.1

func MulticastMdnsQuery()

func NewRecorder added in v0.6.1

func NewRecorder(conf *config.GudgeonConfig, engine Engine, db *sql.DB, metrics Metrics, qlog QueryLog) (*recorder, error)

created from raw engine

func ParseMulticastMessage added in v0.6.1

func ParseMulticastMessage(msg *dns.Msg) (map[string]string, error)

func ReadCachedHostname added in v0.6.1

func ReadCachedHostname(cache *gocache.Cache, address string) string

Types

type CacheSizeFunction added in v0.6.1

type CacheSizeFunction = func() int64

type Engine

type Engine interface {
	IsDomainRuleMatched(consumer *net.IP, domain string) (rule.Match, *config.GudgeonList, string)
	Resolve(domainName string) (string, error)
	Reverse(address string) string

	// different direct handle methods
	Handle(address *net.IP, protocol string, request *dns.Msg) (*dns.Msg, *resolver.RequestContext, *resolver.ResolutionResult)
	HandleWithConsumerName(consumerName string, rCon *resolver.RequestContext, request *dns.Msg) (*dns.Msg, *resolver.RequestContext, *resolver.ResolutionResult)
	HandleWithConsumer(consumer *consumer, rCon *resolver.RequestContext, request *dns.Msg) (*dns.Msg, *resolver.RequestContext, *resolver.ResolutionResult)
	HandleWithGroups(groups []string, rCon *resolver.RequestContext, request *dns.Msg) (*dns.Msg, *resolver.RequestContext, *resolver.ResolutionResult)
	HandleWithResolvers(resolvers []string, rCon *resolver.RequestContext, request *dns.Msg) (*dns.Msg, *resolver.RequestContext, *resolver.ResolutionResult)

	// info, things by name
	Consumers() *[]string
	Groups() *[]string
	Resolvers() *[]string
	Lists() *[]*ListEntry

	// stats
	CacheSize() int64

	// inner providers
	QueryLog() QueryLog
	Metrics() Metrics

	// close engine and all resources
	Close()

	// shutdown engine and all threads
	Shutdown()
}

func NewEngine added in v0.6.1

func NewEngine(conf *config.GudgeonConfig) (Engine, error)

func NewReloadingEngine added in v0.6.11

func NewReloadingEngine(confPath string, conf *config.GudgeonConfig) (Engine, error)

type InfoRecord added in v0.6.1

type InfoRecord struct {
	// client address
	Address string

	// hold the information but aren't serialized
	Request        *dns.Msg                   `json:"-"`
	Response       *dns.Msg                   `json:"-"`
	Result         *resolver.ResolutionResult `json:"-"`
	RequestContext *resolver.RequestContext   `json:"-"`

	// generated/calculated values
	Consumer       string
	ClientName     string
	ConnectionType string
	RequestDomain  string
	RequestType    string
	ResponseText   string
	Rcode          string

	// hard consumer blocked
	Blocked bool

	// matching
	Match          rule.Match
	MatchList      string
	MatchListShort string
	MatchRule      string

	// cached in resolver cache store
	Cached bool

	// when this log record was created
	Created  time.Time
	Finished time.Time

	// how long it took to service the request inside the engine
	ServiceMilliseconds int64
}

info passed over channel and stored in database and that is recovered via the Query method

type ListEntry added in v0.6.17

type ListEntry struct {
	Name  string `json:"name"`
	Short string `json:"short"`
}

represents a short/name combination for a list

type Metric added in v0.6.1

type Metric struct {
	Count int64 `json:"count"`
}

func (*Metric) Clear added in v0.6.1

func (metric *Metric) Clear() *Metric

func (*Metric) Inc added in v0.6.1

func (metric *Metric) Inc(byValue int64) *Metric

func (*Metric) Set added in v0.6.1

func (metric *Metric) Set(newValue int64) *Metric

func (*Metric) Value added in v0.6.1

func (metric *Metric) Value() int64

type Metrics added in v0.6.1

type Metrics interface {
	GetAll() *map[string]*Metric
	Get(name string) *Metric

	// duration of metrics retention
	Duration() *time.Duration

	// duration between metrics collection
	Interval() *time.Duration

	// use cache function
	UseCacheSizeFunction(function CacheSizeFunction)

	// Query metrics from db
	Query(start time.Time, end time.Time) ([]*MetricsEntry, error)
	QueryFunc(accumulatorFunction MetricsAccumulator, options QueryOptions, unmarshall bool, start time.Time, end time.Time) error

	// top information
	TopClients(limit int) []*TopInfo
	TopDomains(limit int) []*TopInfo
	TopQueryTypes(limit int) []*TopInfo
	TopLists(limit int) []*TopInfo
	TopRules(limit int) []*TopInfo

	// stop the metrics collection
	Stop()
	// contains filtered or unexported methods
}

func NewMetrics added in v0.6.1

func NewMetrics(config *config.GudgeonConfig, db *sql.DB) Metrics

type MetricsAccumulator added in v0.6.11

type MetricsAccumulator = func(entry *MetricsEntry)

allows the same query and row scan logic to share code

type MetricsEntry added in v0.6.1

type MetricsEntry struct {
	FromTime        time.Time
	AtTime          time.Time
	JsonBytes       []byte             `json:"-"`
	Values          map[string]*Metric `json:"Values,omitempty"`
	IntervalSeconds int
}

type QueryAccumulator added in v0.6.11

type QueryAccumulator = func(count uint64, info *InfoRecord)

type QueryLog added in v0.6.1

type QueryLog interface {
	Query(query *QueryLogQuery) ([]*InfoRecord, uint64)
	QueryFunc(query *QueryLogQuery, accumulator QueryAccumulator)
	Stop()
	// contains filtered or unexported methods
}

public interface

func NewQueryLog added in v0.6.1

func NewQueryLog(conf *config.GudgeonConfig, db *sql.DB) (QueryLog, error)

create a new query log according to configuration

type QueryLogQuery added in v0.6.1

type QueryLogQuery struct {
	// query on fields
	Address        string
	ClientName     string
	ConnectionType string
	RequestDomain  string
	RequestType    string
	ResponseText   string
	Blocked        *bool
	Cached         *bool
	// aspects of the match
	Match     *rule.Match
	MatchList string
	MatchRule string
	// query on created time
	After  *time.Time
	Before *time.Time
	// query limits for paging
	Skip  int
	Limit int
	// query sort
	SortBy    string
	Direction string
}

the type that is used to make queries against the query log (should be used by the web interface to find queries)

type QueryOptions added in v0.6.26

type QueryOptions struct {
	// a list of metrics names to "choose"
	// to return
	ChosenMetrics string
	// will be used as a modulus to skip rows
	// which reduces the resolution of a given
	// metrics stream and makes the graph
	// less cluttered
	StepSize int
}

query options

type ReverseLookupFunction added in v0.6.1

type ReverseLookupFunction = func(address string) string

allows a dependency injection-way of defining a reverse lookup function, takes a string address (should be an IP) and returns a string that contains the domain name result

type TopInfo added in v0.6.1

type TopInfo struct {
	Desc  string
	Count uint64
}

info from db

Jump to

Keyboard shortcuts

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