tasks

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSemaphorePool = NewSemaphorePool()
View Source
var ErrNaN = errors.New("value is NaN or Inf")
View Source
var LookupIP = func(ctx context.Context, t configs.IPType, domain string) ([]net.IP, error) {
	// 选择解析ip类型
	var network string
	switch t {
	case configs.IPv4:
		network = "ip4"
	case configs.IPv6:
		network = "ip6"
	default:
		network = "ip"
	}

	ret := utils.CheckIpOrDomainValid(domain)
	if ret == utils.Domain {
		network = "ip"
	}
	ips, err := net.DefaultResolver.LookupIP(ctx, network, domain)
	if err != nil {
		return nil, err
	}

	resultIPs := make([]net.IP, 0, len(ips))
	for _, ip := range ips {
		if ip == nil {

			logger.Debugf("ips is empty")
			continue
		}

		if p4 := ip.To4(); p4 != nil {
			ip = p4
		}
		resultIPs = append(resultIPs, ip)
	}

	if len(resultIPs) == 0 {
		return nil, &net.AddrError{
			Err:  "no address found",
			Addr: domain,
		}
	}
	return resultIPs, nil
}

LookupIP 按照类型解析域名为ip列表

Functions

func DefaultIPs

func DefaultIPs(t configs.IPType) []string

DefaultIPs 按照ip类型获取默认IP

func GetListeningIPs

func GetListeningIPs(addr string) []string

GetListeningIPs 实际监听所有IP

func GetSystemType

func GetSystemType() string

GetSystemType 32-bit or 64-bit or unknown

func HashLabels

func HashLabels(lbs labels.Labels) string

func Map2slice

func Map2slice(m map[string]struct{}) []string

func MatchTraces

func MatchTraces(labels map[string]string) (string, string)

func SendFailEvent

func SendFailEvent(dataID int32, e chan<- define.Event)

SendFailEvent :

func UniqueSlice

func UniqueSlice(lst []string) []string

Types

type BaseTask

type BaseTask struct {
	Status       define.Status
	GlobalConfig define.Config
	TaskConfig   define.TaskConfig

	HookPreRun  utils.HookManager
	HookPostRun utils.HookManager
	// contains filtered or unexported fields
}

BaseTask :

func (*BaseTask) GetConfig

func (t *BaseTask) GetConfig() define.TaskConfig

func (*BaseTask) GetGlobalConfig

func (t *BaseTask) GetGlobalConfig() define.Config

func (*BaseTask) GetSemaphore

func (t *BaseTask) GetSemaphore() Semaphore

func (*BaseTask) GetStatus

func (t *BaseTask) GetStatus() define.Status

func (*BaseTask) GetTaskID

func (t *BaseTask) GetTaskID() int32

func (*BaseTask) Init

func (t *BaseTask) Init()

func (*BaseTask) PostRun

func (t *BaseTask) PostRun(ctx context.Context)

PostRun :

func (*BaseTask) PreRun

func (t *BaseTask) PreRun(ctx context.Context)

PreRun :

func (*BaseTask) Reload

func (t *BaseTask) Reload()

func (*BaseTask) SetConfig

func (t *BaseTask) SetConfig(config define.TaskConfig)

func (*BaseTask) SetGlobalConfig

func (t *BaseTask) SetGlobalConfig(config define.Config)

func (*BaseTask) Stop

func (t *BaseTask) Stop()

func (*BaseTask) Wait

func (t *BaseTask) Wait()

type BufferBuilder

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

BufferBuilder :

func NewBufferBuilder

func NewBufferBuilder() *BufferBuilder

NewBufferBuilder :

func (*BufferBuilder) GetBuffer

func (b *BufferBuilder) GetBuffer(initSize int) []byte

GetBuffer :

type CmdbEventSender

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

func (*CmdbEventSender) DuplicateRecordByCMDBLevel

func (s *CmdbEventSender) DuplicateRecordByCMDBLevel(m common.MapStr, labels []configs.Label) []common.MapStr

DuplicateRecordByCMDBLevel 根据下发的信息,将一条数据复制为多条返回

type CustomMetricEvent

type CustomMetricEvent struct {
	*MetricEvent
	Timestamp int64
}

CustomMetricEvent metricbeat转自定义时序上报

func (*CustomMetricEvent) AsMapStr

func (e *CustomMetricEvent) AsMapStr() common.MapStr

type Event

type Event struct {
	DataID            int32
	BizID             int32
	TaskID            int32
	TaskType          string
	Available         float64
	Status            int32
	ErrorCode         define.NamedCode
	StartAt           time.Time
	EndAt             time.Time
	AvailableDuration time.Duration
	Labels            []map[string]string
}

