moira

package module
v2.3.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 6 Imported by: 0

README

Moira 2.0 Documentation Status Telegram Gitter Build Status Coverage Status Go Report Card

Moira 2.0 is a completely rewritten version of:

  1. Checker and API services in Go (instead of Python), based on carbonapi implementation.
  2. Web service in React, with slightly different UI.

Code in this repository is a backend part of Moira monitoring application. Frontend part is here.

Documentation for the entire Moira project is available on Read the Docs site.

If you have any questions, you can ask us on Gitter.

Thanks

SKB Kontur

Moira was originally developed and is supported by SKB Kontur, a B2G company based in Ekaterinburg, Russia. We express gratitude to our company for encouraging us to opensource Moira and for giving back to the community that created Graphite and many other useful DevOps tools.

Documentation

Index

Constants

View Source
const (
	// FallingTrigger represents falling trigger type, in which OK > WARN > ERROR
	FallingTrigger = "falling"
	// RisingTrigger represents rising trigger type, in which OK < WARN < ERROR
	RisingTrigger = "rising"
	// ExpressionTrigger represents trigger type with custom user expression
	ExpressionTrigger = "expression"
)

Variables

This section is empty.

Functions

func UseFloat64

func UseFloat64(f *float64) float64

UseFloat64 gets pointer value of float64 or default float64 if pointer is nil

func UseString

func UseString(str *string) string

UseString gets pointer value of string or default string if pointer is nil

Types

type CheckData

type CheckData struct {
	Metrics         map[string]MetricState `json:"metrics"`
	Score           int64                  `json:"score"`
	State           string                 `json:"state"`
	Timestamp       int64                  `json:"timestamp,omitempty"`
	EventTimestamp  int64                  `json:"event_timestamp,omitempty"`
	Suppressed      bool                   `json:"suppressed,omitempty"`
	SuppressedState string                 `json:"suppressed_state,omitempty"`
	Message         string                 `json:"msg,omitempty"`
}

CheckData represent last trigger check data

func (CheckData) GetEventTimestamp

func (checkData CheckData) GetEventTimestamp() int64

GetEventTimestamp gets event timestamp for given check

func (*CheckData) GetOrCreateMetricState

func (checkData *CheckData) GetOrCreateMetricState(metric string, emptyTimestampValue int64) MetricState

GetOrCreateMetricState gets metric state from check data or create new if CheckData has no state for given metric

func (*CheckData) UpdateScore

func (checkData *CheckData) UpdateScore() int64

UpdateScore update and return checkData score, based on metric states and checkData state

type ContactData

type ContactData struct {
	Type  string `json:"type"`
	Value string `json:"value"`
	ID    string `json:"id"`
	User  string `json:"user"`
}

ContactData represents contact object

type Database

