model

package
v0.0.0-...-1fc07e7 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IdKey      = "_id"
	Prefix int = iota
	Surffix
)

Variables

View Source
var (
	ProcCollect   = "PROC"
	PluginCollect = "PLUGIN"
	PortCollect   = "PORT"
	ApiCollect    = "API"

	RunPrefix = "RUN"
	RunType   = []string{ApiCollect}
)
View Source
var (
	HostnameProp   = "hostname"
	HostStatusProp = "status"
	IpProp         = "ip"

	Online  = "online"
	Offline = "offline"
	Dead    = "dead"
)
View Source
var (
	ErrResMarshal error = errors.New("marshal resources fail")

	ErrResFormat    error = errors.New("invalid resource format")
	ErrInvalidParam error = errors.New("invalid param")
	ErrInvalidUUID  error = errors.New("invalid uuid")
)
View Source
var (
	Machine = "machine"
	Collect = "collect"
	Alarm   = "alarm"
	Deploy  = "deploy"

	Templates []string = []string{
		Machine, Alarm, Collect,
	}

	PkProperty = map[string]string{
		Machine: "hostname",
		Collect: "name",
		Alarm:   "name",
		Deploy:  "name",
	}

	TemplatePrefix     string = "_template_"
	TemplateCollectNum int    = len(collectTemplate)
)
View Source
var LogBackend *log.FileBackend

log file backend

View Source
var (
	RootTemplate map[string]ResourceList
)

Functions

func AppendResources

func AppendResources(rsByte []byte, rs ...Resource) ([]byte, error)

ResourcesAppendByte append the resource to resources.

func DeleteResource

func DeleteResource(rsByte []byte, IDs ...string) ([]byte, error)

Delete resource by resourceID..

func GenCollectName

func GenCollectName(res Resource) string

func GetResNameFromMeasurements

func GetResNameFromMeasurements(measurements []string) ([]string, bool)

GetNameFromMeasurements get the resource names of the measurements. PROC.bin.cpu.idle -> PROC.bin PLUGIN.name.cpu.idle -> PLUGIN.name PORT.service.xx -> PORT.service.xx RUN.API.Ping.xx -> Run.API.Ping.xx

func UpdateCollectName

func UpdateCollectName(collects ...Resource) error

func UpdateResByID

func UpdateResByID(rsByte []byte, ID string, updateMap map[string]string) ([]byte, error)

Update resource with resourceID by updateMap. NOTE: will not change resource ID.

Types

type AlarmResource

type AlarmResource models.Alarm

func NewAlarm

func NewAlarm(ns, name string) *AlarmResource

func NewAlarmByRes

func NewAlarmByRes(ns string, data Resource, ID string) (*AlarmResource, error)

func (*AlarmResource) DisableSelf

func (a *AlarmResource) DisableSelf()

func (*AlarmResource) EnableSelf

func (a *AlarmResource) EnableSelf()

func (*AlarmResource) SetAlert

func (a *AlarmResource) SetAlert(level, groups, alert, message string) error

func (*AlarmResource) SetBlock

func (a *AlarmResource) SetBlock(data Resource)

func (*AlarmResource) SetID

func (a *AlarmResource) SetID(id string)

func (*AlarmResource) SetMD5AndVersion

func (a *AlarmResource) SetMD5AndVersion() error

func (*AlarmResource) SetQuery

func (a *AlarmResource) SetQuery(function, rp, measurement, period, where,
	expression, every, groupby, trigger, shift, value, stime, etime string) error

type Dashboard

type Dashboard struct {
	Title  string  `json:"title"`
	Panels []Panel `json:"panels"`
}

type DashboardData

type DashboardData []Dashboard

type HandleFunc

type HandleFunc func(raw []byte) (ResourceList, error)

type Panel

type Panel struct {
	Title     string   `json:"title"`
	GraphType string   `json:"type"`
	Targets   []Target `json:"targets"`
}

type Report

type Report models.Report

type ResAction

type ResAction interface {
	Marshal() ([]byte, error)
	Unmarshal(raw []byte) error
}

ResAction is the interface that resources Marshal and Unmarshal method.

type Resource

type Resource map[string]string

func GetAlarmFromCollect

func GetAlarmFromCollect(res Resource, ns, groups string) ([]Resource, error)

func NewAlarmResourceByMap

func NewAlarmResourceByMap(ns string, data map[string]string, ID string) (Resource, error)

func NewResource

func NewResource(resMap map[string]string) Resource

func TransAlarmToResource

func TransAlarmToResource(alarm AlarmResource) (Resource, error)

func (*Resource) ID

func (r *Resource) ID() (string, bool)

func (*Resource) InitID

func (r *Resource) InitID() string

InitID create ID for the resource if not have, and return ID.

func (*Resource) Marshal

func (r *Resource) Marshal() ([]byte, error)

Marshal will create UUID if the resource have no ID. Return the resource []byte/ID.

func (*Resource) NewID

func (r *Resource) NewID() string

func (*Resource) ReadProperty

func (r *Resource) ReadProperty(key string) (string, bool)

ReadProperty return property value value of key.

func (*Resource) SetProperty

func (r *Resource) SetProperty(k, v string)

SetProperty set the k-v to resource.

func (*Resource) Size

func (r *Resource) Size() int

Size returns marshed bytes size.

func (*Resource) Unmarshal

func (r *Resource) Unmarshal(raw []byte) error

type ResourceList

type ResourceList []Resource

func NewResourceList

func NewResourceList(resMaps []map[string]string) (*ResourceList, error)

func (*ResourceList) AppendResource

func (rl *ResourceList) AppendResource(r ...Resource)

func (*ResourceList) AppendResourceByte

func (rl *ResourceList) AppendResourceByte(resByte []byte) error

func (*ResourceList) AppendResources

func (rl *ResourceList) AppendResources(res ResourceList)

func (*ResourceList) Get

func (rl *ResourceList) Get(propertyK string, ValueList ...string) ([]Resource, error)

Get multi resource from rl by reousrce property. And Get resource by resource ID, if k is IdKey.

func (*ResourceList) Marshal

func (rl *ResourceList) Marshal() ([]byte, error)

Marshal returns the byte format data of Resources.

func (*ResourceList) Size

func (rl *ResourceList) Size() int

Size returns marshed bytes size.

func (*ResourceList) Unmarshal

func (rl *ResourceList) Unmarshal(raw []byte) error

Unmarshal the byte to the method caller rs.

func (*ResourceList) WalkRsByte

func (rl *ResourceList) WalkRsByte(rsByte []byte, handler walkResourceFunc) ([]byte, error)

walk the resources byte, process every resource by handler.

type ResourceSearch

type ResourceSearch struct {
	Id    string   // key of resource property
	Key   string   // search string
	Value []string // match prefix or Surffix
	Fuzzy bool

	Process HandleFunc
}

func NewSearch

func NewSearch(fuzzy bool, k string, v ...string) (ResourceSearch, error)

func (*ResourceSearch) IdSearch

func (s *ResourceSearch) IdSearch(raw []byte) (ResourceList, error)

func (*ResourceSearch) Init

func (s *ResourceSearch) Init() error

func (*ResourceSearch) ValueSearch

func (s *ResourceSearch) ValueSearch(raw []byte) (ResourceList, error)

type Row

type Row struct {
	Key    []byte `json:"key,omitempty"`
	Value  []byte `json:"value,omitempty"`
	Bucket []byte `json:"bucket,omitempty"`
}

type Target

type Target struct {
	Ns          string `json:"ns"`
	Measurement string `json:"measurement"`
	Fn          string `json:"function"`
	Where       string `json:"where"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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