types

package
v5.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACTION_ALARM = iota
	ACTION_RESTORE
)
View Source
const (
	ACTION_NOTIFY = iota + 1
	ACTION_RUN
)
View Source
const (
	ALAR_MESS_INSPECTOR_HEARTBEAT tcp.PacketType = iota + 1
	ALAR_MESS_INSPECTOR_TASK_REQUEST
	ALAR_MESS_INSPECTOR_TASKS
	ALAR_MESS_INSPECTOR_RESULT
)

报警服务消息类型定义

View Source
const (
	EVENT_NEW = iota + 1
	EVENT_AWARE
	EVENT_CLOSED
	EVENT_NODATA
	EVENT_UNKNOW
)
View Source
const (
	// Agent
	MsgAgentRegister tcp.PacketType = iota
	MsgAgentSendMetricInfo
	MsgAgentSendTimeSeriesData
	MsgAgentGetPluginsList
	MsgAgentRequestSyncPlugins
	MsgAgentSendHeartbeat

	// CFC
	MsgCFCSendPluginsList
	MsgCFCSendPlugin
	MsgCFCSendReconnect

	// Repeater
	MsgRepeaterPostTimeSeriesData
)
View Source
const (
	PRIORITY_HIGH_LEVEL = iota + 1
	PRIORITY_MIDDLE_LEVEL
	PRIORITY_LOW_LEVEL
)
View Source
const (
	H3C_CPU_OID    = ".1.3.6.1.4.1.25506.2.6.1.1.1.1.6"
	H3C_MEM_OID    = ".1.3.6.1.4.1.25506.2.6.1.1.1.1.8"
	CISCO_CPU_OID  = ".1.3.6.1.4.1.9.9.109.1.1.1.1.7"
	CISCO_MEM_OID  = ".1.3.6.1.4.1.9.9.109.1.1.1.1.12"
	HUAWEI_MEM_OID = ".1.3.6.1.4.1.2011.5.25.31.1.1.1.1.7"
	HUAWEI_CPU_OID = ".1.3.6.1.4.1.2011.5.25.31.1.1.1.1.5"
)
View Source
const (
	USER = iota
	ADMIN
)

Variables

View Source
var (
	ErrPluginPathIsBlank    = errors.New("plugin path is blank")
	ErrPluginIntervalIsZero = errors.New("plugin interval is zore")
)
View Source
var AlarmMessageTypeText map[tcp.PacketType]string = map[tcp.PacketType]string{
	ALAR_MESS_INSPECTOR_HEARTBEAT:    "inspector heartbeat",
	ALAR_MESS_INSPECTOR_TASK_REQUEST: "inspector task request",
	ALAR_MESS_INSPECTOR_TASKS:        "inspector tasks",
	ALAR_MESS_INSPECTOR_RESULT:       "inspector result",
}

报警服务消息类型可读映射

View Source
var DEFAULT_TIME, _ = time.Parse(time.RFC3339, "1980-01-01T00:00:00+00:00")
View Source
var MsgTextMap map[tcp.PacketType]string = map[tcp.PacketType]string{
	MsgAgentRegister:              "MsgAgentRegister",
	MsgAgentSendMetricInfo:        "MsgAgentSendMetricInfo",
	MsgAgentSendTimeSeriesData:    "MsgAgentSendTimeSeriesData",
	MsgAgentGetPluginsList:        "MsgAgentGetPluginList",
	MsgAgentRequestSyncPlugins:    "MsgAgentRequestSyncPlugins",
	MsgAgentSendHeartbeat:         "MsgAgentSendHeartbeat",
	MsgCFCSendPluginsList:         "MsgCFCSendPluginsList",
	MsgCFCSendPlugin:              "MsgCFCSendPlugin",
	MsgCFCSendReconnect:           "MsgCFCSendReconnect",
	MsgRepeaterPostTimeSeriesData: "MsgRepeaterPostTimeSeriesData",
}

Functions

func ParseTags

func ParseTags(name string) map[string]string

tag1=v1,tag2=v2,tag3=v3 {"tag1":v1,"tag2":v2,"tag3":v3}

