Documentation ¶
Overview ¶
Package models implements metric, index, rule, project, user modeling.
Index ¶
- Constants
- Variables
- func ValidateMetricName(name string) error
- func ValidateMetricStamp(stamp uint32) error
- func ValidateProjectName(name string) error
- func ValidateProjectSilentRange(start, end int) error
- func ValidateRuleLevel(level int) error
- func ValidateRulePattern(pattern string) error
- func ValidateTeamName(name string) error
- func ValidateUserEmail(email string) error
- func ValidateUserName(name string) error
- func ValidateUserPhone(phone string) error
- func ValidateWebHookURL(url string) error
- type BulkMetric
- type ByStamp
- type Event
- type EventWrapper
- type Index
- type Metric
- type Project
- type Rule
- func (rule *Rule) Copy() *Rule
- func (rule *Rule) CopyTo(r *Rule)
- func (rule *Rule) Equal(r *Rule) bool
- func (rule *Rule) IsTrendRelated() bool
- func (c *Rule) Lock()
- func (c *Rule) RLock()
- func (c *Rule) RUnlock()
- func (rule *Rule) SetNumMetrics(n int)
- func (c *Rule) Share()
- func (rule *Rule) Test(m *Metric, idx *Index, cfg *config.Config) bool
- func (c *Rule) Unlock()
- type Team
- type User
- type WebHook
Constants ¶
const ( RuleLevelLow = iota RuleLevelMiddle RuleLevelHigh )
Rule Levels
const ( // Max value of the project name length. MaxProjectNameLen = 64 // Max value of the user name length. MaxUserNameLen = 32 // Max value of the rule pattern length. MaxRulePatternLen = 256 // Max value of the metric name length. MaxMetricNameLen = 256 // Min value of the metric stamp. MinMetricStamp uint32 = 1450322633 )
Limitations
Variables ¶
var ( ErrProjectNameEmpty = errors.New("project name is empty") ErrProjectNameTooLong = errors.New("project name is too long") ErrProjectSilentTimeStart = errors.New("project silent time start is invalid") ErrProjectSilentTimeEnd = errors.New("project silent time end is invalid") ErrProjectSilentTimeRange = errors.New("project silent time start should be smaller than end") ErrUserNameEmpty = errors.New("user name is empty") ErrUserNameTooLong = errors.New("user name is too long") ErrUserEmailEmpty = errors.New("user email is empty") ErrUserEmailFormat = errors.New("user email format is invalid") ErrUserPhoneLen = errors.New("user phone length should be 10 or 11") ErrUserPhoneFormat = errors.New("user phone should contains 10 or 11 numbers") ErrRulePatternEmpty = errors.New("rule pattern is empty") ErrRulePatternTooLong = errors.New("rule pattern is too long") ErrRulePatternContainsSpace = errors.New("rule pattern contains spaces") ErrRulePatternFormat = errors.New("rule pattern format is invalid") ErrRuleLevel = errors.New("rule level is invalid") ErrWebHookURLEmpty = errors.New("webhook url is empty") ErrWebHookURLFormat = errors.New("webhook url format is invalid") ErrMetricNameEmpty = errors.New("metric name is empty") ErrMetricNameTooLong = errors.New("metric name is too long") ErrMetricStampTooSmall = errors.New("metric stamp is too small") )
Errors
Functions ¶
func ValidateMetricName ¶ added in v0.1.2
ValidateMetricName validates metric name.
func ValidateMetricStamp ¶ added in v0.1.2
ValidateMetricStamp validates metric stamp.
func ValidateProjectName ¶ added in v0.0.7
ValidateProjectName validates project name
func ValidateProjectSilentRange ¶ added in v0.1.0
ValidateProjectSilentRange validates project silent time start and end.
func ValidateRuleLevel ¶ added in v0.1.5
ValidateRuleLevel validates rule level.
func ValidateRulePattern ¶ added in v0.0.7
ValidateRulePattern validates rule pattern.
func ValidateTeamName ¶ added in v0.2.5
ValidateTeamName validates project name
func ValidateUserEmail ¶ added in v0.0.7
ValidateUserEmail validates user email.
func ValidateUserName ¶ added in v0.0.7
ValidateUserName validates user name.
func ValidateUserPhone ¶ added in v0.0.7
ValidateUserPhone validates user phone.
func ValidateWebHookURL ¶ added in v0.2.5
ValidateWebHookURL validates webhook url.
Types ¶
type BulkMetric ¶ added in v0.2.5
BulkMetric is a data container for time series data points among a few days.
type Event ¶ added in v0.1.8
type Event struct { ID string `json:"id"` Index *Index `json:"index"` Metric *Metric `json:"metric"` Rule *Rule `json:"rule"` }
Event is the alert event.
func (*Event) TranslateRuleComment ¶ added in v0.1.8
TranslateRuleComment translates rule comment variables with metric name and rule pattern.
m := &Metric{Name: "timer.count_ps.foo"} r := &Rule{Pattern: "timer.count_ps.*", Comment: "$1 timing"} ev := &Event{Metric:m, Rule:r} ev.TranslateRuleComment() // => "foo timing"
type EventWrapper ¶ added in v0.2.2
type EventWrapper struct { *Event Team *Team `json:"team"` Project *Project `json:"project"` User *User `json:"user,omitempty"` RuleTranslatedComment string `json:"ruleTranslatedComment"` }
EventWrapper is a wrapper of Event for tmp usage.
func NewWrapperOfEvent ¶ added in v0.2.2
func NewWrapperOfEvent(ev *Event) *EventWrapper
NewWrapperOfEvent creates an event wrapper from given event.
type Index ¶
type Index struct { // Metric name Name string `json:"name"` // Latest stamp for the metric. Stamp uint32 `json:"stamp"` // Latest trending score for the metric. Score float64 `json:"score"` // Latest average for the metric. Average float64 `json:"average"` // Link between index and metric. Link uint32 `json:"link"` // Matched rules. MatchedRules []*Rule `json:"matchedRules,omitempty"` // contains filtered or unexported fields }
Index is for metric indexing, it records metric name for faster metric indexing. And metric latest informations like timstamp, score, average are also indexed.
func (*Index) WriteMetric ¶
WriteMetric writes metric to index.
type Metric ¶
type Metric struct { // Name Name string `json:"name"` // Metric unix time stamp Stamp uint32 `json:"stamp"` // Metric value Value float64 `json:"value"` // Anomaly score Score float64 `json:"score"` // Average old Average float64 `json:"average"` // Link between index and metric. Link uint32 `json:"link"` }
Metric is a data container for time series datapoint.
type Project ¶
type Project struct { // ID in db. ID int `json:"id"` // Name Name string `sql:"not null;unique" json:"name"` // Project may have many rules, they shouldn't be shared. Rules []*Rule `json:"-"` // Project may have many users, they shouldn't be shared. Users []*User `gorm:"many2many:project_users" json:"-"` // Project may have many webhooks, they shouldn't be shared. WebHooks []*WebHook `gorm:"many2many:project_webhooks" json:"-"` // Silent time range in one day. EnableSilent bool `json:"enableSilent"` SilentTimeStart int `json:"silentTimeStart"` SilentTimeEnd int `json:"silentTimeEnd"` // Team belongs to TeamID int `sql:"index;not null;DEFAULT:1" json:"teamID"` }
Project is a rules group.
type Rule ¶
type Rule struct { // ID in db. ID int `gorm:"primary_key" json:"id"` // Project belongs to ProjectID int `sql:"index;not null" json:"projectID"` // Pattern is a wildcard string Pattern string `sql:"size:400;not null" json:"pattern"` // Trend TrendUp bool `json:"trendUp"` TrendDown bool `json:"trendDown"` // Optional thresholds data, only used if the rule condition is about // threshold. Although we really don't need any thresholds for trending // analyzation and alertings, but we still provide a way to alert by // thresholds. ThresholdMax float64 `json:"thresholdMax"` ThresholdMin float64 `json:"thresholdMin"` // Number of metrics matched. NumMetrics int `sql:"-" json:"numMetrics"` // Comment Comment string `sql:"type:varchar(256)" json:"comment"` // Level Level int `json:"level"` // Disabled Disabled bool `sql:"default:false" json:"disabled"` // DisabledFor DisabledFor int `json:"disabledFor"` // DisabledAt DisabledAt time.Time `json:"disabledAt"` // TrackIdle TrackIdle bool `json:"trackIdle"` // FillZero NeverFillZero bool `sql:"default:false" json:"neverFillZero"` // contains filtered or unexported fields }
Rule is a type to describe alerter rule.
func (*Rule) IsTrendRelated ¶ added in v0.2.2
IsTrendRelated returns true if any trend options is set.
func (*Rule) SetNumMetrics ¶ added in v0.0.7
SetNumMetrics sets the rule's number of metrics matched.
type Team ¶ added in v0.2.5
type Team struct { // ID in db. ID int `json:"id"` // Name Name string `sql:"not null;unique" json:"name"` // Project may have many rules, they shouldn't be shared. Project []*Project `json:"-"` }
Team is a projects group.
type User ¶
type User struct { // ID in db. ID int `gorm:"primary_key" json:"id"` // Name Name string `sql:"index;not null;unique" json:"name"` // Email Email string `json:"email"` EnableEmail bool `json:"enableEmail"` // Phone Phone string `json:"phone"` EnablePhone bool `json:"enablePhone"` // Universal Universal bool `sql:"index" json:"universal"` // Users can subscribe many projects. Projects []*Project `gorm:"many2many:project_users" json:"-"` // Rule level to receive RuleLevel int `json:"ruleLevel"` }
User is the alerter message receiver.
type WebHook ¶ added in v0.2.5
type WebHook struct { // ID in db. ID int `gorm:"primary_key" json:"id"` // Name Name string `sql:"index;not null;unique" json:"name"` //Type Type string `json:"type"` // Email URL string `json:"url"` // Universal Universal bool `sql:"index;DEFAULT:false" json:"universal"` // Rule level to receive RuleLevel int `sql:"not null;DEFAULT:0" json:"ruleLevel"` // WebHooks can been subscribed by many projects. Projects []*Project `gorm:"many2many:project_webhooks" json:"-"` }
WebHook is the alerter message receiver.