Documentation
¶
Overview ¶
Package models implements metric, index, rule, project, user and state modeling.
Index ¶
- Constants
- 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 (rule *Rule) IsValid() bool
- func (c *Rule) Lock()
- func (c *Rule) RLock()
- func (c *Rule) RUnlock()
- func (c *Rule) Share()
- func (rule *Rule) Test(m *Metric, cfg *config.Config) bool
- func (c *Rule) Unlock()
- type State
- type User
Constants ¶
const ( WhenTrendUp = 0x1 // 0b000001 WhenTrendDown = 0x2 // 0b000010 WhenValueGt = 0x4 // 0b000100 WhenValueLt = 0x8 // 0b001000 WhenTrendUpAndValueGt = 0x10 // 0b010000 WhenTrendDownAndValueLt = 0x20 // 0b100000 )
Conditions
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index struct {
// Metric name
Name string `json:"name"`
// Latest stamp for the metric.
Stamp uint32 `json:"stamp"`
// Latest 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.
func (*Metric) IsAnomalous ¶
IsAnomalous test whether the metric is anomalous.
func (*Metric) IsAnomalousTrendDown ¶
IsAnomalousTrendDown test whether the metric is anomalously trending down.
func (*Metric) IsAnomalousTrendUp ¶
IsAnomalousTrendUp test whether the metric is anomalously trending up.
func (*Metric) IsTrendDown ¶
IsTrendDown test whether the metric is trending down.
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"`
// Alerting condition, described as the logic OR result of basic conditions
// above:
// When = condition1 | condition2
// example:
// 0x3 = WhenTrendUp | WhenTrendDown
When int `json:"when"`
// 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 offer a way to alert by
// thresholds.
ThresholdMax float64 `json:"thresholdMax"`
ThresholdMin float64 `json:"thresholdMin"`
// Never alert for values below this line. The mainly reason to provide
// this option is to ignore the volatility of values with a very small
// average level.
TrustLine float64 `json:"trustLine"`
// String representation.
Repr string `sql:"-" json:"repr"`
// contains filtered or unexported fields
}
Rule is a type to describe alerter rule.
func (*Rule) BuildRepr ¶
func (rule *Rule) BuildRepr()
BuildRepr initializes the rule's string repr.
type State ¶
type State struct {
// Detection won't start if the current analyzation suite is too small,
// Count is to record the count of metrics hit the current grid.
// It won't be updated until it is greater than startSize.
// And there is no need to use a lock or sync.Mutex for it since incoming
// metrics at the same time never duplicates.
Count uint32
// Current moving average value for this metric at this grid.
Average float64
// Current moving standard deviation for this metric at this grid.
StdDev float64
}
State is to record the recurrence result of detection.
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.