Types

type Action

type Action struct {
	ID              int    `json:"-"`
	StrategyID      int    `json:"strategy_id" db:"strategy_id"`
	Type            int    `json:"type"`
	Kind            int    `json:"kind"`
	ScriptID        int    `json:"script_id" db:"script_id"`
	FilePath        string `json:"file_path" db:"file_path"`
	AlarmSubject    string `json:"alarm_subject" db:"alarm_subject"`
	AlarmTemplate   string `json:"alarm_template" db:"alarm_template"`
	RestoreSubject  string `json:"restore_subject" db:"restore_subject"`
	RestoreTemplate string `json:"restore_template" db:"restore_template"`
	BeginTime       string `json:"begin_time" db:"begin_time"`
	EndTime         string `json:"end_time" db:"end_time"`
	TimePeriod      int    `json:"time_period" db:"time_period"`
}

type ActionResult

type ActionResult struct {
	StrategyEventID int64  `json:"strategy_event_id"`
	Count           int    `json:"count"`
	ActionID        int    `json:"action_id"`
	ActionType      int    `json:"action_type"`
	ActionKind      int    `json:"action_kind"`
	ScriptID        int    `json:"script_id"`
	UserID          int    `json:"user_id"`
	Username        string `json:"username"`
	Phone           string `json:"phone"`
	Mail            string `json:"mail"`
	Weixin          string `json:"weixin"`
	Subject         string `json:"subject"`
	Content         string `json:"content"`
	Success         bool   `json:"success"`
	Response        string `json:"response"`
	FilePath        string `json:"file_path"`
}

func NewActionResult

func NewActionResult(
	strategy_event_id int64,
	count, action_id, action_type, action_kind, script_id, user_id int,
	user_name, phone, mail, weixin, subject, content, response string,
	success bool) *ActionResult

type AgentPostMetricRequest

type AgentPostMetricRequest struct {
	HostID  string           `json:"host_id"`
	Metrics []TimeSeriesData `json:"metrics"` // cpu.idle/ip=10.10.32.10,cpu=1
}

func (*AgentPostMetricRequest) Encode

func (this *AgentPostMetricRequest) Encode() []byte

type AlarmMessage

type AlarmMessage interface {
	Encode() []byte
}

报警服务消息接口

type AlarmResults

type AlarmResults struct {
	Results []*StrategyResult
}

type AlarmTask

type AlarmTask struct {
	ID       string
	Host     *Host `json:"-"`
	Strategy *Strategy
	Triggers map[string]*Trigger
}

func NewAlarmTask

func NewAlarmTask(host *Host, strategy *Strategy, triggers map[string]*Trigger) *AlarmTask

type AlarmTasks

type AlarmTasks struct {
	Tasks []*AlarmTask
}

func (*AlarmTasks) Decode

func (this *AlarmTasks) Decode(data []byte) error

func (*AlarmTasks) Encode

func (this *AlarmTasks) Encode() []byte

type Chart

type Chart struct {
	ID         int       `json:"id"`
	Name       string    `json:"name"`
	UserID     int       `json:"-"`
	Size       int       `json:"size"`
	ReferCount int       `json:"refer_count"`
	Thumbnail  string    `json:"thumbnail"`
	CreateAt   time.Time `json:"create_at"`
	UpdateAt   time.Time `json:"update_at"`

	Elements []*ChartElement `json:"elements"`
}

func (Chart) TableName

func (Chart) TableName() string

type ChartElement

type ChartElement struct {
	ID      int    `json:"id"`
	ChartID int    `json:"-"`
	Name    string `json:"name"`
	Metric  string `json:"metric"`
	Tags    string `json:"tags"`
}

func (ChartElement) TableName

func (ChartElement) TableName() string

type Client

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

func NewTsdbClient

func NewTsdbClient(addr string, timeout time.Duration) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Query

func (c *Client) Query(q *QueryParams) ([]Result, error)

type Counter

type Counter struct {
	Last, Prev uint64
}

type ErrorResp

type ErrorResp struct {
	Error InnerError `json:"error"`
}

