mirror of
https://github.com/ccfos/nightingale.git
synced 2026-03-12 19:09:06 +00:00
Compare commits
5 Commits
release-22
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
314e11a303 | ||
|
|
3e5871e9f1 | ||
|
|
5e01e8e021 | ||
|
|
61c7bbd0d8 | ||
|
|
303ef3476e |
@@ -13,10 +13,10 @@ import (
|
||||
|
||||
"github.com/ccfos/nightingale/v6/alert/mute"
|
||||
"github.com/ccfos/nightingale/v6/models"
|
||||
"github.com/ccfos/nightingale/v6/pkg/ginx"
|
||||
"github.com/ccfos/nightingale/v6/pkg/strx"
|
||||
"github.com/ccfos/nightingale/v6/pushgw/pconf"
|
||||
"github.com/ccfos/nightingale/v6/pushgw/writer"
|
||||
"github.com/ccfos/nightingale/v6/pkg/ginx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/copier"
|
||||
@@ -886,6 +886,7 @@ func (rt *Router) batchAlertRuleClone(c *gin.Context) {
|
||||
func (rt *Router) timezonesGet(c *gin.Context) {
|
||||
// 返回常用时区列表(按时差去重,每个时差只保留一个代表性时区)
|
||||
timezones := []string{
|
||||
"Local",
|
||||
"UTC",
|
||||
"Asia/Shanghai", // UTC+8 (代表 Asia/Hong_Kong, Asia/Singapore 等)
|
||||
"Asia/Tokyo", // UTC+9 (代表 Asia/Seoul 等)
|
||||
|
||||
@@ -191,6 +191,7 @@ func HandleHeartbeat(c *gin.Context, ctx *ctx.Context, engineName string, metaSe
|
||||
}
|
||||
|
||||
if targetNeedUpdate {
|
||||
newTarget.UpdateAt = time.Now().Unix()
|
||||
err := models.DB(ctx).Model(&target).Updates(newTarget).Error
|
||||
if err != nil {
|
||||
logger.Errorf("update target fields failed, err: %v", err)
|
||||
|
||||
@@ -201,7 +201,7 @@ func (d *Doris) NewWriteConn(ctx context.Context, database string) (*sql.DB, err
|
||||
func (d *Doris) createTimeoutContext(ctx context.Context) (context.Context, context.CancelFunc) {
|
||||
timeout := d.Timeout
|
||||
if timeout == 0 {
|
||||
timeout = 60
|
||||
timeout = 60000
|
||||
}
|
||||
return context.WithTimeout(ctx, time.Duration(timeout)*time.Millisecond)
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func TargetBindBgids(ctx *ctx.Context, idents []string, bgids []int64, tags []st
|
||||
}
|
||||
|
||||
return DB(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := DB(ctx).Clauses(cl).CreateInBatches(&lst, 10).Error; err != nil {
|
||||
if err := tx.Clauses(cl).CreateInBatches(&lst, 10).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if targets, err := TargetsGetByIdents(ctx, idents); err != nil {
|
||||
@@ -100,13 +100,24 @@ func TargetBindBgids(ctx *ctx.Context, idents []string, bgids []int64, tags []st
|
||||
}
|
||||
}
|
||||
|
||||
// update target.update_at so that syncTargets can detect the change and refresh GroupIds cache
|
||||
if err := tx.Model(&Target{}).Where("ident in ?", idents).Update("update_at", updateAt).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func TargetUnbindBgids(ctx *ctx.Context, idents []string, bgids []int64) error {
|
||||
return DB(ctx).Where("target_ident in ? and group_id in ?",
|
||||
idents, bgids).Delete(&TargetBusiGroup{}).Error
|
||||
return DB(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Where("target_ident in ? and group_id in ?",
|
||||
idents, bgids).Delete(&TargetBusiGroup{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// update target.update_at so that syncTargets can detect the change and refresh GroupIds cache
|
||||
return tx.Model(&Target{}).Where("ident in ?", idents).Update("update_at", time.Now().Unix()).Error
|
||||
})
|
||||
}
|
||||
|
||||
func TargetDeleteBgids(tx *gorm.DB, idents []string) error {
|
||||
@@ -150,7 +161,8 @@ func TargetOverrideBgids(ctx *ctx.Context, idents []string, bgids []int64, tags
|
||||
return err
|
||||
}
|
||||
if len(tags) == 0 {
|
||||
return nil
|
||||
// update target.update_at so that syncTargets can detect the change and refresh GroupIds cache
|
||||
return tx.Model(&Target{}).Where("ident IN ?", idents).Update("update_at", updateAt).Error
|
||||
}
|
||||
|
||||
return tx.Model(Target{}).Where("ident IN ?", idents).Updates(map[string]interface{}{
|
||||
|
||||
@@ -21,6 +21,7 @@ type Pushgw struct {
|
||||
PushConcurrency int
|
||||
UpdateTargetByUrlConcurrency int
|
||||
|
||||
GetHeartbeatFromMetric bool // 是否从时序数据中提取机器心跳时间,默认 false
|
||||
BusiGroupLabelKey string
|
||||
IdentMetrics []string
|
||||
IdentStatsThreshold int
|
||||
|
||||
@@ -250,8 +250,10 @@ func (r *Router) datadogSeries(c *gin.Context) {
|
||||
}
|
||||
|
||||
if ident != "" {
|
||||
// register host
|
||||
ids[ident] = struct{}{}
|
||||
if r.Pushgw.GetHeartbeatFromMetric {
|
||||
// register host
|
||||
ids[ident] = struct{}{}
|
||||
}
|
||||
|
||||
// fill tags
|
||||
target, has := r.TargetCache.Get(ident)
|
||||
|
||||
@@ -200,8 +200,10 @@ func (rt *Router) falconPush(c *gin.Context) {
|
||||
}
|
||||
|
||||
if ident != "" {
|
||||
// register host
|
||||
ids[ident] = struct{}{}
|
||||
if rt.Pushgw.GetHeartbeatFromMetric {
|
||||
// register host
|
||||
ids[ident] = struct{}{}
|
||||
}
|
||||
|
||||
// fill tags
|
||||
target, has := rt.TargetCache.Get(ident)
|
||||
|
||||
@@ -195,8 +195,10 @@ func (rt *Router) openTSDBPut(c *gin.Context) {
|
||||
|
||||
host, has := arr[i].Tags["ident"]
|
||||
if has {
|
||||
// register host
|
||||
ids[host] = struct{}{}
|
||||
if rt.Pushgw.GetHeartbeatFromMetric {
|
||||
// register host
|
||||
ids[host] = struct{}{}
|
||||
}
|
||||
|
||||
// fill tags
|
||||
target, has := rt.TargetCache.Get(host)
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"net/http"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/ccfos/nightingale/v6/pushgw/pstat"
|
||||
"github.com/ccfos/nightingale/v6/pkg/ginx"
|
||||
"github.com/ccfos/nightingale/v6/pushgw/pstat"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/snappy"
|
||||
@@ -149,7 +149,7 @@ func (rt *Router) remoteWrite(c *gin.Context) {
|
||||
pstat.CounterSampleReceivedByIdent.WithLabelValues(ident).Inc()
|
||||
}
|
||||
|
||||
if insertTarget {
|
||||
if rt.Pushgw.GetHeartbeatFromMetric && insertTarget {
|
||||
// has ident tag or agent_hostname tag
|
||||
// register host in table target
|
||||
ids[ident] = struct{}{}
|
||||
|
||||
Reference in New Issue
Block a user