type Database interface {
	// SelfState
	UpdateMetricsHeartbeat() error
	GetMetricsUpdatesCount() (int64, error)
	GetChecksUpdatesCount() (int64, error)
	GetRemoteChecksUpdatesCount() (int64, error)
	GetNotifierState() (string, error)
	SetNotifierState(string) error

	// Tag storing
	GetTagNames() ([]string, error)
	RemoveTag(tagName string) error
	GetTagTriggerIDs(tagName string) ([]string, error)

	// LastCheck storing
	GetTriggerLastCheck(triggerID string) (CheckData, error)
	SetTriggerLastCheck(triggerID string, checkData *CheckData, isRemote bool) error
	RemoveTriggerLastCheck(triggerID string) error
	GetTriggerCheckIDs(tags []string, onlyErrors bool) ([]string, error)
	SetTriggerCheckMetricsMaintenance(triggerID string, metrics map[string]int64) error

	// Trigger storing
	GetTriggerIDs() ([]string, error)
	GetAllTriggerIDs() ([]string, error)
	GetRemoteTriggerIDs() ([]string, error)
	GetTrigger(triggerID string) (Trigger, error)
	GetTriggers(triggerIDs []string) ([]*Trigger, error)
	GetTriggerChecks(triggerIDs []string) ([]*TriggerCheck, error)
	SaveTrigger(triggerID string, trigger *Trigger) error
	RemoveTrigger(triggerID string) error
	GetPatternTriggerIDs(pattern string) ([]string, error)
	RemovePatternTriggerIDs(pattern string) error

	// Throttling
	GetTriggerThrottling(triggerID string) (time.Time, time.Time)
	SetTriggerThrottling(triggerID string, next time.Time) error
	DeleteTriggerThrottling(triggerID string) error

	// NotificationEvent storing
	GetNotificationEvents(triggerID string, start, size int64) ([]*NotificationEvent, error)
	PushNotificationEvent(event *NotificationEvent, ui bool) error
	GetNotificationEventCount(triggerID string, from int64) int64
	FetchNotificationEvent() (NotificationEvent, error)
	RemoveAllNotificationEvents() error

	// ContactData storing
	GetContact(contactID string) (ContactData, error)
	GetContacts(contactIDs []string) ([]*ContactData, error)
	GetAllContacts() ([]*ContactData, error)
	RemoveContact(contactID string) error
	SaveContact(contact *ContactData) error
	GetUserContactIDs(userLogin string) ([]string, error)

	// SubscriptionData storing
	GetSubscription(id string) (SubscriptionData, error)
	GetSubscriptions(subscriptionIDs []string) ([]*SubscriptionData, error)
	SaveSubscription(subscription *SubscriptionData) error
	SaveSubscriptions(subscriptions []*SubscriptionData) error
	RemoveSubscription(subscriptionID string) error
	GetUserSubscriptionIDs(userLogin string) ([]string, error)
	GetTagsSubscriptions(tags []string) ([]*SubscriptionData, error)

	// ScheduledNotification storing
	GetNotifications(start, end int64) ([]*ScheduledNotification, int64, error)
	RemoveNotification(notificationKey string) (int64, error)
	RemoveAllNotifications() error
	FetchNotifications(to int64) ([]*ScheduledNotification, error)
	AddNotification(notification *ScheduledNotification) error
	AddNotifications(notification []*ScheduledNotification, timestamp int64) error

	// Patterns and metrics storing
	GetPatterns() ([]string, error)
	AddPatternMetric(pattern, metric string) error
	GetPatternMetrics(pattern string) ([]string, error)
	RemovePattern(pattern string) error
	RemovePatternsMetrics(pattern []string) error
	RemovePatternWithMetrics(pattern string) error

	SubscribeMetricEvents(tomb *tomb.Tomb) (<-chan *MetricEvent, error)
	SaveMetrics(buffer map[string]*MatchedMetric) error
	GetMetricRetention(metric string) (int64, error)
	GetMetricsValues(metrics []string, from int64, until int64) (map[string][]*MetricValue, error)
	RemoveMetricValues(metric string, toTime int64) error
	RemoveMetricsValues(metrics []string, toTime int64) error

	AddTriggersToCheck(triggerIDs []string) error
	GetTriggerToCheck() (string, error)
	GetTriggersToCheckCount() (int64, error)

	AddRemoteTriggersToCheck(triggerIDs []string) error
	GetRemoteTriggerToCheck() (string, error)
	GetRemoteTriggersToCheckCount() (int64, error)

	// TriggerCheckLock storing
	AcquireTriggerCheckLock(triggerID string, timeout int) error
	DeleteTriggerCheckLock(triggerID string) error
	SetTriggerCheckLock(triggerID string) (bool, error)

	// Bot data storing
	GetIDByUsername(messenger, username string) (string, error)
	SetUsernameID(messenger, username, id string) error
	RemoveUser(messenger, username string) error
	RegisterBotIfAlreadyNot(messenger string, ttl time.Duration) bool
	RenewBotRegistration(messenger string) bool
	DeregisterBots()
	DeregisterBot(messenger string) bool
}

Database implements DB functionality

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Warning(args ...interface{})
	Warningf(format string, args ...interface{})
}

Logger implements logger abstraction

type MatchedMetric

type MatchedMetric struct {
	Metric             string
	Patterns           []string
	Value              float64
	Timestamp          int64
	RetentionTimestamp int64
	Retention          int
}

MatchedMetric represent parsed and matched metric data

type MetricEvent

type MetricEvent struct {
	Metric  string `json:"metric"`
	Pattern string `json:"pattern"`
}

MetricEvent represent filter metric event

type MetricState

type MetricState struct {
	EventTimestamp  int64    `json:"event_timestamp"`
	State           string   `json:"state"`
	Suppressed      bool     `json:"suppressed"`
	SuppressedState string   `json:"suppressed_state,omitempty"`
	Timestamp       int64    `json:"timestamp"`
	Value           *float64 `json:"value,omitempty"`
	Maintenance     int64    `json:"maintenance,omitempty"`
}

MetricState represent metric state data for given timestamp

func (*MetricState) GetCheckPoint

func (metricState *MetricState) GetCheckPoint(checkPointGap int64) int64

GetCheckPoint gets check point for given MetricState CheckPoint is the timestamp from which to start checking the current state of the metric

func (MetricState) GetEventTimestamp

func (metricState MetricState) GetEventTimestamp() int64

GetEventTimestamp gets event timestamp for given metric

type MetricValue

type MetricValue struct {
	RetentionTimestamp int64   `json:"step,omitempty"`
	Timestamp          int64   `json:"ts"`
	Value              float64 `json:"value"`
}

MetricValue represent metric data

type NotificationEvent

type NotificationEvent struct {
	IsTriggerEvent bool     `json:"trigger_event,omitempty"`
	Timestamp      int64    `json:"timestamp"`
	Metric         string   `json:"metric"`
	Value          *float64 `json:"value,omitempty"`
	State          string   `json:"state"`
	TriggerID      string   `json:"trigger_id"`
	SubscriptionID *string  `json:"sub_id,omitempty"`
	ContactID      string   `json:"contactId,omitempty"`
	OldState       string   `json:"old_state"`
	Message        *string  `json:"msg,omitempty"`
}

NotificationEvent represents trigger state changes event

func (NotificationEvent) String

func (eventData NotificationEvent) String() string

type NotificationEvents

type NotificationEvents []NotificationEvent

