model

package
v0.0.0-...-d989b54 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const (
	EventError = iota - 2
	EventNone

	EventSync
	EventNodeConfChanged
	EventNodeRegister
	EventNodeStatus
	EventNodeProc
	EventNodeExit
	EventCmdStart
	EventCmdStop
	EventCmdRestart

	EventOperate
	EventOperateBatch
	EventOperateRollback
)

EventType

View Source
const (
	PkgPrefix     string     = "github.com/huajiao-tv/gokeeper/model."
	StatusStop    NodeStatus = 0
	StatusRunning NodeStatus = 1
)

Variables

This section is empty.

Functions

func EncodeConfData

func EncodeConfData(cd ConfData) (string, error)

func FormatEvent

func FormatEvent(modelEvent *Event) (*pb.ConfigEvent, error)

将model格式的event转化为pb格式的event

func GetRawKey

func GetRawKey(key, typ string) string

func GetStructName

func GetStructName(fname string) string

func ToCamlCase

func ToCamlCase(key string) string

ToCamlCase convert snake_case to CamlCase

func ToUpperFirst

func ToUpperFirst(s string) string

ToUpperFirst return first letter to upper

Types

type ConfData

type ConfData struct {
	Type      string      `json:"type"`
	RawKey    string      `json:"raw_key"`
	RawValue  string      `json:"raw_value"`
	Key       string      `json:"key"`
	Value     interface{} `json:"value"`
	StructKey string      `json:"struct_key"`
	IsJson    bool        `json:"is_json"`
}

func DecodeConfData

func DecodeConfData(s string) (*ConfData, error)

func NewConfData

func NewConfData(rawKey, rawValue string) (*ConfData, error)

type Event

type Event struct {
	EventType int
	Data      interface{}
}

Event .

func NewEvent

func NewEvent() Event

NewEvent return EventTypeNone event

func ParseEvent

func ParseEvent(pbEvent *pb.ConfigEvent) (*Event, error)

将pb格式的event转化为model格式的event

type MachineCpu

type MachineCpu struct {
	User        uint64
	Nice        uint64
	System      uint64
	Idle        uint64
	Iowait      uint64
	Irq         uint64
	SoftIrq     uint64
	Stealstolen uint64
	Guest       uint64
	Uptime      uint64
}

func (*MachineCpu) ReSet

func (this *MachineCpu) ReSet()

func (*MachineCpu) Refresh

func (this *MachineCpu) Refresh() error

type MachineInfo

type MachineInfo struct {
	Uptime float64
	Hertz  int
	Host   string
	Cpu    *MachineCpu
}

func NewMachineInfo

func NewMachineInfo() *MachineInfo

*

  • 获取Hertz值:C.sysconf(C._SC_CLK_TCK),sysconf具体实现参见glibc源码:
  • x86_64平台:glibc/sysdeps/posix/sysconf.c
  • glibc/sysdeps/unix/sysv/linux/getclktck.c

func (*MachineInfo) GetUptime

func (this *MachineInfo) GetUptime() float64

type Node

type Node struct {
	*NodeInfo
	Subscription []string     `json:"subscription"`
	StructDatas  []StructData `json:"struct_datas"`
	Proc         *ProcInfo    `json:"proc"`

	Event chan Event `json:"-"`
}

Node stores the information about a node

func NewNode

func NewNode(nodeInfo NodeInfo) *Node

func (*Node) AddEvent

func (n *Node) AddEvent(evt Event) error

func (*Node) Exit

func (n *Node) Exit()

func (*Node) GetProc

func (n *Node) GetProc() *ProcInfo

func (*Node) GetStructDatas

func (n *Node) GetStructDatas() []StructData

func (*Node) GetSubscription

func (n *Node) GetSubscription() []string

func (*Node) Info

func (n *Node) Info() NodeInfo

func (*Node) SetProc

func (n *Node) SetProc(proc *ProcInfo)

func (*Node) SetStructDatas

func (n *Node) SetStructDatas(structDatas []StructData, version int)

func (*Node) SetSubscription

func (n *Node) SetSubscription(subscription []string)

type NodeInfo

type NodeInfo struct {
	ID              string     `json:"id"`
	KeeperAddr      string     `json:"keeper_addr"`
	Domain          string     `json:"domain"`
	Component       string     `json:"component"`
	Hostname        string     `json:"hostname"`
	StartTime       int64      `json:"start_time"`
	UpdateTime      int64      `json:"update_time"`
	RawSubscription []string   `json:"raw_subscription"`
	Status          NodeStatus `json:"status"`
	Version         int        `json:"version"`

	ComponentTags map[string]string `json:"component_tags"`
	// contains filtered or unexported fields
}

