define

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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BeaterStatusUnknown     = -2
	BeaterStatusError       = -1
	BeaterStatusReady       = 0
	BeaterStatusRunning     = 1
	BeaterStatusTerminating = 2
	BeaterStatusTerminated  = 3

	// GatherStatus
	GatherStatusUnknown = -1
	GatherStatusOK      = 0
	GatherStatusError   = 1
)

BeaterStatus

View Source
const (
	NameGatherUp    = "bkm_gather_up"
	LabelUpCode     = "bkm_up_code"
	LabelUpCodeName = "bkm_up_code_name"

	NameMetricBeatUp             = "bkm_metricbeat_endpoint_up"
	NameMetricBeatScrapeDuration = "bkm_metricbeat_scrape_duration_seconds"
	NameMetricBeatScrapeSize     = "bkm_metricbeat_scrape_size_bytes"
	NameMetricBeatScrapeLine     = "bkm_metricbeat_scrape_line"
	NameMetricBeatHandleDuration = "bkm_metricbeat_handle_duration_seconds"

	NameKubeEventReceiveEvents = "bkm_kubeevent_receive_events"
	NameKubeEventReportEvents  = "bkm_kubeevent_report_events"
)
View Source
const (
	DefaultTimeout                         = 3 * time.Second  // 默认任务超时
	DefaultPeriod                          = 10 * time.Second // 默认任务执行间隔
	DefaultTaskConcurrencyLimitPerInstance = 100000           // 默认任务单实例并发限制
	DefaultTaskConcurrencyLimitPerTask     = 1000             // 默认单个任务并发限制
)
View Source
const (
	ModuleGlobalHeartBeat = "global_heartbeat"
	ModuleChildHeartBeat  = "child_heartbeat"
	ModuleStatus          = "status"
	ModuleStatic          = "static"
	ModuleHTTP            = "http"
	ModuleMetricbeat      = "metricbeat"
	ModulePing            = "ping"
	ModuleScript          = "script"
	ModuleTCP             = "tcp"
	ModuleUDP             = "udp"
	ModuleKeyword         = "keyword"
	ModuleTrap            = "snmptrap"
	ModuleBasereport      = "basereport"
	ModuleExceptionbeat   = "exceptionbeat"
	ModuleKubeevent       = "kubeevent"
	ModuleProcessbeat     = "processbeat"
	ModuleProcConf        = "procconf"
	ModuleProcCustom      = "proccustom"
	ModuleProcSync        = "procsync"
	ModuleProcStatus      = "procstatus"
	ModuleProcBin         = "procbin"
	ModuleLoginLog        = "loginlog"
	ModuleProcSnapshot    = "procsnapshot"
	ModuleSocketSnapshot  = "socketsnapshot"
	ModuleShellHistory    = "shellhistory"
	ModuleRpmPackage      = "rpmpackage"
)

所有模块的module名引用

View Source
const (
	UTCTimeFormat = "2006-01-02 15:04:05"
)

Variables