NotificationEvents represents slice of NotificationEvent

func (NotificationEvents) GetSubjectState

func (events NotificationEvents) GetSubjectState() string

GetSubjectState returns the most critical state of events

type ScheduleData

type ScheduleData struct {
	Days           []ScheduleDataDay `json:"days"`
	TimezoneOffset int64             `json:"tzOffset"`
	StartOffset    int64             `json:"startOffset"`
	EndOffset      int64             `json:"endOffset"`
}

ScheduleData represent subscription schedule

func (*ScheduleData) IsScheduleAllows

func (schedule *ScheduleData) IsScheduleAllows(ts int64) bool

IsScheduleAllows check if the time is in the allowed schedule interval

type ScheduleDataDay

type ScheduleDataDay struct {
	Enabled bool   `json:"enabled"`
	Name    string `json:"name,omitempty"`
}

ScheduleDataDay represent week day of schedule

type ScheduledNotification

type ScheduledNotification struct {
	Event     NotificationEvent `json:"event"`
	Trigger   TriggerData       `json:"trigger"`
	Contact   ContactData       `json:"contact"`
	Throttled bool              `json:"throttled"`
	SendFail  int               `json:"send_fail"`
	Timestamp int64             `json:"timestamp"`
}

ScheduledNotification represent notification object

func (*ScheduledNotification) GetKey

func (notification *ScheduledNotification) GetKey() string

GetKey return notification key to prevent duplication to the same contact

type Sender

type Sender interface {
	SendEvents(events NotificationEvents, contact ContactData, trigger TriggerData, throttled bool) error
	Init(senderSettings map[string]string, logger Logger, location *time.Location, dateTimeFormat string) error
}

Sender interface for implementing specified contact type sender

type SubscriptionData

type SubscriptionData struct {
	Contacts          []string     `json:"contacts"`
	Tags              []string     `json:"tags"`
	Schedule          ScheduleData `json:"sched"`
	ID                string       `json:"id"`
	Enabled           bool         `json:"enabled"`
	IgnoreWarnings    bool         `json:"ignore_warnings,omitempty"`
	IgnoreRecoverings bool         `json:"ignore_recoverings,omitempty"`
	ThrottlingEnabled bool         `json:"throttling"`
	User              string       `json:"user"`
}

SubscriptionData represent user subscription

func (*SubscriptionData) MustIgnore

func (subscription *SubscriptionData) MustIgnore(eventData *NotificationEvent) bool

MustIgnore returns true if given state transition must be ignored

type Trigger

type Trigger struct {
	ID               string        `json:"id"`
	Name             string        `json:"name"`
	Desc             *string       `json:"desc,omitempty"`
	Targets          []string      `json:"targets"`
	WarnValue        *float64      `json:"warn_value"`
	ErrorValue       *float64      `json:"error_value"`
	TriggerType      string        `json:"trigger_type"`
	Tags             []string      `json:"tags"`
	TTLState         *string       `json:"ttl_state,omitempty"`
	TTL              int64         `json:"ttl,omitempty"`
	Schedule         *ScheduleData `json:"sched,omitempty"`
	Expression       *string       `json:"expression,omitempty"`
	PythonExpression *string       `json:"python_expression,omitempty"`
	Patterns         []string      `json:"patterns"`
	IsRemote         bool          `json:"is_remote"`
}

Trigger represents trigger data object

func (*Trigger) IsSimple

func (trigger *Trigger) IsSimple() bool

IsSimple checks triggers patterns If patterns more than one or it contains standard graphite wildcard symbols, when this target can contain more then one metrics, and is it not simple trigger

type TriggerCheck

type TriggerCheck struct {
	Trigger
	Throttling int64     `json:"throttling"`
	LastCheck  CheckData `json:"last_check"`
}

TriggerCheck represent trigger data with last check data and check timestamp

type TriggerData

type TriggerData struct {
	ID         string   `json:"id"`
	Name       string   `json:"name"`
	Desc       string   `json:"desc"`
	Targets    []string `json:"targets"`
	WarnValue  float64  `json:"warn_value"`
	ErrorValue float64  `json:"error_value"`
	Tags       []string `json:"__notifier_trigger_tags"`
}

TriggerData represents trigger object

func (*TriggerData) GetTags

func (trigger *TriggerData) GetTags() string

GetTags returns "[tag1][tag2]...[tagN]" string

Directories

Path Synopsis
api
dto
nolint nolint nolint nolint nolint nolint nolint nolint nolint
nolint nolint nolint nolint nolint nolint nolint nolint nolint
cmd
api
cli
logging
metrics
graphite/go-metrics
nolint nolint nolint nolint nolint nolint
nolint nolint nolint nolint nolint nolint
mock
moira-alert
Package mock_moira_alert is a generated GoMock package.
Package mock_moira_alert is a generated GoMock package.
notifier
Package mock_notifier is a generated GoMock package.
Package mock_notifier is a generated GoMock package.
scheduler
Package mock_scheduler is a generated GoMock package.
Package mock_scheduler is a generated GoMock package.
senders

Jump to

Keyboard shortcuts

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