Esempio n. 1
0
// encode encodes db value from index.
func encode(idx *models.Index) []byte {
	// Value format is Stamp:Score:Average
	score := util.ToFixed(idx.Score, 5)
	average := util.ToFixed(idx.Average, 5)
	s := fmt.Sprintf("%d:%s:%s", idx.Stamp, score, average)
	return []byte(s)
}
Esempio n. 2
0
// BuildRepr sets the rule's string repr.
func (rule *Rule) BuildRepr() {
	// Lock if shared.
	rule.Lock()
	defer rule.Unlock()
	// Repr
	var parts []string
	if rule.TrendUp && rule.ThresholdMax == 0 {
		parts = append(parts, "trend ↑")
	}
	if rule.TrendUp && rule.ThresholdMax != 0 {
		s := fmt.Sprintf("(trend ↑ && value >= %s)", util.ToFixed(rule.ThresholdMax, 3))
		parts = append(parts, s)
	}
	if !rule.TrendUp && rule.ThresholdMax != 0 {
		s := fmt.Sprintf("value >= %s", util.ToFixed(rule.ThresholdMax, 3))
		parts = append(parts, s)
	}
	if rule.TrendDown && rule.ThresholdMin == 0 {
		parts = append(parts, "trend ↓")
	}
	if rule.TrendDown && rule.ThresholdMin != 0 {
		s := fmt.Sprintf("(trend ↓ && value <= %s)", util.ToFixed(rule.ThresholdMin, 3))
		parts = append(parts, s)
	}
	if !rule.TrendDown && rule.ThresholdMin != 0 {
		s := fmt.Sprintf("value <= %s", util.ToFixed(rule.ThresholdMin, 3))
		parts = append(parts, s)
	}
	rule.Repr = strings.Join(parts, " || ")
}
Esempio n. 3
0
// encodeValue encodes state value.
func (db *DB) encodeValue(s *models.State) []byte {
	// Value format is Average:StdDev:Count
	average := util.ToFixed(s.Average, 5)
	stddev := util.ToFixed(s.StdDev, 5)
	value := fmt.Sprintf("%s:%s:%d", average, stddev, s.Count)
	return []byte(value)
}
Esempio n. 4
0
// encodeValue encodes db value from metric.
func encodeValue(m *models.Metric) []byte {
	// Value format is Value:Score:Average.
	value := util.ToFixed(m.Value, 5)
	score := util.ToFixed(m.Score, 5)
	average := util.ToFixed(m.Average, 5)
	s := fmt.Sprintf("%s:%s:%s", value, score, average)
	return []byte(s)
}