Event :

func NewEvent

func NewEvent(task define.Task) *Event

NewEvent :

func (*Event) AsMapStr

func (e *Event) AsMapStr() common.MapStr

AsMapStr :

func (*Event) Fail

func (e *Event) Fail(code define.NamedCode)

Fail :

func (*Event) FailWithTime

func (e *Event) FailWithTime(code define.NamedCode, start, end time.Time)

func (*Event) GetType

func (e *Event) GetType() string

func (*Event) IgnoreCMDBLevel

func (e *Event) IgnoreCMDBLevel() bool

IgnoreCMDBLevel :

func (*Event) Success

func (e *Event) Success()

Success :

func (*Event) SuccessOrTimeout

func (e *Event) SuccessOrTimeout()

SuccessOrTimeout :

func (*Event) SuccessWithTime

func (e *Event) SuccessWithTime(start, end time.Time)

func (*Event) TaskDuration

func (e *Event) TaskDuration() time.Duration

TaskDuration :

type EventTask

type EventTask struct {
	BaseTask
	// contains filtered or unexported fields
}

EventTask 事件任务类型

func (*EventTask) CheckMode

func (t *EventTask) CheckMode() bool

CheckMode 检查是否为check模式

func (*EventTask) CheckRunning

func (t *EventTask) CheckRunning() bool

CheckRunning 检查是否正在运行,使用锁控制

func (*EventTask) ResetRunningState

func (t *EventTask) ResetRunningState()

ResetRunningState 重置running锁

type GatherUpEvent

type GatherUpEvent struct {
	DataID     int32
	Time       time.Time
	Metrics    common.MapStr
	Dimensions common.MapStr
}

func NewGatherUpEvent

func NewGatherUpEvent(task define.Task, upCode define.NamedCode) *GatherUpEvent

func NewGatherUpEventWithConfig

func NewGatherUpEventWithConfig(dataID int32, taskConfig define.TaskConfig, upCode define.NamedCode, customDims common.MapStr, value float64) *GatherUpEvent

func NewGatherUpEventWithDims

func NewGatherUpEventWithDims(task define.Task, upCode define.NamedCode, customDims common.MapStr) *GatherUpEvent

func NewGatherUpEventWithValue

func NewGatherUpEventWithValue(task define.Task, upCode define.NamedCode, value float64) *GatherUpEvent

func (*GatherUpEvent) AsMapStr

func (e *GatherUpEvent) AsMapStr() common.MapStr

func (*GatherUpEvent) GetType

func (e *GatherUpEvent) GetType() string

func (*GatherUpEvent) IgnoreCMDBLevel

func (e *GatherUpEvent) IgnoreCMDBLevel() bool

func (*GatherUpEvent) KVs

func (e *GatherUpEvent) KVs() []define.LogKV

type HostInfo

type HostInfo struct {
	Host  string
	Ips   []string
	Errno define.NamedCode
}

func GetHostsInfo

func GetHostsInfo(ctx context.Context, hosts []string, dnsMode configs.CheckMode, ipType configs.IPType, protocol configs.ProtocolType) []HostInfo

type MetricEvent

type MetricEvent struct {
	StatusEvent
	BizID  int32
	Labels []map[string]string
	Data   common.MapStr
}

MetricEvent :

func NewMetricEvent

func NewMetricEvent(task define.TaskConfig) *MetricEvent

NewMetricEvent :

func (*MetricEvent) AsMapStr

func (e *MetricEvent) AsMapStr() common.MapStr

AsMapStr :

func (*MetricEvent) GetType

func (e *MetricEvent) GetType() string

type NoopSemaphore

type NoopSemaphore struct{}

func (*NoopSemaphore) Acquire

func (ns *NoopSemaphore) Acquire(_ context.Context, _ int64) error

func (*NoopSemaphore) Release

func (ns *NoopSemaphore) Release(_ int64)

func (*NoopSemaphore) TryAcquire

func (ns *NoopSemaphore) TryAcquire(_ int64) bool

type PingEvent

type PingEvent struct {
	StandardEvent
}

PingEvent

func NewPingEvent

func NewPingEvent(task define.TaskConfig) *PingEvent

NewPingEvent

func (*PingEvent) AsMapStr

func (e *PingEvent) AsMapStr() common.MapStr

func (*PingEvent) GetType

func (e *PingEvent) GetType() string

func (*PingEvent) IgnoreCMDBLevel