func (ErrorResp) String

func (this ErrorResp) String() string

type GetPluginResp

type GetPluginResp struct {
	HostID  string   `json:"host_id"` // 当agent通过proxy连接,需要通过hostid来查找映射表
	Plugins []Plugin `json:"plugins"`
}

func (*GetPluginResp) Decode

func (this *GetPluginResp) Decode(data []byte) error

func (*GetPluginResp) Encode

func (this *GetPluginResp) Encode() []byte

type Group

type Group struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

func (Group) TableName

func (Group) TableName() string

type HeartBeat

type HeartBeat struct {
	IP       string `json:"ip"`
	Hostname string `json:"hostname"`
}

func NewHeartBeat

func NewHeartBeat(ip, hostname string) *HeartBeat

func (*HeartBeat) Decode

func (this *HeartBeat) Decode(data []byte) error

func (*HeartBeat) Encode

func (this *HeartBeat) Encode() []byte

type Host

type Host struct {
	ID           string    `json:"id"`
	IP           string    `json:"ip"`
	Hostname     string    `json:"hostname"`
	AgentVersion string    `json:"agent_version" db:"agent_version"`
	Status       string    `json:"status"`
	CreateAt     time.Time `json:"create_at" db:"create_at"`
	UpdateAt     time.Time `json:"update_at" db:"update_at"`
	Uptime       float64   `json:"uptime" db:"uptime"`
	IdlePct      float64   `json:"idle_pct" db:"idle_pct"`
	MuteTime     time.Time `json:"-" db:"mute_time"`
}

func (*Host) Decode

func (this *Host) Decode(data []byte) error

func (*Host) Encode

func (this *Host) Encode() []byte

func (*Host) IsAlive

func (this *Host) IsAlive() bool

func (*Host) IsMute

func (this *Host) IsMute() bool

type InnerError

type InnerError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Details string `json:"details"`
}

type Interface

type Interface struct {
	Index       string  `json:"index"`
	Name        string  `json:"name"`
	OperStatus  uint64  `json:"oper_starus"`
	InBytes     Counter `json:"in_bytes"`
	OutBytes    Counter `json:"out_bytes"`
	InDiscards  Counter `json:"in_discards"`
	OutDiscards Counter `json:"out_discards"`
	InErrors    Counter `json:"in_errors"`
	OutErrors   Counter `json:"out_errors"`
	Speed       uint64  `json:"speed"`
}

type MessageType

type MessageType byte
const (
	MESS_POST_HOST_CONFIG MessageType = iota
	MESS_POST_METRIC
	MESS_POST_TSD
	MESS_GET_HOST_PLUGIN_LIST
	MESS_GET_HOST_PLUGIN_LIST_RESP
	MESS_GET_ALL_PLUGIN_MD5
	MESS_GET_ALL_PLUGIN_MD5_RESP
	MESS_PULL_PLUGIN
	MESS_POST_HOST_ALIVE
)

消息类型定义

type MetricConfig

type MetricConfig struct {
	HostID     string         `json:"host_id"`
	SeriesData TimeSeriesData `json:"time_series_data"`
}

func (*MetricConfig) Decode

func (tsd *MetricConfig) Decode(data []byte) error

func (*MetricConfig) Encode

func (tsd *MetricConfig) Encode() []byte

type Node

type Node struct {
	IP       string    `json:"ip"`
	Hostname string    `json:"hostname"`
	Update   time.Time `json:"update"`
}

func (*Node) Encode

func (this *Node) Encode() []byte

func (Node) MarshalJSON

func (this Node) MarshalJSON() ([]byte, error)

type Options

type Options struct {
	Addr    string
	Timeout time.Duration
}

type Panel

type Panel struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	Thumbnail string    `json:"thumbnail"`
	UserID    int       `json:"-"`
	Favor     int       `json:"-"`
	CreateAt  time.Time `json:"create_at"`
	UpdateAt  time.Time `json:"update_at"`
	Charts    []*Chart  `json:"charts" gorm:"many2many:panel_chart"`
}

func (Panel) TableName

