未验证 提交 8fe3d2b0 编写于 作者: Y yubo 提交者: GitHub

bugfix: replace ref with instantiated variable for prober.rules.updatedAt (#536)

* add mon.plugins.redis descriptions

* bugfix: add region field for instances/heartbeat

* bugfix: replace ref with instantiated variable for prober.rules.updatedAt
上级 25c31fcb
......@@ -37,6 +37,10 @@ func (p CollectRule) PluginName() string {
return p.CollectType
}
func (p *CollectRule) String() string {
return fmt.Sprintf("id %d type %s name %s", p.Id, p.CollectType, p.Name)
}
func (p *CollectRule) Validate(v ...interface{}) error {
if p.Name == "" {
return fmt.Errorf("invalid collectRule.name")
......
......@@ -3,7 +3,6 @@ package http
import (
"encoding/json"
"fmt"
"log"
"regexp"
"strings"
......@@ -90,7 +89,6 @@ func collectRulesGetV2(c *gin.Context) {
limit := queryInt(c, "limit", 20)
typ := queryStr(c, "type", "")
log.Printf("typ %s", typ)
total, list, err := models.GetCollectRules(typ, nid, limit, offset(c, limit, 0))
renderData(c, map[string]interface{}{
......
package manager
import (
"log"
"strconv"
"sync"
"time"
......@@ -23,6 +22,7 @@ type collectRule struct {
precision time.Duration
metrics []*dataobj.MetricValue
lastAt int64
updatedAt int64
}
func newCollectRule(rule *models.CollectRule) (*collectRule, error) {
......@@ -47,6 +47,7 @@ func newCollectRule(rule *models.CollectRule) (*collectRule, error) {
tags: tags,
metrics: []*dataobj.MetricValue{},
precision: time.Second,
updatedAt: rule.UpdatedAt,
}, nil
}
......@@ -121,15 +122,16 @@ func (p *collectRule) prepareMetrics() error {
}
func (p *collectRule) update(rule *models.CollectRule) error {
if p.CollectRule.UpdatedAt == rule.UpdatedAt {
if p.updatedAt == rule.UpdatedAt {
return nil
}
logger.Debugf("update %s", rule)
input, err := telegrafInput(rule)
if err != nil {
// ignore error, use old config
log.Printf("telegrafInput() id %d type %s name %s err %s",
rule.Id, rule.CollectType, rule.Name, err)
logger.Warningf("telegrafInput %s err %s", rule, err)
}
tags, err := dataobj.SplitTagsString(rule.Tags)
......@@ -140,6 +142,7 @@ func (p *collectRule) update(rule *models.CollectRule) error {
p.Input = input
p.CollectRule = rule
p.tags = tags
p.UpdatedAt = rule.UpdatedAt
return nil
}
......
......@@ -87,22 +87,22 @@ func (p *manager) schedule() error {
}
summary := heap.Pop(&p.heap).(*ruleSummary)
ruleConfig, ok := p.cache.Get(summary.id)
latestRule, ok := p.cache.Get(summary.id)
if !ok {
// drop it if not exist in cache
delete(p.index, summary.id)
continue
}
rule, ok := p.index[ruleConfig.Id]
rule, ok := p.index[latestRule.Id]
if !ok {
// impossible
log.Printf("manager.index[%d] not exists", ruleConfig.Id)
logger.Warningf("manager.index[%d] not exists", latestRule.Id)
continue
}
// update rule
if err := rule.update(ruleConfig); err != nil {
if err := rule.update(latestRule); err != nil {
logger.Warningf("ruleEntity update err %s", err)
}
......@@ -110,9 +110,9 @@ func (p *manager) schedule() error {
logger.Debugf("%s %s %d lastAt %ds before nextAt %ds later",
rule.CollectType, rule.Name, rule.Id,
now-rule.lastAt, ruleConfig.Step)
now-rule.lastAt, rule.Step)
summary.activeAt = now + int64(ruleConfig.Step)
summary.activeAt = now + int64(rule.Step)
rule.lastAt = now
heap.Push(&p.heap, summary)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册