View Source
var (
	CodeOK       = newNamedCode(0, "Ok")
	CodeUnknown  = newNamedCode(1, "Unknown")
	CodeCanceled = newNamedCode(2, "Canceled")
	CodeTimeout  = newNamedCode(3, "Timeout")

	CodeWriteTempFileFailed = newNamedCode(1501, "WriteTempFileFailed")
	CodeConnTimeout         = newNamedCode(1001, "ConnTimeout")
	CodeConnFailed          = newNamedCode(1000, "ConnFailed")
	CodeConnRefused         = newNamedCode(2501, "ConnRefused")
	CodeInvalidPromFormat   = newNamedCode(2502, "InvalidPromFormat")
	CodeScriptRunFailed     = newNamedCode(2301, "ScriptRunFailed")
	CodeScriptNoOutput      = newNamedCode(2303, "ScriptNoOutput")
	CodeScriptTimeout       = newNamedCode(2304, "ScriptRunTimeout")
	CodeRequestFailed       = newNamedCode(1100, "RequestFailed")
	CodeRequestTimeout      = newNamedCode(1101, "RequestTimeout")
	CodeResponseFailed      = newNamedCode(1200, "ResponseFailed")
	CodeResponseNotMatch    = newNamedCode(1202, "ResponseNotMatch")
	CodeIPNotFound          = newNamedCode(1211, "IPNotFound")
	CodeInvalidURL          = newNamedCode(1213, "InvalidURL")
	CodeDNSResolveFailed    = newNamedCode(1004, "DNSResolveFailed")
	CodeInvalidIP           = newNamedCode(2102, "InvalidIP")
	CodeBadRequestParams    = newNamedCode(1103, "BadRequestParams")
)
View Source
var (
	ErrNotConfigured   = errors.New("get not configured error")
	ErrTaskNotFound    = errors.New("task not found")
	ErrType            = errors.New("type error")
	ErrTypeConvert     = errors.New("get error when try to convert type")
	ErrWrongTargetType = errors.New("wrong target type") // 目标类型不是ip也不是domain
	ErrNoChildPath     = errors.New("bkmonitorbeat.include not configured")
	ErrGetChildTasks   = errors.New("get child tasks error")
	ErrUnpackCfg       = errors.New("unpack cfg error")
	ErrCleanGlobalFail = errors.New("clean global config failed")
	ErrGetTaskFailed   = errors.New("get task item by filename failed")
	ErrNoName          = errors.New("task name not found")
	ErrNoVersion       = errors.New("task version not found")
	ErrorNoTask        = errors.New("no task found")
	ErrNoScriptOutput  = errors.New("script no output")
)
View Source
var ErrCodeMap = map[error]int{
	ErrNotConfigured:   100,
	ErrTaskNotFound:    103,
	ErrType:            106,
	ErrNoChildPath:     111,
	ErrGetChildTasks:   112,
	ErrUnpackCfg:       113,
	ErrCleanGlobalFail: 114,
	ErrGetTaskFailed:   121,
	ErrNoName:          122,
	ErrNoVersion:       123,
	ErrTypeConvert:     131,
	ErrWrongTargetType: 138,
}
View Source
var GlobalPidStore = newPidStore()

GlobalPidStore 全局pid信息

View Source
var GlobalWatcher host.Watcher

Functions

func GetErrorCodeByError

func GetErrorCodeByError(err error) int

GetErrorCodeByError 通过错误信息获取错误代码

func RecordLog

func RecordLog(template string, kvs []LogKV)

func RecordLogf

func RecordLogf(template string, args ...interface{})

func SetLogConfig

func SetLogConfig(c LogConfig)

Types

type Beater

type Beater interface {
	Run() error
	Stop()
	Reload(*common.Config)
	GetEventChan() chan Event
	GetConfig() Config
	GetScheduler() Scheduler
}

Beater : Beater

type CPUStat

type CPUStat struct {
	Ts            time.Time
	StartTime     uint64
	User          uint64
	Sys           uint64
	Total         uint64
	Percent       float64
	NormalPercent float64
}

type CompareFlag

type CompareFlag int

CompareFlag 比较结果标志位

var (
	Upper CompareFlag = 1
	Lower CompareFlag = 2
	Equal CompareFlag = 3
)

标志位枚举

type CompositeConfig

type CompositeConfig interface {
	CleanConfig() error
}

CompositeConfig :

type CompositeParam

type CompositeParam interface {
	CleanParams() error
}

CompositeParam :

type Config

type Config interface {
	GetTaskConfigListByType(string) []TaskConfig
	GetGatherUpDataID() int32
	Clean() error
}

Config : task config

type ConfigEngine

type ConfigEngine interface {
	Init(cfg *common.Config, bt Beater) error
	ReInit(cfg *common.Config) error
	GetTaskConfigList() []TaskConfig
	GetTaskNum() int
	GetWrongTaskNum() int
	CleanTaskConfigList() error
	RefreshHeartBeat() error
	SendHeartBeat() error
	GetGlobalConfig() Config
	HasChildPath() bool
}