func (Panel) TableName() string

type Plugin

type Plugin struct {
	// plugin 在数据库中的id号
	ID int `json:"id"`
	// plugin 名称
	Name string `json:"name"`
	// plugin 在磁盘上的路径
	Path string `json:"path"`
	// 校验和,用于插件同步比对
	Checksum string `json:"checksum"`
	// 执行参数
	Args string `json:"args"`
	// 执行间隔
	Interval int `json:"interval"`
	// 执行超时时间
	Timeout int `json:"timeout"`
}

func (*Plugin) Decode

func (plugin *Plugin) Decode(data []byte) error

func (*Plugin) Encode

func (plugin *Plugin) Encode() []byte

func (*Plugin) Equal

func (plugin *Plugin) Equal(p Plugin) bool

func (Plugin) String

func (plugin Plugin) String() string

func (*Plugin) UniqueKey

func (plugin *Plugin) UniqueKey() string

func (*Plugin) Validate

func (plugin *Plugin) Validate() error

type Product

type Product struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type Query

type Query struct {
	Aggregator string            `json:"aggregator"`
	Metric     string            `json:"metric"`
	Rate       bool              `json:"rate,omitempty"`
	Tags       map[string]string `json:"tags,omitempty"`
}

type QueryParams

type QueryParams struct {
	Start             interface{} `json:"start"`
	End               interface{} `json:"end,omitempty"`
	Queries           []Query     `json:"queries,omitempty"`
	NoAnnotations     bool        `json:"no_annotations,omitempty"`
	GlobalAnnotations bool        `json:"global_annotations,omitempty"`
	MsResolution      bool        `json:"ms,omitempty"`
	ShowTSUIDs        bool        `json:"show_tsuids,omitempty"`
	ShowSummary       bool        `json:"show_summary,omitempty"`
	ShowQuery         bool        `json:"show_query,omitempty"`
	Delete            bool        `json:"delete,omitempty"`
}

func NewQueryParams

func NewQueryParams(start, end string, rawTags string, aggregator string, metric string) *QueryParams

type Result

type Result struct {
	Metric        string             `json:"metric"`
	Tags          map[string]string  `json:"tags"`
	AggregateTags []string           `json:"aggregateTags"`
	Dps           map[string]float64 `json:"dps"`
}

type Script

type Script struct {
	ID       int    `db:"id"`
	Name     string `db:"name"`
	FilePath string `db:"file_path"`
}

type SnmpConfig

type SnmpConfig struct {
	Port      int    `json:"port"`
	Version   string `json:"version"`
	Community string `json:"community"`
	Timeout   int    `json:"timeout"`
}

type Strategy

type Strategy struct {
	ID          int    `json:"id"`
	ProductID   int    `json:"product_id" db:"product_id"`
	Name        string `json:"name"`
	Priority    int    `json:"priority"`
	AlarmCount  int    `json:"alarm_count" db:"alarm_count"`
	Cycle       int    `json:"cycle" `
	Expression  string `json:"expression"`
	Description string `json:"description"`
	UserID      int    `json:"user_id" db:"user_id"`
	Enable      bool   `json:"enable"`
}

type StrategyEvent

type StrategyEvent struct {
	ID           int64     `json:"id" db:"id"`
	ProductID    int       `json:"product_id" db:"product_id"`
	StrategyID   int       `json:"strategy_id" db:"strategy_id"`
	StrategyName string    `json:"strategy_name" db:"strategy_name"`
	Priority     int       `json:"priority"`
	Cycle        int       `json:"cycle"`
	AlarmCount   int       `json:"alarm_count" db:"alarm_count"`
	Expression   string    `json:"expression"`
	CreateTime   time.Time `json:"create_time" db:"create_time"`
	UpdateTime   time.Time `json:"update_time" db:"update_time"`
	AwareEndTime time.Time `json:"aware_end_time" db:"aware_end_time"`
	Count        int       `json:"count"`
	Status       int       `json:"status"`
	HostID       string    `json:"host_id" db:"host_id"`
	HostName     string    `json:"host_name" db:"host_name"`
	IP           string    `json:"ip"`
	ErrorMessage string    `json:"error_message"`
}

