Browse Source

update 调整输入输出

dev
lucas 15 hours ago
parent
commit
758fefa11c
  1. 18
      configFiles/config_安心云告警双控.yaml
  2. 4
      consumers/AXY_SK/config.go
  3. 48
      consumers/consumerAxySkAlarm.go

18
configFiles/config_安心云告警双控.yaml

@ -1,6 +1,15 @@
consumer: consumerAxySkAlarm consumer: consumerAxySkAlarm
ioConfig: ioConfig:
in: in:
es:
address:
- "http://10.8.30.160:30092"
index: native_sk_alarms #推送告警索引
auth:
userName: post
password: 123
interval: 30 #多久写一次es(秒)
out:
kafka: kafka:
brokers: brokers:
- 10.8.30.160:30992 - 10.8.30.160:30992
@ -8,15 +17,6 @@ ioConfig:
alarmTopic: anxinyun_alarm #推送告警的主题 alarmTopic: anxinyun_alarm #推送告警的主题
topics: topics:
- no - no
out:
es:
address:
- "http://10.8.30.160:30092"
index: native_sk_alarms #推送告警索引
auth:
userName: post
password: 123
interval: 30 #多久写一次es(秒)
monitor: monitor:
cron: 24 * * * * cron: 24 * * * *

4
consumers/AXY_SK/config.go

