当前位置: 首页>>代码示例>>Golang>>正文


Golang types.Alert类代码示例

本文整理汇总了Golang中github.com/prometheus/alertmanager/types.Alert的典型用法代码示例。如果您正苦于以下问题:Golang Alert类的具体用法?Golang Alert怎么用?Golang Alert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Alert类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: insert

// insert inserts the alert into the aggregation group. If the aggregation group
// is empty afterwards, it returns true.
func (ag *aggrGroup) insert(alert *types.Alert) {
	ag.mtx.Lock()
	defer ag.mtx.Unlock()

	ag.alerts[alert.Fingerprint()] = alert

	// Immediately trigger a flush if the wait duration for this
	// alert is already over.
	if !ag.hasSent && alert.StartsAt.Add(ag.opts.GroupWait).Before(time.Now()) {
		ag.next.Reset(0)
	}
}
开发者ID:farcaller,项目名称:alertmanager,代码行数:14,代码来源:dispatch.go

示例2: Put

// Put adds the given alert to the set.
func (a *Alerts) Put(alerts ...*types.Alert) error {
	a.mtx.Lock()
	defer a.mtx.Unlock()

	err := a.db.Update(func(tx *bolt.Tx) error {
		b := tx.Bucket(bktAlerts)

		for _, alert := range alerts {
			fp := make([]byte, 8)
			binary.BigEndian.PutUint64(fp, uint64(alert.Fingerprint()))

			ab := b.Get(fp)

			// Merge the alert with the existing one.
			if ab != nil {
				var old types.Alert
				if err := json.Unmarshal(ab, &old); err != nil {
					return fmt.Errorf("decoding alert failed: %s", err)
				}
				// Merge alerts if there is an overlap in activity range.
				if (alert.EndsAt.After(old.StartsAt) && alert.EndsAt.Before(old.EndsAt)) ||
					(alert.StartsAt.After(old.StartsAt) && alert.StartsAt.Before(old.EndsAt)) {
					alert = old.Merge(alert)
				}
			}

			ab, err := json.Marshal(alert)
			if err != nil {
				return fmt.Errorf("encoding alert failed: %s", err)
			}

			if err := b.Put(fp, ab); err != nil {
				return fmt.Errorf("writing alert failed: %s", err)
			}

			// Send the update to all subscribers.
			for _, ch := range a.listeners {
				ch <- alert
			}
		}
		return nil
	})

	return err
}
开发者ID:craig-mulligan,项目名称:alertmanager,代码行数:46,代码来源:boltmem.go

示例3: hasUpdate

// hasUpdates checks an alert against the last notification that was made
// about it.
func (n *DedupingNotifier) hasUpdate(alert *types.Alert, last *types.NotifyInfo, now time.Time, interval time.Duration) bool {
	if last != nil {
		if alert.Resolved() {
			if last.Resolved {
				return false
			}
		} else if !last.Resolved {
			// Do not send again if last was delivered unless
			// the repeat interval has already passed.
			if !now.After(last.Timestamp.Add(interval)) {
				return false
			}
		}
	} else if alert.Resolved() {
		// If the alert is resolved but we never notified about it firing,
		// there is nothing to do.
		return false
	}
	return true
}
开发者ID:MonsantoCo,项目名称:alertmanager,代码行数:22,代码来源:notify.go

示例4: set

// set the alert in the source cache.
func (r *InhibitRule) set(a *types.Alert) {
	r.mtx.Lock()
	defer r.mtx.Unlock()

	r.scache[a.Fingerprint()] = a
}
开发者ID:prometheus,项目名称:alertmanager,代码行数:7,代码来源:inhibit.go

示例5: Put

// Put implements the Alerts interface.
func (a *Alerts) Put(alerts ...*types.Alert) error {
	dbmtx.Lock()
	defer dbmtx.Unlock()

	tx, err := a.db.Begin()
	if err != nil {
		return err
	}

	// The insert invariant requires that there are no two alerts with the same
	// fingerprint that have overlapping activity range ([StartsAt:EndsAt]).
	// Such alerts are merged into a single one with the union of both intervals
	// as its new activity interval.
	// The exact merge procedure is defined on the Alert structure. Here, we just
	// care about finding intersecting alerts for each new inserts, deleting them
	// if existant, and insert the new alert we retrieved by merging.
	overlap, err := tx.Prepare(`
		SELECT id, annotations, starts_at, ends_at, updated_at, timeout
		FROM alerts
		WHERE fingerprint == $1 AND (
			(starts_at <= $2 AND ends_at >= $2) OR
			(starts_at <= $3 AND ends_at >= $3)
		)
	`)
	if err != nil {
		tx.Rollback()
		return err
	}
	defer overlap.Close()

	delOverlap, err := tx.Prepare(`
		DELETE FROM alerts WHERE id IN (
			SELECT id FROM alerts
			WHERE fingerprint == $1 AND (
				(starts_at <= $2 AND ends_at >= $2) OR
				(starts_at <= $3 AND ends_at >= $3)
			)
		)
	`)
	if err != nil {
		tx.Rollback()
		return err
	}
	defer delOverlap.Close()

	insert, err := tx.Prepare(`
		INSERT INTO alerts(fingerprint, labels, annotations, starts_at, ends_at, updated_at, timeout)
		VALUES ($1, $2, $3, $4, $5, $6, $7)
	`)
	if err != nil {
		tx.Rollback()
		return err
	}
	defer insert.Close()

	for _, alert := range alerts {
		fp := alert.Fingerprint()

		// Retrieve all intersecting alerts and delete them.
		olaps, err := overlap.Query(int64(fp), alert.StartsAt, alert.EndsAt)
		if err != nil {
			tx.Rollback()
			return err
		}

		var (
			overlapIDs []int64
			merges     []*types.Alert
		)
		for olaps.Next() {
			var (
				id  int64
				na  types.Alert
				ann []byte
			)
			if err := olaps.Scan(
				&id,
				&ann,
				&na.StartsAt,
				&na.EndsAt,
				&na.UpdatedAt,
				&na.Timeout,
			); err != nil {
				tx.Rollback()
				return err
			}
			if err := json.Unmarshal(ann, &na.Annotations); err != nil {
				tx.Rollback()
				return err
			}
			na.Labels = alert.Labels

			merges = append(merges, &na)
			overlapIDs = append(overlapIDs, id)
		}
		if err := olaps.Err(); err != nil {
			tx.Rollback()
			return err
		}
//.........这里部分代码省略.........
开发者ID:cherti,项目名称:alertmanager,代码行数:101,代码来源:sqlite.go


注:本文中的github.com/prometheus/alertmanager/types.Alert类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。