func NewStrategyEvent

func NewStrategyEvent(
	product_id int,
	strategy_id int,
	strategy_name string,
	priority int,
	cycle int,
	alarm_count int,
	expression string,
	create_time time.Time,
	host_id string,
	host_name string,
	ip string,
	error_message string) *StrategyEvent

type StrategyResult

type StrategyResult struct {
	TaskID            string                       `json:"taskid"`
	Priority          int                          `json:"priority"`
	TriggerResultSets map[string]*TriggerResultSet `json:"trigger_resultset"`
	ErrorMessage      string                       `json:"error_message"`
	Triggered         bool                         `json:"triggered"`
	CreateTime        time.Time                    `json:"create_time"`
}

func NewStrategyResult

func NewStrategyResult(task_id string, priority int, trigger_results map[string]*TriggerResultSet, error_message string, triggered bool, create_time time.Time) *StrategyResult

func (*StrategyResult) Decode

func (this *StrategyResult) Decode(data []byte) error

func (*StrategyResult) Encode

func (this *StrategyResult) Encode() []byte

type Switch

type Switch struct {
	ID              string   `json:"id"`
	IP              string   `json:"ip"`
	Hostname        string   `json:"hostname"`
	Vendor          string   `json:"vendor"`
	AgentVersion    string   `json:"agent_version"`
	CollectInterval int      `json:"collect_interval"`
	LegalPrefix     []string `json:"legal_prefix"`

	//采集数据成功更新
	LastUpdate time.Time             `json:"last_update"`
	Snmp       SnmpConfig            `json:"snmp"`
	Interfaces map[string]*Interface `json:"interfaces"`
	Cpu        map[string]uint64
	Mem        map[string]uint64
}

func (*Switch) BuildInterfaceIndex

func (this *Switch) BuildInterfaceIndex() error

func (*Switch) CollectIfaceSpeed

func (this *Switch) CollectIfaceSpeed() error

func (*Switch) CollectInterfaceName

func (this *Switch) CollectInterfaceName() error

func (*Switch) CollectPerformanceData

func (this *Switch) CollectPerformanceData(oid string)

func (*Switch) CollectTraffic

func (this *Switch) CollectTraffic()

func (*Switch) Do

func (this *Switch) Do(buf1 chan<- *TimeSeriesData, buf2 chan<- *MetricConfig)

func (*Switch) IsLegalPrefix

func (this *Switch) IsLegalPrefix(name string) bool

type SyncPluginRequest

type SyncPluginRequest struct {
	HostID string
	Plugin
}

func (*SyncPluginRequest) Decode

func (spr *SyncPluginRequest) Decode(data []byte) error

func (*SyncPluginRequest) Encode

func (spr *SyncPluginRequest) Encode() []byte

type SyncPluginResponse

type SyncPluginResponse struct {
	HostID string
	Path   string
	Body   []byte
}

func (*SyncPluginResponse) Decode

func (sp *SyncPluginResponse) Decode(data []byte) error

func (*SyncPluginResponse) Encode

func (sp *SyncPluginResponse) Encode() []byte

type TimeSeriesData

type TimeSeriesData struct {
	Metric    string            `json:"metric"`    //sys.cpu.idle
	DataType  string            `json:"data_type"` //COUNTER,GAUGE,DERIVE
	Value     float64           `json:"value"`     //99.00
	Timestamp int64             `json:"timestamp"` //unix timestamp
	Cycle     int               `json:"cycle,omitempty"`
	Tags      map[string]string `json:"tags"` //{"product":"app01", "group":"dev02"}
}

func (*TimeSeriesData) AddTags

func (tsd *TimeSeriesData) AddTags(tags map[string]string)

func (*TimeSeriesData) Decode

func (tsd *TimeSeriesData) Decode(data []byte) error

func (*TimeSeriesData) Encode

func (tsd *TimeSeriesData) Encode() []byte

func (*TimeSeriesData) GetMetric

func (tsd *TimeSeriesData) GetMetric() string

