|
|
@ -1,6 +1,7 @@ |
|
|
|
package et_sink |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"gitea.anxinyun.cn/container/common_models" |
|
|
|
"gitea.anxinyun.cn/container/common_utils/configLoad" |
|
|
|
"gitea.anxinyun.cn/container/common_utils/storage/storageDBs" |
|
|
@ -92,16 +93,22 @@ func (the *SinkHandler) sinkRawDataToES(deviceData common_models.DeviceData) { |
|
|
|
the.dataQueueVib = append(the.dataQueueVib, vbRaws) |
|
|
|
case common_models.RawTypeDiag: |
|
|
|
default: |
|
|
|
esRaws := common_models.EsRaw{ |
|
|
|
StructId: deviceData.StructId, |
|
|
|
IotaDeviceName: deviceData.Name, |
|
|
|
Data: deviceData.Raw, |
|
|
|
CollectTime: deviceData.AcqTime.Truncate(time.Millisecond), |
|
|
|
Meta: deviceData.DeviceInfo.DeviceMeta.GetOutputProps(), |
|
|
|
IotaDevice: deviceData.DeviceId, |
|
|
|
CreateTime: time.Now().Truncate(time.Millisecond), |
|
|
|
|
|
|
|
if deviceData.Raw == nil { |
|
|
|
msg, _ := json.Marshal(deviceData) |
|
|
|
log.Printf("异常空,raw数据 =%s", string(msg)) |
|
|
|
} else { |
|
|
|
esRaws := common_models.EsRaw{ |
|
|
|
StructId: deviceData.StructId, |
|
|
|
IotaDeviceName: deviceData.Name, |
|
|
|
Data: deviceData.Raw, |
|
|
|
CollectTime: deviceData.AcqTime.Truncate(time.Millisecond), |
|
|
|
Meta: deviceData.DeviceInfo.DeviceMeta.GetOutputProps(), |
|
|
|
IotaDevice: deviceData.DeviceId, |
|
|
|
CreateTime: time.Now().Truncate(time.Millisecond), |
|
|
|
} |
|
|
|
the.dataQueueRaw = append(the.dataQueueRaw, esRaws) |
|
|
|
} |
|
|
|
the.dataQueueRaw = append(the.dataQueueRaw, esRaws) |
|
|
|
} |
|
|
|
|
|
|
|
if len(the.dataQueueRaw) >= the.batchCount || len(the.dataQueueVib) >= the.batchCount { |
|
|
@ -119,9 +126,9 @@ func (the *SinkHandler) dumpRawBatchMonitor() { |
|
|
|
if len(the.dataQueueRaw) > 0 { |
|
|
|
count := len(the.dataQueueRaw) |
|
|
|
log.Printf("es写入dataQueueRaw数据 count====> %d", count) |
|
|
|
needDump := the.dataQueueRaw[:count] |
|
|
|
needDump := the.dataQueueRaw[:count] //make([]common_models.EsRaw, count)
|
|
|
|
the.dataQueueRaw = the.dataQueueRaw[count:] |
|
|
|
the.dumpRaws(needDump) |
|
|
|
go the.dumpRaws(needDump) |
|
|
|
} |
|
|
|
|
|
|
|
if len(the.dataQueueVib) > 0 { |
|
|
@ -129,7 +136,7 @@ func (the *SinkHandler) dumpRawBatchMonitor() { |
|
|
|
log.Printf("es写入dataQueueVib数据 count====> %d", count) |
|
|
|
needDump := the.dataQueueVib[:count] |
|
|
|
the.dataQueueVib = the.dataQueueVib[count:] |
|
|
|
the.dumpVibRaws(needDump) |
|
|
|
go the.dumpVibRaws(needDump) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -138,13 +145,13 @@ func (the *SinkHandler) dumpRawBatchMonitor() { |
|
|
|
func (the *SinkHandler) dumpRaws(esRaws []common_models.EsRaw) { |
|
|
|
for i, consumer := range the.storageConsumers { |
|
|
|
log.Printf("[consumer-%d]存储raw数据 %d 条", i, len(esRaws)) |
|
|
|
go consumer.SaveRaw(esRaws) |
|
|
|
consumer.SaveRaw(esRaws) |
|
|
|
} |
|
|
|
} |
|
|
|
func (the *SinkHandler) dumpVibRaws(esVbRaws []common_models.EsVbRaw) { |
|
|
|
for i, consumer := range the.storageConsumers { |
|
|
|
log.Printf("[consumer-%d]存储VbRaw数据 %d 条", i, len(esVbRaws)) |
|
|
|
go consumer.SaveVib(esVbRaws) |
|
|
|
consumer.SaveVib(esVbRaws) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -159,7 +166,7 @@ func (the *SinkHandler) dumpThemeBatchMonitor() { |
|
|
|
count := len(the.dataQueueTheme) |
|
|
|
needDump := the.dataQueueTheme[:count] |
|
|
|
the.dataQueueTheme = the.dataQueueTheme[count:] |
|
|
|
the.dumpThemes(needDump) |
|
|
|
go the.dumpThemes(needDump) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -195,7 +202,7 @@ func (the *SinkHandler) sinkThemeData(stations []common_models.Station) { |
|
|
|
func (the *SinkHandler) dumpThemes(esThemes []common_models.EsTheme) { |
|
|
|
for i, consumer := range the.storageConsumers { |
|
|
|
log.Printf("[consumer-%d]存储Theme数据 %d 条", i, len(esThemes)) |
|
|
|
go consumer.SaveTheme(esThemes) |
|
|
|
consumer.SaveTheme(esThemes) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|