func (e *PingEvent) IgnoreCMDBLevel() bool

IgnoreCMDBLevel

type PromEvent

type PromEvent struct {
	Key             string
	Value           float64
	Labels          common.MapStr
	AggValue        common.MapStr
	DimensionString string // ordered dimension string
	HashKey         string
	TS              int64
	Exemplar        *exemplar.Exemplar
}

PromEvent store the lines prometheus data

func NewPromEvent

func NewPromEvent(line string, ts int64, offsetTime time.Duration, handler TimestampHandler) (PromEvent, error)

NewPromEvent 优先使用 V2 作为解析方式 出错再回退到 V1 还出错的话就抛出异常

func NewPromEventFast

func NewPromEventFast(line string, ts int64, offsetTime time.Duration, handler TimestampHandler) (PromEvent, error)

NewPromEventFast 同 NewPromEvent 但不计算 PromEvent 哈希值

func (*PromEvent) GetAggValue

func (pe *PromEvent) GetAggValue() common.MapStr

GetAggValue get same timestamp and same dimension metrics

func (*PromEvent) GetLabels

func (pe *PromEvent) GetLabels() common.MapStr

GetLabels get dimensions

func (*PromEvent) GetTimestamp

func (pe *PromEvent) GetTimestamp() int64

GetTimestamp get the timestamp of the metric or local time

func (*PromEvent) ProduceHashKey

func (pe *PromEvent) ProduceHashKey()

ProduceHashKey the hash of dimension map string

type Semaphore

type Semaphore interface {
	Acquire(ctx context.Context, n int64) error
	TryAcquire(n int64) bool
	Release(n int64)
}

Semaphore 统一信号量接口

type SemaphorePool

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

func NewSemaphorePool

func NewSemaphorePool() *SemaphorePool

NewSemaphorePool 获取信号量池,同一池同key的信号量限制互通

func (*SemaphorePool) Delete

func (p *SemaphorePool) Delete(key string)

func (*SemaphorePool) GetSemaphore

func (p *SemaphorePool) GetSemaphore(key1 string, n1 int64, key2 string, n2 int64) Semaphore

GetSemaphore 获取信号量实例,weight以第一次配置为准,同pool所有实例同key共享信号量

type SimpleEvent

type SimpleEvent struct {
	*Event
	TargetHost string
	TargetPort int
	ResolvedIP string // DNS解析模式为全部时对应的实际请求IP,其他情况为空
}

SimpleEvent :

func NewSimpleEvent

func NewSimpleEvent(task define.Task) *SimpleEvent

NewSimpleEvent :

func (*SimpleEvent) AsMapStr

func (e *SimpleEvent) AsMapStr() common.MapStr

AsMapStr :

type StandardEvent

type StandardEvent struct {
	StatusEvent
	Labels     []map[string]string
	DataID     int32
	BizID      int32
	TaskID     int32
	Time       time.Time
	Metrics    map[string]interface{}
	Dimensions map[string]string
}

StandardEvent :

func NewStandardEvent

func NewStandardEvent(task define.TaskConfig) *StandardEvent

NewStandardEvent :

func (*StandardEvent) AsMapStr

func (e *StandardEvent) AsMapStr() common.MapStr

AsMapStr :

type StatusEvent

type StatusEvent struct {
	DataID         int32
	Status         int32
	NotUptimecheck int32
}

StatusEvent 状态参数

func NewStatusEvent

func NewStatusEvent() *StatusEvent

NewStatusEvent :

func (*StatusEvent) AsMapStr

func (e *StatusEvent) AsMapStr() common.MapStr

AsMapStr :

func (*StatusEvent) Fail

func (e *StatusEvent) Fail()

Fail :

func (*StatusEvent) GetType

func (e *StatusEvent) GetType() string

func (*StatusEvent) IgnoreCMDBLevel

func (e *StatusEvent) IgnoreCMDBLevel() bool

IgnoreCMDBLevel :

func (*StatusEvent) Success

func (e *StatusEvent) Success()

Success :

type TimestampHandler

type TimestampHandler func(nowTSMilli, timestamp int64, offsetTime time.Duration) int64

TimestampHandler 默认为ms,其他情况自行计算

func GetTimestampHandler

func GetTimestampHandler(timestampUnit string) (TimestampHandler, error)

GetTimestampHandler 获取时间戳处理工具

Directories

Path Synopsis
include
Package include imports all Module and MetricSet packages so that they register their factories with the global registry.
Package include imports all Module and MetricSet packages so that they register their factories with the global registry.

Jump to

Keyboard shortcuts

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