models

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package models implements metric, index, rule, project, user modeling.

Index

Constants

View Source
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 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) Copy

func (idx *Index) Copy() *Index

Copy the index.

func (*Index) CopyTo

func (idx *Index) CopyTo(i *Index)

CopyTo copy the index to another.

func (*Index) Equal

func (idx *Index) Equal(i *Index) bool

Equal tests the equality.

func (*Index) Lock

func (c *Index) Lock()

Lock locks instance for writing.

func (*Index) RLock

func (c *Index) RLock()

RLock locks instance for reading.

func (*Index) RUnlock

func (c *Index) RUnlock()

RUnlock unlocks instance reading.

func (*Index) Share

func (c *Index) Share()

Share the instance between goroutines.

func (*Index) Unlock

func (c *Index) Unlock()

Unlock unlocks instance writing.

func (*Index) WriteMetric

func (idx *Index) WriteMetric(m *Metric)

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

func (m *Metric) IsAnomalous() bool

IsAnomalous test whether the metric is anomalous.

func (*Metric) IsAnomalousTrendDown

func (m *Metric) IsAnomalousTrendDown() bool

IsAnomalousTrendDown test whether the metric is anomalously trending down.

func (*Metric) IsAnomalousTrendUp

func (m *Metric) IsAnomalousTrendUp() bool

IsAnomalousTrendUp test whether the metric is anomalously trending up.

func (*Metric) IsTrendDown

func (m *Metric) IsTrendDown() bool

IsTrendDown test whether the metric is trending down.

func (*Metric) IsTrendUp

func (m *Metric) IsTrendUp() bool

IsTrendUp test whether the metric is trending up.

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.

func (*Rule) Copy

func (rule *Rule) Copy() *Rule

Copy the rule.

func (*Rule) CopyTo

func (rule *Rule) CopyTo(r *Rule)

CopyTo copy the rule to another.

func (*Rule) Equal

func (rule *Rule) Equal(r *Rule) bool

Equal tests rule equality

func (*Rule) IsValid

func (rule *Rule) IsValid() bool

IsValid returns true if rule.When is valid.

func (*Rule) Lock

func (c *Rule) Lock()

Lock locks instance for writing.

func (*Rule) RLock

func (c *Rule) RLock()

RLock locks instance for reading.

func (*Rule) RUnlock

func (c *Rule) RUnlock()

RUnlock unlocks instance reading.

func (*Rule) Share

func (c *Rule) Share()

Share the instance between goroutines.

func (*Rule) Test

func (rule *Rule) Test(m *Metric, cfg *config.Config) bool

Test returns true if the metric hits this rule.

func (*Rule) Unlock

func (c *Rule) Unlock()

Unlock unlocks instance writing.

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.

Jump to

Keyboard shortcuts

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