func (*TimeSeriesData) PK

func (tsd *TimeSeriesData) PK() string

func (*TimeSeriesData) RemoveTag

func (tsd *TimeSeriesData) RemoveTag(tagk string)

func (TimeSeriesData) String

func (tsd TimeSeriesData) String() string

func (*TimeSeriesData) Tags2String

func (tsd *TimeSeriesData) Tags2String() string

func (*TimeSeriesData) Validate

func (m *TimeSeriesData) Validate() bool

type TimeSeriesDataStore

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

func NewTimeSeriesDataStore

func NewTimeSeriesDataStore() *TimeSeriesDataStore

func (*TimeSeriesDataStore) Add

func (*TimeSeriesDataStore) Get

func (ts *TimeSeriesDataStore) Get(pk string) (tsd TimeSeriesData, exist bool)

func (*TimeSeriesDataStore) GetAll

func (ts *TimeSeriesDataStore) GetAll() []TimeSeriesData

func (*TimeSeriesDataStore) Remove

func (ts *TimeSeriesDataStore) Remove(pk string)

type TimeSeriesDataV4

type TimeSeriesDataV4 struct {
	PerformanceIndex map[string]float64 `json:"performance_index"`
	Host             string             `json:"host"`
	AppName          string             `json:"app_name"`
	Domain           string             `json:"domain"`
}

func (*TimeSeriesDataV4) ToV5

func (tsdv4 *TimeSeriesDataV4) ToV5() []*TimeSeriesData

type Trigger

type Trigger struct {
	ID          int64   `form:"id" json:"-" `
	StrategyID  int     `form:"strategy_id" json:"strategy_id"`
	Metric      string  `form:"metric" json:"metric"`
	Tags        string  `form:"tags" json:"tags"`
	Number      int     `form:"number" json:"number"`
	Index       string  `form:"index" json:"index"`
	Method      string  `form:"method" json:"method" `
	Symbol      string  `form:"symbol" json:"symbol" `
	Threshold   float64 `form:"threshold" json:"threshold" `
	Description string  `form:"description" json:"description"`
}

func (Trigger) TableName

func (Trigger) TableName() string

type TriggerEvent

type TriggerEvent struct {
	StrategyEventID  int64   `json:"strategy_event_id" db:"strategy_event_id"`
	Index            string  `json:"index" db:"index"`
	Metric           string  `json:"metric" db:"metric"`
	Tags             string  `json:"tags"`
	Number           int     `json:"number"`
	AggregateTags    string  `json:"aggregate_tags" db:"aggregate_tags"`
	CurrentThreshold float64 `json:"current_threshold" db:"current_threshold"`
	Method           string  `json:"method"`
	Symbol           string  `json:"symbol"`
	Threshold        float64 `json:"threshold"`
	Triggered        bool    `json:"triggered"`
	TriggerChanged   bool    `json:"-"`
}

func NewTriggerEvent

func NewTriggerEvent(strategy_event_id int64, index, metric, tags, aggregate_tags, symbol, method string, number int, threshold, current_threshold float64, triggered bool) *TriggerEvent

func (*TriggerEvent) String

func (this *TriggerEvent) String() string

type TriggerResult

type TriggerResult struct {
	Index            string
	Tags             string
	AggregateTags    string
	CurrentThreshold float64
	Triggered        bool
}

func NewTriggerResult

func NewTriggerResult(index string, tags map[string]string, aggregate_tags []string, current_threshold float64, triggered bool) *TriggerResult

type TriggerResultSet

type TriggerResultSet struct {
	TriggerResults []*TriggerResult
	Triggered      bool
}

type User

type User struct {
	ID       int    `json:"id"`
	Username string `json:"username"`
	Password string `json:"-"`
	Role     int    `json:"role"`
	Phone    string `json:"phone"`
	Mail     string `json:"mail"`
	Wechat   string `json:"wechat"`
	Status   int    `json:"status"`
}

func (*User) IsAdmin

func (this *User) IsAdmin() bool

type UserGroup

type UserGroup struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Jump to

Keyboard shortcuts

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