Documentation
¶
Overview ¶
Package models implements metric, index, rule, project, user modeling.
Index ¶
- Constants
- Variables
- func ValidateProjectName(name string) error
- func ValidateRulePattern(pattern string) error
- func ValidateUserEmail(email string) error
- func ValidateUserName(name string) error
- func ValidateUserPhone(phone string) error
- type Index
- type Metric
- type Project
- type Rule
- func (rule *Rule) BuildRepr()
- func (rule *Rule) Copy() *Rule
- func (rule *Rule) CopyTo(r *Rule)
- func (rule *Rule) Equal(r *Rule) 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 User
Constants ¶
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 )
Limitations
Variables ¶
var ( ErrProjectNameEmpty = errors.New("project name is empty") ErrProjectNameTooLong = errors.New("project name is too long") 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") )
Errors
Functions ¶
func ValidateProjectName ¶ added in v0.0.7
ValidateProjectName validates project name
func ValidateRulePattern ¶ added in v0.0.7
ValidateRulePattern validates rule pattern.
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.
Types ¶
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"`
// 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"`
// Matched rules
TestedRules []*Rule `json:"-"`
}
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 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;unique" 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"`
// String representation.
Repr string `sql:"-" json:"repr"`
// Number of metrics matched.
NumMetrics int `sql:"-" json:"numMetrics"`
// contains filtered or unexported fields
}
Rule is a type to describe alerter rule.
func (*Rule) SetNumMetrics ¶ added in v0.0.7
SetNumMetrics sets the rule's number of metrics matched.
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:"-"`
}
User is the alerter message receiver.