ConfigEngine 配置引擎的接口

type Event

type Event interface {
	AsMapStr() common.MapStr
	IgnoreCMDBLevel() bool
	GetType() string
}

Event :

type FdStat

type FdStat struct {
	Open      uint64
	SoftLimit uint64
	HardLimit uint64
}

type IOStat

type IOStat struct {
	Ts         time.Time
	ReadBytes  uint64
	WriteBytes uint64
	ReadSpeed  float64
	WriteSpeed float64
}

type LogConfig

type LogConfig struct {
	Stdout  bool   `config:"stdout"`
	Level   string `config:"level"`
	Path    string `config:"path"`
	MaxSize int    `config:"maxsize"`
	MaxAge  int    `config:"maxage"`
	Backups int    `config:"backups"`
}

type LogKV

type LogKV struct {
	K string
	V interface{}
}

func (LogKV) String

func (kv LogKV) String() string

type MemStat

type MemStat struct {
	Size     uint64
	Resident uint64
	Share    uint64
	Percent  float64
}

type MetricsReaderFunc

type MetricsReaderFunc func() (<-chan common.MapStr, error)

func (MetricsReaderFunc) MarshalJSON

func (m MetricsReaderFunc) MarshalJSON() ([]byte, error)

type NamedCode

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

func (NamedCode) Code

func (nc NamedCode) Code() int

func (NamedCode) Name

func (nc NamedCode) Name() string

type ProcStat

type ProcStat struct {
	Pid      int32
	PPid     int32
	Name     string
	Cwd      string
	Exe      string
	Cmd      string
	CmdSlice []string
	Status   string
	Username string
	Created  int64
	Mem      *MemStat
	CPU      *CPUStat
	IO       *IOStat
	Fd       *FdStat
}

type Scheduler

type Scheduler interface {
	Add(Task)
	Start(context.Context) error
	IsDaemon() bool
	Count() int
	Stop()
	Wait()
	GetStatus() Status
	Reload(context.Context, Config, []Task) error
}

Scheduler : scheduler to run task

type Status

type Status int

Status :

const (
	SchedulerReady Status = iota
	SchedulerRunning
	SchedulerError
	SchedulerTerminting
	SchedulerFinished
)

scheduler status

const (
	TaskReady    Status = iota
	TaskRunning  Status = iota
	TaskError    Status = iota
	TaskFinished Status = iota
)

task status

type Tag

type Tag struct {
	Key   string
	Value string
}

Tag 从Labels里面获取到的传输tag键值对

type Tags

type Tags []Tag

Tags 全部Tag集合,实现了sort.Interface接口,可排序

func (Tags) CompareString

func (t Tags) CompareString(a, b string) CompareFlag

CompareString 比较两个字符串大小 1.大于 2.小于 3.等于

func (Tags) Len

func (t Tags) Len() int

func (Tags) Less

func (t Tags) Less(i, j int) bool

Less key字符串长度长的排前面,长度相同则比较byte数组

func (Tags) Swap

func (t Tags) Swap(i, j int)

type Task

type Task interface {
	GetTaskID() int32
	GetStatus() Status
	SetConfig(TaskConfig)
	GetConfig() TaskConfig
	SetGlobalConfig(Config)
	GetGlobalConfig() Config
	Reload()
	Wait()
	Stop()
	Run(ctx context.Context, e chan<- Event)
}

Task : task for scheduler

type TaskConfig

type TaskConfig interface {
	GetBizID() int32
	GetIdent() string
	InitIdent() error
	SetIdent(ident string)
	GetTimeout() time.Duration
	GetAvailableDuration() time.Duration
	GetDataID() int32
	GetTaskID() int32
	GetPeriod() time.Duration
	GetType() string
	GetLabels() []map[string]string
	Clean() error
}

TaskConfig : task config

type TaskMetaConfig

type TaskMetaConfig interface {
	GetTaskConfigList() []TaskConfig
	Clean() error
}

TaskMetaConfig : task config

Jump to

Keyboard shortcuts

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