func NewNodeInfo

func NewNodeInfo(ID, hostname, keeperAddr, domain, component string, rawSubscription []string, tag map[string]string) *NodeInfo

func (*NodeInfo) GetComponent

func (n *NodeInfo) GetComponent() string

func (*NodeInfo) GetDomain

func (n *NodeInfo) GetDomain() string

func (*NodeInfo) GetID

func (n *NodeInfo) GetID() string

func (*NodeInfo) GetKeeperAddr

func (n *NodeInfo) GetKeeperAddr() string

func (*NodeInfo) GetRawSubscription

func (n *NodeInfo) GetRawSubscription() []string

func (*NodeInfo) GetUpdateTime

func (n *NodeInfo) GetUpdateTime() int64

func (*NodeInfo) GetVersion

func (n *NodeInfo) GetVersion() int

func (*NodeInfo) SetComponentTag

func (n *NodeInfo) SetComponentTag(tag map[string]string)

func (*NodeInfo) SetRawSubscription

func (n *NodeInfo) SetRawSubscription(rawSubscription []string)

func (*NodeInfo) SetStartTime

func (n *NodeInfo) SetStartTime(t int64)

func (*NodeInfo) SetStatus

func (n *NodeInfo) SetStatus(status NodeStatus)

func (*NodeInfo) SetUpdateTime

func (n *NodeInfo) SetUpdateTime(t int64)

func (*NodeInfo) SetVersion

func (n *NodeInfo) SetVersion(version int)

type NodeStatus

type NodeStatus int

type ObjContainer

type ObjContainer interface {
	Update(name string, st interface{}) error
	GetStructs() map[string]interface{}
}

ObjContainer is function to update data

type Opcode

type Opcode string
const (
	OpcodeGet    Opcode = "get"
	OpcodeAdd    Opcode = "add"
	OpcodeUpdate Opcode = "update"
	OpcodeDelete Opcode = "delete"

	DefaultSection = "DEFAULT"
	PathSeparator  = string(os.PathSeparator)
)

type Operate

type Operate struct {
	Opcode  Opcode
	Domain  string
	File    string
	Section string
	Key     string
	Type    string
	Value   string
	Note    string
	ID      int
	Version int64 //@todo 后台传递回滚版本号
}

func (*Operate) Format

func (op *Operate) Format()

type ProcBase

type ProcBase struct {
	Pid       string
	PPid      string
	Command   string
	State     string
	StartTime string
}

func (*ProcBase) GetCommand

func (this *ProcBase) GetCommand() string

func (*ProcBase) GetProcInfo

func (this *ProcBase) GetProcInfo() error

type ProcCpu

type ProcCpu struct {
	Utime     uint64
	Stime     uint64
	Cutime    uint64
	Cstime    uint64
	StartTime uint64
	LastUS    uint64    //Utime+Stime
	LastTimer time.Time //time.Now()
	CpuUsage  string
	ProcBase
}

func (*ProcCpu) CurrentUsage

func (this *ProcCpu) CurrentUsage() float64

*

  • 采样时间段内的cpu使用率,算法与top命令一致。
  • top计算进程cpu使用率源码参见:procs的top.c:prochlp()

func (*ProcCpu) ReSet

func (this *ProcCpu) ReSet()

func (*ProcCpu) Refresh

func (this *ProcCpu) Refresh() error

func (*ProcCpu) String

func (this *ProcCpu) String() string

type ProcInfo

type ProcInfo struct {
	Base *ProcBase
	Cpu  *ProcCpu
	Mem  *ProcMem
}

func NewProcInfo

func NewProcInfo() *ProcInfo

func (*ProcInfo) Init

func (this *ProcInfo) Init(pid string)

func (*ProcInfo) StartDate

func (this *ProcInfo) StartDate() string

type ProcMem

type ProcMem struct {
	VmSize int //Virtual memory size
	VmRss  int //Resident set size
	VmData int //Size of data
	VmStk  int //Size of Stack
	VmExe  int //Size of text segments
	VmLib  int //Shared library code size
	ProcBase
}

func (*ProcMem) ReSet

func (this *ProcMem) ReSet()

func (*ProcMem) Refresh

func (this *ProcMem) Refresh() error

func (*ProcMem) String

func (this *ProcMem) String() string

type StructData

type StructData struct {
	Name    string              `json:"name"`
	Version int                 `json:"version"`
	Data    map[string]ConfData `json:"data"`

	//only for gokeeper-cli
	Libraries []string
}

func NewStructData

func NewStructData(name string, version int, data map[string]ConfData) StructData

func (*StructData) SetVersion

func (s *StructData) SetVersion(version int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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