probe

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProbeTypeMetrics = iota
	ProbeTypeEvent
	ProbeTypeCount
)
View Source
const (
	ProbeStateStopped = iota
	ProbeStateStarting
	ProbeStateRunning
	ProbeStateStopping
	ProbeStateFailed
)
View Source
const LegacyMetricsNamespace = "inspector"
View Source
const MetricsNamespace = "kubeskoop"

Variables

View Source
var (
	ErrProbeNotExists     = errors.New("probe not exists")
	ErrProbeAlreadyExists = errors.New("probe already exists")
	ErrInvalidProbeState  = errors.New("invalid probe state")
)
View Source
var (
	ErrUndeclaredMetrics = errors.New("undeclared metrics")
)

Functions

func CopyLegacyMetricsMap added in v1.0.0

func CopyLegacyMetricsMap(m map[string]map[uint32]uint64) map[string]map[uint32]uint64

func ListEventProbes added in v1.0.0

func ListEventProbes() []string

func ListMetricsProbes added in v1.0.0

func ListMetricsProbes() []string

func MustRegisterEventProbe added in v1.0.0

func MustRegisterEventProbe(name string, creator interface{})

MustRegisterEventProbe registers the event probe by given name and creator. The creator is a function that creates EventProbe. Return values of the creator must be (EventProbe, error). The creator can accept one parameter of type chan<- *Event, or struct/map as an extra parameter. When the creator specifies the extra parameter, the configuration of the probe in the configuration file will be passed to the creator when the probe is created. For example:

The creator accepts no extra args.

func eventProbeCreator(sink chan<- *Event) (EventProbe, error)

The creator accepts struct "probeArgs" as args. Names of struct fields are case-insensitive.

	// Config in yaml
	args:
      argA: test
	  argB: 20
	  argC:
	    - a
	// Struct definition
	type probeArgs struct {
	  ArgA string
	  ArgB int
	  ArgC []string
	}
	// The creator function:
	func eventProbeCreator(sink chan<- *Event, args probeArgs) (EventProbe, error)

The creator can also use a map with string keys as parameters. However, if you use a type other than interface{} as the value type, errors may occur during the configuration parsing process.

func metricsProbeCreator(sink chan<- *Event, args map[string]string) (EventProbe, error)
func metricsProbeCreator(sink chan<- *Event, args map[string]interface{} (EventProbe, error)

func MustRegisterMetricsProbe added in v1.0.0

func MustRegisterMetricsProbe(name string, creator interface{})

MustRegisterMetricsProbe registers the metrics probe by given name and creator. The creator is a function that creates MetricProbe. Return values of the creator must be (MetricsProbe, error). The creator can accept no parameter, or struct/map as a parameter. When the creator specifies the parameter, the configuration of the probe in the configuration file will be passed to the creator when the probe is created. For example:

The creator accepts no extra args.

func metricsProbeCreator() (MetricsProbe, error)

The creator accepts struct "probeArgs" as args. Names of struct fields are case-insensitive.

	// Config in yaml
	args:
      argA: test
	  argB: 20
	  argC:
	    - a
	// Struct definition
	type probeArgs struct {
	  ArgA string
	  ArgB int
	  ArgC []string
	}
	// The creator function:
	func metricsProbeCreator(args probeArgs) (MetricsProbe, error)

The creator can also use a map with string keys as parameters. However, if you use a type other than interface{} as the value type, errors may occur during the configuration parsing process.

func metricsProbeCreator(args map[string]string) (MetricsProbe, error)
func metricsProbeCreator(args map[string]interface{} (MetricsProbe, error)

func NewLegacyBatchMetrics added in v1.0.0

func NewLegacyBatchMetrics(module string, metrics []string, collector LegacyCollector) prometheus.Collector

func NewLegacyBatchMetricsWithUnderscore added in v1.0.0

func NewLegacyBatchMetricsWithUnderscore(module string, metrics []string, collector LegacyCollector) prometheus.Collector

Types

type BatchMetrics added in v1.0.0

type BatchMetrics struct {
	ProbeCollector Collector
	// contains filtered or unexported fields
}

func NewBatchMetrics added in v1.0.0

func NewBatchMetrics(opts BatchMetricsOpts, probeCollector Collector) *BatchMetrics

func (*BatchMetrics) Collect added in v1.0.0

func (b *BatchMetrics) Collect(metrics chan<- prometheus.Metric)

func (*BatchMetrics) Describe added in v1.0.0

func (b *BatchMetrics) Describe(descs chan<- *prometheus.Desc)

type BatchMetricsOpts added in v1.0.0

type BatchMetricsOpts struct {
	Namespace         string
	Subsystem         string
	ConstLabels       map[string]string
	VariableLabels    []string
	SingleMetricsOpts []SingleMetricsOpts
}

type Collector added in v1.0.0

type Collector func(emit Emit) error

type Emit added in v1.0.0

type Emit func(name string, labels []string, val float64)

type Event added in v1.0.0

type Event struct {
	Timestamp int64     `json:"timestamp"`
	Type      EventType `json:"type"`
	Labels    []Label   `json:"labels"`
	Message   string    `json:"msg"`
}

type EventProbe added in v1.0.0

type EventProbe interface {
	Probe
}

func CreateEventProbe added in v1.0.0

func CreateEventProbe(name string, sink chan<- *Event, args map[string]interface{}) (EventProbe, error)

func NewEventProbe added in v1.0.0

func NewEventProbe(name string, simpleProbe SimpleProbe) EventProbe

type EventType added in v1.0.0

type EventType string

type Label added in v1.0.0

type Label struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

func EventMetaByNetNS added in v1.0.0

func EventMetaByNetNS(netns int) []Label

func LagacyEventLabels added in v1.0.0

func LagacyEventLabels(netns uint32) []Label

type LegacyCollector added in v1.0.0

type LegacyCollector func() (map[string]map[uint32]uint64, error)

type MetricsProbe added in v1.0.0

type MetricsProbe interface {
	Probe
	prometheus.Collector
}

func CreateMetricsProbe added in v1.0.0

func CreateMetricsProbe(name string, args map[string]interface{}) (MetricsProbe, error)

func NewMetricsProbe added in v1.0.0

func NewMetricsProbe(name string, simpleProbe SimpleProbe, collector prometheus.Collector) MetricsProbe

type Probe added in v1.0.0

type Probe interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	State() State
	Name() string
}

func NewProbe added in v1.0.0

func NewProbe(name string, probe SimpleProbe) Probe

type RawEvent added in v1.0.0

type RawEvent struct {
	Netns     uint32
	EventType string
	EventBody string
}

type SimpleProbe added in v1.0.0

type SimpleProbe interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

type SingleMetricsOpts added in v1.0.0

type SingleMetricsOpts struct {
	Name           string
	Help           string
	ConstLabels    map[string]string
	VariableLabels []string
	ValueType      prometheus.ValueType
}

type State added in v1.0.0

type State uint8

func (State) String added in v1.0.0

func (ps State) String() string

type Type added in v1.0.0

type Type uint8

func (Type) String added in v1.0.0

func (p Type) String() string

Jump to

Keyboard shortcuts

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