提交 6462c028 编写于 作者: U Ulric Qin

rename obs to dumper

上级 c6571826
......@@ -15,9 +15,9 @@ import (
"github.com/ccfos/nightingale/v6/alert/router"
"github.com/ccfos/nightingale/v6/alert/sender"
"github.com/ccfos/nightingale/v6/conf"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/memsto"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/ccfos/nightingale/v6/pkg/httpx"
"github.com/ccfos/nightingale/v6/pkg/logx"
......@@ -60,7 +60,7 @@ func Initialize(configDir string, cryptoKey string) (func(), error) {
r := httpx.GinEngine(config.Global.RunMode, config.HTTP)
rt := router.New(config.HTTP, config.Alert, alertMuteCache, targetCache, busiGroupCache, alertStats, ctx, externalProcessors)
rt.Config(r)
obs.ConfigRouter(r)
dumper.ConfigRouter(r)
httpClean := httpx.Init(config.HTTP, r)
......
......@@ -11,10 +11,10 @@ import (
"github.com/ccfos/nightingale/v6/center/metas"
"github.com/ccfos/nightingale/v6/center/sso"
"github.com/ccfos/nightingale/v6/conf"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/memsto"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/models/migrate"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/ccfos/nightingale/v6/pkg/httpx"
"github.com/ccfos/nightingale/v6/pkg/i18nx"
......@@ -93,7 +93,7 @@ func Initialize(configDir string, cryptoKey string) (func(), error) {
centerRouter.Config(r)
alertrtRouter.Config(r)
pushgwRouter.Config(r)
obs.ConfigRouter(r)
dumper.ConfigRouter(r)
httpClean := httpx.Init(config.HTTP, r)
......
......@@ -8,8 +8,8 @@ import (
"github.com/ccfos/nightingale/v6/alert/astats"
"github.com/ccfos/nightingale/v6/alert/process"
"github.com/ccfos/nightingale/v6/conf"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/memsto"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/ccfos/nightingale/v6/pkg/httpx"
"github.com/ccfos/nightingale/v6/pkg/logx"
......@@ -63,7 +63,7 @@ func Initialize(configDir string, cryptoKey string) (func(), error) {
alertrtRouter.Config(r)
}
obs.ConfigRouter(r)
dumper.ConfigRouter(r)
httpClean := httpx.Init(config.HTTP, r)
return func() {
......
package obs
package dumper
import "github.com/gin-gonic/gin"
......
package obs
package dumper
import (
"fmt"
......
......@@ -5,8 +5,8 @@ import (
"sync"
"time"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/pkg/errors"
......@@ -109,7 +109,7 @@ func (amc *AlertMuteCacheType) syncAlertMutes() error {
stat, err := models.AlertMuteStatistics(amc.ctx)
if err != nil {
obs.PutSyncRecord("alert_mutes", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
dumper.PutSyncRecord("alert_mutes", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
return errors.WithMessage(err, "failed to exec AlertMuteStatistics")
}
......@@ -117,13 +117,13 @@ func (amc *AlertMuteCacheType) syncAlertMutes() error {
amc.stats.GaugeCronDuration.WithLabelValues("sync_alert_mutes").Set(0)
amc.stats.GaugeSyncNumber.WithLabelValues("sync_alert_mutes").Set(0)
logger.Debug("alert mutes not changed")
obs.PutSyncRecord("alert_mutes", start.Unix(), -1, -1, "not changed")
dumper.PutSyncRecord("alert_mutes", start.Unix(), -1, -1, "not changed")
return nil
}
lst, err := models.AlertMuteGetsAll(amc.ctx)
if err != nil {
obs.PutSyncRecord("alert_mutes", start.Unix(), -1, -1, "failed to query records: "+err.Error())
dumper.PutSyncRecord("alert_mutes", start.Unix(), -1, -1, "failed to query records: "+err.Error())
return errors.WithMessage(err, "failed to exec AlertMuteGetsByCluster")
}
......@@ -144,7 +144,7 @@ func (amc *AlertMuteCacheType) syncAlertMutes() error {
amc.stats.GaugeCronDuration.WithLabelValues("sync_alert_mutes").Set(float64(ms))
amc.stats.GaugeSyncNumber.WithLabelValues("sync_alert_mutes").Set(float64(len(lst)))
logger.Infof("timer: sync mutes done, cost: %dms, number: %d", ms, len(lst))
obs.PutSyncRecord("alert_mutes", start.Unix(), ms, len(lst), "success")
dumper.PutSyncRecord("alert_mutes", start.Unix(), ms, len(lst), "success")
return nil
}
......@@ -5,8 +5,8 @@ import (
"sync"
"time"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/pkg/errors"
......@@ -105,7 +105,7 @@ func (arc *AlertRuleCacheType) syncAlertRules() error {
start := time.Now()
stat, err := models.AlertRuleStatistics(arc.ctx)
if err != nil {
obs.PutSyncRecord("alert_rules", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
dumper.PutSyncRecord("alert_rules", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
return errors.WithMessage(err, "failed to exec AlertRuleStatistics")
}
......@@ -113,13 +113,13 @@ func (arc *AlertRuleCacheType) syncAlertRules() error {
arc.stats.GaugeCronDuration.WithLabelValues("sync_alert_rules").Set(0)
arc.stats.GaugeSyncNumber.WithLabelValues("sync_alert_rules").Set(0)
logger.Debug("alert rules not changed")
obs.PutSyncRecord("alert_rules", start.Unix(), -1, -1, "not changed")
dumper.PutSyncRecord("alert_rules", start.Unix(), -1, -1, "not changed")
return nil
}
lst, err := models.AlertRuleGetsAll(arc.ctx)
if err != nil {
obs.PutSyncRecord("alert_rules", start.Unix(), -1, -1, "failed to query records: "+err.Error())
dumper.PutSyncRecord("alert_rules", start.Unix(), -1, -1, "failed to query records: "+err.Error())
return errors.WithMessage(err, "failed to exec AlertRuleGetsByCluster")
}
......@@ -134,7 +134,7 @@ func (arc *AlertRuleCacheType) syncAlertRules() error {
arc.stats.GaugeCronDuration.WithLabelValues("sync_alert_rules").Set(float64(ms))
arc.stats.GaugeSyncNumber.WithLabelValues("sync_alert_rules").Set(float64(len(m)))
logger.Infof("timer: sync rules done, cost: %dms, number: %d", ms, len(m))
obs.PutSyncRecord("alert_rules", start.Unix(), ms, len(m), "success")
dumper.PutSyncRecord("alert_rules", start.Unix(), ms, len(m), "success")
return nil
}
......@@ -5,8 +5,8 @@ import (
"sync"
"time"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/pkg/errors"
......@@ -121,7 +121,7 @@ func (c *AlertSubscribeCacheType) syncAlertSubscribes() error {
start := time.Now()
stat, err := models.AlertSubscribeStatistics(c.ctx)
if err != nil {
obs.PutSyncRecord("alert_subscribes", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
dumper.PutSyncRecord("alert_subscribes", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
return errors.WithMessage(err, "failed to exec AlertSubscribeStatistics")
}
......@@ -129,13 +129,13 @@ func (c *AlertSubscribeCacheType) syncAlertSubscribes() error {
c.stats.GaugeCronDuration.WithLabelValues("sync_alert_subscribes").Set(0)
c.stats.GaugeSyncNumber.WithLabelValues("sync_alert_subscribes").Set(0)
logger.Debug("alert subscribes not changed")
obs.PutSyncRecord("alert_subscribes", start.Unix(), -1, -1, "not changed")
dumper.PutSyncRecord("alert_subscribes", start.Unix(), -1, -1, "not changed")
return nil
}
lst, err := models.AlertSubscribeGetsAll(c.ctx)
if err != nil {
obs.PutSyncRecord("alert_subscribes", start.Unix(), -1, -1, "failed to query records: "+err.Error())
dumper.PutSyncRecord("alert_subscribes", start.Unix(), -1, -1, "failed to query records: "+err.Error())
return errors.WithMessage(err, "failed to exec AlertSubscribeGetsAll")
}
......@@ -169,7 +169,7 @@ func (c *AlertSubscribeCacheType) syncAlertSubscribes() error {
c.stats.GaugeCronDuration.WithLabelValues("sync_alert_subscribes").Set(float64(ms))
c.stats.GaugeSyncNumber.WithLabelValues("sync_alert_subscribes").Set(float64(len(lst)))
logger.Infof("timer: sync subscribes done, cost: %dms, number: %d", ms, len(lst))
obs.PutSyncRecord("alert_subscribes", start.Unix(), ms, len(lst), "success")
dumper.PutSyncRecord("alert_subscribes", start.Unix(), ms, len(lst), "success")
return nil
}
......@@ -5,8 +5,8 @@ import (
"sync"
"time"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/pkg/errors"
......@@ -84,7 +84,7 @@ func (c *BusiGroupCacheType) syncBusiGroups() error {
stat, err := models.BusiGroupStatistics(c.ctx)
if err != nil {
obs.PutSyncRecord("busi_groups", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
dumper.PutSyncRecord("busi_groups", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
return errors.WithMessage(err, "failed to call BusiGroupStatistics")
}
......@@ -92,13 +92,13 @@ func (c *BusiGroupCacheType) syncBusiGroups() error {
c.stats.GaugeCronDuration.WithLabelValues("sync_busi_groups").Set(0)
c.stats.GaugeSyncNumber.WithLabelValues("sync_busi_groups").Set(0)
logger.Debug("busi_group not changed")
obs.PutSyncRecord("busi_groups", start.Unix(), -1, -1, "not changed")
dumper.PutSyncRecord("busi_groups", start.Unix(), -1, -1, "not changed")
return nil
}
m, err := models.BusiGroupGetMap(c.ctx)
if err != nil {
obs.PutSyncRecord("busi_groups", start.Unix(), -1, -1, "failed to query records: "+err.Error())
dumper.PutSyncRecord("busi_groups", start.Unix(), -1, -1, "failed to query records: "+err.Error())
return errors.WithMessage(err, "failed to call BusiGroupGetMap")
}
......@@ -109,7 +109,7 @@ func (c *BusiGroupCacheType) syncBusiGroups() error {
c.stats.GaugeSyncNumber.WithLabelValues("sync_busi_groups").Set(float64(len(m)))
logger.Infof("timer: sync busi groups done, cost: %dms, number: %d", ms, len(m))
obs.PutSyncRecord("busi_groups", start.Unix(), ms, len(m), "success")
dumper.PutSyncRecord("busi_groups", start.Unix(), ms, len(m), "success")
return nil
}
......@@ -5,8 +5,8 @@ import (
"sync"
"time"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/pkg/errors"
......@@ -83,7 +83,7 @@ func (d *DatasourceCacheType) syncDatasources() error {
stat, err := models.DatasourceStatistics(d.ctx)
if err != nil {
obs.PutSyncRecord("datasources", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
dumper.PutSyncRecord("datasources", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
return errors.WithMessage(err, "failed to call DatasourceStatistics")
}
......@@ -92,14 +92,14 @@ func (d *DatasourceCacheType) syncDatasources() error {
d.stats.GaugeSyncNumber.WithLabelValues("sync_datasources").Set(0)
logger.Debug("datasource not changed")
obs.PutSyncRecord("datasources", start.Unix(), -1, -1, "not changed")
dumper.PutSyncRecord("datasources", start.Unix(), -1, -1, "not changed")
return nil
}
m, err := models.DatasourceGetMap(d.ctx)
if err != nil {
obs.PutSyncRecord("datasources", start.Unix(), -1, -1, "failed to query records: "+err.Error())
dumper.PutSyncRecord("datasources", start.Unix(), -1, -1, "failed to query records: "+err.Error())
return errors.WithMessage(err, "failed to call DatasourceGetMap")
}
......@@ -110,7 +110,7 @@ func (d *DatasourceCacheType) syncDatasources() error {
d.stats.GaugeSyncNumber.WithLabelValues("sync_datasources").Set(float64(len(m)))
logger.Infof("timer: sync datasources done, cost: %dms, number: %d", ms, len(m))
obs.PutSyncRecord("datasources", start.Unix(), ms, len(m), "success")
dumper.PutSyncRecord("datasources", start.Unix(), ms, len(m), "success")
return nil
}
......@@ -8,8 +8,8 @@ import (
"github.com/BurntSushi/toml"
"github.com/ccfos/nightingale/v6/alert/aconf"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/toolkits/pkg/logger"
)
......@@ -76,37 +76,37 @@ func (w *NotifyConfigCacheType) syncNotifyConfigs() error {
cval, err := models.ConfigsGet(w.ctx, models.WEBHOOKKEY)
if err != nil {
obs.PutSyncRecord("webhooks", start.Unix(), -1, -1, "failed to query configs.webhook: "+err.Error())
dumper.PutSyncRecord("webhooks", start.Unix(), -1, -1, "failed to query configs.webhook: "+err.Error())
return err
}
if strings.TrimSpace(cval) != "" {
err = json.Unmarshal([]byte(cval), &w.webhooks)
if err != nil {
obs.PutSyncRecord("webhooks", start.Unix(), -1, -1, "failed to unmarshal configs.webhook: "+err.Error())
dumper.PutSyncRecord("webhooks", start.Unix(), -1, -1, "failed to unmarshal configs.webhook: "+err.Error())
logger.Errorf("failed to unmarshal webhooks:%s error:%v", cval, err)
}
}
obs.PutSyncRecord("webhooks", start.Unix(), time.Since(start).Milliseconds(), len(w.webhooks), "success, webhooks:\n"+cval)
dumper.PutSyncRecord("webhooks", start.Unix(), time.Since(start).Milliseconds(), len(w.webhooks), "success, webhooks:\n"+cval)
logger.Debugf("timer: sync wbhooks done number: %d", len(w.webhooks))
start = time.Now()
cval, err = models.ConfigsGet(w.ctx, models.SMTP)
if err != nil {
obs.PutSyncRecord("smtp", start.Unix(), -1, -1, "failed to query configs.smtp_config: "+err.Error())
dumper.PutSyncRecord("smtp", start.Unix(), -1, -1, "failed to query configs.smtp_config: "+err.Error())
return err
}
if strings.TrimSpace(cval) != "" {
err = toml.Unmarshal([]byte(cval), &w.smtp)
if err != nil {
obs.PutSyncRecord("smtp", start.Unix(), -1, -1, "failed to unmarshal configs.smtp_config: "+err.Error())
dumper.PutSyncRecord("smtp", start.Unix(), -1, -1, "failed to unmarshal configs.smtp_config: "+err.Error())
logger.Errorf("failed to unmarshal smtp:%s error:%v", cval, err)
}
}
obs.PutSyncRecord("smtp", start.Unix(), time.Since(start).Milliseconds(), 1, "success, smtp_config:\n"+cval)
dumper.PutSyncRecord("smtp", start.Unix(), time.Since(start).Milliseconds(), 1, "success, smtp_config:\n"+cval)
var tmp aconf.SMTPConfig
toml.Unmarshal([]byte(cval), &tmp)
......@@ -116,43 +116,43 @@ func (w *NotifyConfigCacheType) syncNotifyConfigs() error {
start = time.Now()
cval, err = models.ConfigsGet(w.ctx, models.NOTIFYSCRIPT)
if err != nil {
obs.PutSyncRecord("notify_script", start.Unix(), -1, -1, "failed to query configs.notify_script: "+err.Error())
dumper.PutSyncRecord("notify_script", start.Unix(), -1, -1, "failed to query configs.notify_script: "+err.Error())
return err
}
if strings.TrimSpace(cval) != "" {
err = json.Unmarshal([]byte(cval), &w.script)
if err != nil {
obs.PutSyncRecord("notify_script", start.Unix(), -1, -1, "failed to unmarshal configs.notify_script: "+err.Error())
dumper.PutSyncRecord("notify_script", start.Unix(), -1, -1, "failed to unmarshal configs.notify_script: "+err.Error())
logger.Errorf("failed to unmarshal notify script:%s error:%v", cval, err)
}
}
obs.PutSyncRecord("notify_script", start.Unix(), time.Since(start).Milliseconds(), 1, "success, notify_script:\n"+cval)
dumper.PutSyncRecord("notify_script", start.Unix(), time.Since(start).Milliseconds(), 1, "success, notify_script:\n"+cval)
logger.Debug("timer: sync notify script done")
start = time.Now()
cval, err = models.ConfigsGet(w.ctx, models.IBEX)
if err != nil {
obs.PutSyncRecord("ibex", start.Unix(), -1, -1, "failed to query configs.ibex_server: "+err.Error())
dumper.PutSyncRecord("ibex", start.Unix(), -1, -1, "failed to query configs.ibex_server: "+err.Error())
return err
}
if strings.TrimSpace(cval) != "" {
err = toml.Unmarshal([]byte(cval), &w.ibex)
if err != nil {
obs.PutSyncRecord("ibex", start.Unix(), -1, -1, "failed to unmarshal configs.ibex_server: "+err.Error())
dumper.PutSyncRecord("ibex", start.Unix(), -1, -1, "failed to unmarshal configs.ibex_server: "+err.Error())
logger.Errorf("failed to unmarshal ibex:%s error:%v", cval, err)
}
} else {
err = toml.Unmarshal([]byte(DefaultIbex), &w.ibex)
if err != nil {
obs.PutSyncRecord("ibex", start.Unix(), -1, -1, "failed to unmarshal configs.ibex_server: "+err.Error())
dumper.PutSyncRecord("ibex", start.Unix(), -1, -1, "failed to unmarshal configs.ibex_server: "+err.Error())
logger.Errorf("failed to unmarshal ibex:%s error:%v", cval, err)
}
}
obs.PutSyncRecord("ibex", start.Unix(), time.Since(start).Milliseconds(), 1, "success, ibex_server config:\n"+cval)
dumper.PutSyncRecord("ibex", start.Unix(), time.Since(start).Milliseconds(), 1, "success, ibex_server config:\n"+cval)
logger.Debug("timer: sync ibex done")
return nil
......
......@@ -5,8 +5,8 @@ import (
"sync"
"time"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/pkg/errors"
......@@ -106,21 +106,21 @@ func (rrc *RecordingRuleCacheType) syncRecordingRules() error {
stat, err := models.RecordingRuleStatistics(rrc.ctx)
if err != nil {
obs.PutSyncRecord("recording_rules", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
dumper.PutSyncRecord("recording_rules", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
return errors.WithMessage(err, "failed to exec RecordingRuleStatistics")
}
if !rrc.StatChanged(stat.Total, stat.LastUpdated) {
rrc.stats.GaugeCronDuration.WithLabelValues("sync_recording_rules").Set(0)
rrc.stats.GaugeSyncNumber.WithLabelValues("sync_recording_rules").Set(0)
obs.PutSyncRecord("recording_rules", start.Unix(), -1, -1, "not changed")
dumper.PutSyncRecord("recording_rules", start.Unix(), -1, -1, "not changed")
logger.Debug("recoding rules not changed")
return nil
}
lst, err := models.RecordingRuleGetsByCluster(rrc.ctx)
if err != nil {
obs.PutSyncRecord("recording_rules", start.Unix(), -1, -1, "failed to query records: "+err.Error())
dumper.PutSyncRecord("recording_rules", start.Unix(), -1, -1, "failed to query records: "+err.Error())
return errors.WithMessage(err, "failed to exec RecordingRuleGetsByCluster")
}
......@@ -135,7 +135,7 @@ func (rrc *RecordingRuleCacheType) syncRecordingRules() error {
rrc.stats.GaugeCronDuration.WithLabelValues("sync_recording_rules").Set(float64(ms))
rrc.stats.GaugeSyncNumber.WithLabelValues("sync_recording_rules").Set(float64(len(m)))
logger.Infof("timer: sync recording rules done, cost: %dms, number: %d", ms, len(m))
obs.PutSyncRecord("recording_rules", start.Unix(), ms, len(m), "success")
dumper.PutSyncRecord("recording_rules", start.Unix(), ms, len(m), "success")
return nil
}
......@@ -8,8 +8,8 @@ import (
"sync"
"time"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/ccfos/nightingale/v6/storage"
......@@ -130,21 +130,21 @@ func (tc *TargetCacheType) syncTargets() error {
stat, err := models.TargetStatistics(tc.ctx)
if err != nil {
obs.PutSyncRecord("targets", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
dumper.PutSyncRecord("targets", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
return errors.WithMessage(err, "failed to call TargetStatistics")
}
if !tc.StatChanged(stat.Total, stat.LastUpdated) {
tc.stats.GaugeCronDuration.WithLabelValues("sync_targets").Set(0)
tc.stats.GaugeSyncNumber.WithLabelValues("sync_targets").Set(0)
obs.PutSyncRecord("targets", start.Unix(), -1, -1, "not changed")
dumper.PutSyncRecord("targets", start.Unix(), -1, -1, "not changed")
logger.Debug("targets not changed")
return nil
}
lst, err := models.TargetGetsAll(tc.ctx)
if err != nil {
obs.PutSyncRecord("targets", start.Unix(), -1, -1, "failed to query records: "+err.Error())
dumper.PutSyncRecord("targets", start.Unix(), -1, -1, "failed to query records: "+err.Error())
return errors.WithMessage(err, "failed to call TargetGetsAll")
}
......@@ -168,7 +168,7 @@ func (tc *TargetCacheType) syncTargets() error {
tc.stats.GaugeCronDuration.WithLabelValues("sync_targets").Set(float64(ms))
tc.stats.GaugeSyncNumber.WithLabelValues("sync_targets").Set(float64(len(lst)))
logger.Infof("timer: sync targets done, cost: %dms, number: %d", ms, len(lst))
obs.PutSyncRecord("targets", start.Unix(), ms, len(lst), "success")
dumper.PutSyncRecord("targets", start.Unix(), ms, len(lst), "success")
return nil
}
......
......@@ -5,8 +5,8 @@ import (
"sync"
"time"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/pkg/errors"
......@@ -140,7 +140,7 @@ func (uc *UserCacheType) syncUsers() error {
stat, err := models.UserStatistics(uc.ctx)
if err != nil {
obs.PutSyncRecord("users", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
dumper.PutSyncRecord("users", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
return errors.WithMessage(err, "failed to exec UserStatistics")
}
......@@ -148,13 +148,13 @@ func (uc *UserCacheType) syncUsers() error {
uc.stats.GaugeCronDuration.WithLabelValues("sync_users").Set(0)
uc.stats.GaugeSyncNumber.WithLabelValues("sync_users").Set(0)
logger.Debug("users not changed")
obs.PutSyncRecord("users", start.Unix(), -1, -1, "not changed")
dumper.PutSyncRecord("users", start.Unix(), -1, -1, "not changed")
return nil
}
lst, err := models.UserGetAll(uc.ctx)
if err != nil {
obs.PutSyncRecord("users", start.Unix(), -1, -1, "failed to query records: "+err.Error())
dumper.PutSyncRecord("users", start.Unix(), -1, -1, "failed to query records: "+err.Error())
return errors.WithMessage(err, "failed to exec UserGetAll")
}
......@@ -170,7 +170,7 @@ func (uc *UserCacheType) syncUsers() error {
uc.stats.GaugeSyncNumber.WithLabelValues("sync_users").Set(float64(len(m)))
logger.Infof("timer: sync users done, cost: %dms, number: %d", ms, len(m))
obs.PutSyncRecord("users", start.Unix(), ms, len(m), "success")
dumper.PutSyncRecord("users", start.Unix(), ms, len(m), "success")
return nil
}
......@@ -5,8 +5,8 @@ import (
"sync"
"time"
"github.com/ccfos/nightingale/v6/dumper"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/obs"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/pkg/errors"
......@@ -111,7 +111,7 @@ func (ugc *UserGroupCacheType) syncUserGroups() error {
stat, err := models.UserGroupStatistics(ugc.ctx)
if err != nil {
obs.PutSyncRecord("user_groups", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
dumper.PutSyncRecord("user_groups", start.Unix(), -1, -1, "failed to query statistics: "+err.Error())
return errors.WithMessage(err, "failed to exec UserGroupStatistics")
}
......@@ -120,14 +120,14 @@ func (ugc *UserGroupCacheType) syncUserGroups() error {
ugc.stats.GaugeSyncNumber.WithLabelValues("sync_user_groups").Set(0)
logger.Debug("user_group not changed")
obs.PutSyncRecord("user_groups", start.Unix(), -1, -1, "not changed")
dumper.PutSyncRecord("user_groups", start.Unix(), -1, -1, "not changed")
return nil
}
lst, err := models.UserGroupGetAll(ugc.ctx)
if err != nil {
obs.PutSyncRecord("user_groups", start.Unix(), -1, -1, "failed to query records: "+err.Error())
dumper.PutSyncRecord("user_groups", start.Unix(), -1, -1, "failed to query records: "+err.Error())
return errors.WithMessage(err, "failed to exec UserGroupGetAll")
}
......@@ -139,7 +139,7 @@ func (ugc *UserGroupCacheType) syncUserGroups() error {
// fill user ids
members, err := models.UserGroupMemberGetAll(ugc.ctx)
if err != nil {
obs.PutSyncRecord("user_groups", start.Unix(), -1, -1, "failed to query members: "+err.Error())
dumper.PutSyncRecord("user_groups", start.Unix(), -1, -1, "failed to query members: "+err.Error())
return errors.WithMessage(err, "failed to exec UserGroupMemberGetAll")
}
......@@ -163,7 +163,7 @@ func (ugc *UserGroupCacheType) syncUserGroups() error {
ugc.stats.GaugeSyncNumber.WithLabelValues("sync_user_groups").Set(float64(len(m)))
logger.Infof("timer: sync user groups done, cost: %dms, number: %d", ms, len(m))
obs.PutSyncRecord("user_groups", start.Unix(), ms, len(m), "success")
dumper.PutSyncRecord("user_groups", start.Unix(), ms, len(m), "success")
return nil
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册