@ -12,11 +12,11 @@ type ioConfig struct {
Out out `json:"out"` Out out `json:"out"`
} }
type in struct { type in struct {
Kafka config.KafkaConfig `json:"kafka"` Es config.EsConfig `json:"es"`
} }
type out struct { type out struct {
Es config.EsConfig `json:"es"` Kafka config.KafkaConfig `json:"kafka"`
} }
type Info struct { type Info struct {

48
consumers/consumerAxySkAlarm.go

@ -21,8 +21,8 @@ type consumerAxySkAlarm struct {
alarmCache map[string]models.EsAlarm alarmCache map[string]models.EsAlarm
//具体配置 //具体配置
Info AXY_SK.ConfigFile Info AXY_SK.ConfigFile
InKafka _kafka.KafkaHelper InEs dbOperate.ESHelper
OutEs dbOperate.ESHelper OutKafka _kafka.KafkaHelper
infoPg *dbOperate.DBHelper infoPg *dbOperate.DBHelper
sinkMap sync.Map sinkMap sync.Map
lock sync.Mutex lock sync.Mutex
@ -66,24 +66,24 @@ func (the *consumerAxySkAlarm) Initial(cfg string) error {
} }
func (the *consumerAxySkAlarm) inputInitial() error { func (the *consumerAxySkAlarm) inputInitial() error {
//数据入口 //数据入口
the.InKafka = _kafka.KafkaHelper{ the.OutKafka = _kafka.KafkaHelper{
Brokers: the.Info.IoConfig.In.Kafka.Brokers, Brokers: the.Info.IoConfig.Out.Kafka.Brokers,
GroupId: the.Info.IoConfig.In.Kafka.GroupId, GroupId: the.Info.IoConfig.Out.Kafka.GroupId,
} }
the.InKafka.Initial() the.OutKafka.Initial()
for _, inTopic := range the.Info.IoConfig.In.Kafka.Topics { for _, inTopic := range the.Info.IoConfig.Out.Kafka.Topics {
the.InKafka.Subscribe(inTopic, the.onData) the.OutKafka.Subscribe(inTopic, the.onData)
} }
the.InKafka.Worker() the.OutKafka.Worker()
return nil return nil
} }
func (the *consumerAxySkAlarm) outputInitial() error { func (the *consumerAxySkAlarm) outputInitial() error {
//数据出口 //数据出口
the.OutEs = *dbOperate.NewESHelper( the.InEs = *dbOperate.NewESHelper(
the.Info.IoConfig.Out.Es.Address, the.Info.IoConfig.In.Es.Address,
the.Info.IoConfig.Out.Es.Auth.UserName, the.Info.IoConfig.In.Es.Auth.UserName,
the.Info.IoConfig.Out.Es.Auth.Password, the.Info.IoConfig.In.Es.Auth.Password,
) )
return nil return nil
@ -105,13 +105,13 @@ func (the *consumerAxySkAlarm) monitorInitial() error {
for taskName, cron := range the.Info.Monitor { for taskName, cron := range the.Info.Monitor {
switch taskName { switch taskName {
case "cron": case "cron":
//the.monitor.RegisterTask(cron, the.updateTriggerConfig) the.monitor.RegisterTask(cron, the.updateTriggerConfig)
default: default:
log.Printf("定时任务[%s],cron=[%s] 无匹配", taskName, cron) log.Printf("定时任务[%s],cron=[%s] 无匹配", taskName, cron)
} }
} }
//测试用 //测试用
the.updateTriggerConfig() //the.updateTriggerConfig()
return nil return nil
} }
func (the *consumerAxySkAlarm) updateTriggerConfig() { func (the *consumerAxySkAlarm) updateTriggerConfig() {
@ -161,7 +161,7 @@ func (the *consumerAxySkAlarm) judgeSK() string {
//配置的结构物的监测因素 去查询 //配置的结构物的监测因素 去查询
esSql := the.getEsAlarmTriggerPartQueryStr(trigger.StructId) esSql := the.getEsAlarmTriggerPartQueryStr(trigger.StructId)
alarms, err := the.OutEs.SearchAlarm(the.Info.IoConfig.Out.Es.Index, esSql) alarms, err := the.InEs.SearchAlarm(the.Info.IoConfig.In.Es.Index, esSql)
if err != nil { if err != nil {
log.Printf("es查询异常err -> %s", err.Error()) log.Printf("es查询异常err -> %s", err.Error())
continue continue
@ -224,10 +224,10 @@ func (the *consumerAxySkAlarm) judgeSK() string {
} }
payload := the.skAlarmInfo(alarmInfoTemplate, level, detail, alarmTime) payload := the.skAlarmInfo(alarmInfoTemplate, level, detail, alarmTime)
the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload) the.OutKafka.Publish(the.Info.IoConfig.Out.Kafka.AlarmTopic, payload)
} else { } else {
payload := the.skAlarmElimination(alarmInfoTemplate, level, detail) payload := the.skAlarmElimination(alarmInfoTemplate, level, detail)
the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload) the.OutKafka.Publish(the.Info.IoConfig.Out.Kafka.AlarmTopic, payload)
delete(the.historyStationAlarmMap, sid) delete(the.historyStationAlarmMap, sid)
} }
} }
@ -358,7 +358,7 @@ func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationA
func (the *consumerAxySkAlarm) updateEsAlarmTriggerHistory(structId int) { func (the *consumerAxySkAlarm) updateEsAlarmTriggerHistory(structId int) {
esSql := the.getEsAlarmTriggerHistoryQueryStr(structId) esSql := the.getEsAlarmTriggerHistoryQueryStr(structId)
alarms, err := the.OutEs.SearchAlarm(the.Info.IoConfig.Out.Es.Index, esSql) alarms, err := the.InEs.SearchAlarm(the.Info.IoConfig.In.Es.Index, esSql)
if err != nil { if err != nil {
log.Printf("结构物[%d] 查询历史有效AlarmTrigger 异常=>%s", structId, err.Error()) log.Printf("结构物[%d] 查询历史有效AlarmTrigger 异常=>%s", structId, err.Error())
} }
@ -447,7 +447,7 @@ func (the *consumerAxySkAlarm) getEsAlarmTriggerPartQueryStr(structId int) strin
} }
func (the *consumerAxySkAlarm) sinkTask() { func (the *consumerAxySkAlarm) sinkTask() {
intervalSec := the.Info.IoConfig.Out.Es.Interval intervalSec := the.Info.IoConfig.In.Es.Interval
ticker := time.NewTicker(time.Duration(intervalSec) * time.Second) ticker := time.NewTicker(time.Duration(intervalSec) * time.Second)
defer ticker.Stop() defer ticker.Stop()
for { for {
@ -475,9 +475,9 @@ func (the *consumerAxySkAlarm) toSink() {
return true return true
}) })
if len(themes) > 0 { if len(themes) > 0 {
index := the.Info.IoConfig.Out.Es.Index index := the.Info.IoConfig.In.Es.Index
log.Printf("写入es [%s] %d条", index, len(themes)) log.Printf("写入es [%s] %d条", index, len(themes))
the.OutEs.BulkWriteThemes2Es(index, themes) the.InEs.BulkWriteThemes2Es(index, themes)
the.sinkMap.Clear() the.sinkMap.Clear()
} }
} }
@ -503,9 +503,7 @@ func (the *consumerAxySkAlarm) Work() {
}() }()
} }
func (the *consumerAxySkAlarm) onData(topic string, msg string) bool { func (the *consumerAxySkAlarm) onData(topic string, msg string) bool {
//if len(msg) > 80 {
// log.Printf("recv:[%s]:%s ...", topic, msg[:80])
//}
adaptor := adaptors.Adaptor_Savoir_LastTheme{} adaptor := adaptors.Adaptor_Savoir_LastTheme{}
needPush := adaptor.Transform(topic, msg) needPush := adaptor.Transform(topic, msg)

Loading…
Cancel
Save