|
@@ -16,10 +16,12 @@ func dealWithSTData() {
|
|
|
log.Println("开始统计站点数据...")
|
|
|
defer qu.Catch()
|
|
|
|
|
|
+ start := int(time.Now().Unix())
|
|
|
now:=time.Now() //当前天
|
|
|
gte_time:= time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, time.Local).Unix()
|
|
|
lt_time := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
|
|
|
- //临时测试
|
|
|
+
|
|
|
+ //临时测试-8号
|
|
|
gte_time = 1618070400
|
|
|
lt_time = 1618156800
|
|
|
mgodata := toCalculateMgoData(gte_time,lt_time)
|
|
@@ -33,7 +35,7 @@ func dealWithSTData() {
|
|
|
|
|
|
comeintime:=qu.Int64All(time.Now().Unix())
|
|
|
date := qu.FormatDateByInt64(&comeintime, qu.DATEFORMAT)
|
|
|
- datamgo.Save("monitor_site", map[string]interface{}{
|
|
|
+ data_mgo.Save("monitor_site", map[string]interface{}{
|
|
|
"comeintime":comeintime,
|
|
|
"updatedate":date,
|
|
|
"mgonum":mgonum,
|
|
@@ -41,6 +43,8 @@ func dealWithSTData() {
|
|
|
"mgodata":mgodata["detail"],
|
|
|
"esdata":esdata["detail"],
|
|
|
})
|
|
|
+
|
|
|
+ log.Println("站点-定时处理完毕...","用时:",int(time.Now().Unix())-start,"秒")
|
|
|
}
|
|
|
|
|
|
|
|
@@ -52,7 +56,9 @@ func toCalculateEsData(gte_time string,lt_time string) map[string]interface{} {
|
|
|
"detail": map[string]interface{}{},
|
|
|
}
|
|
|
}
|
|
|
- log.Println("es 查询区间:",gte_time,lt_time)
|
|
|
+
|
|
|
+ dict:= make(map[string]interface{},0)
|
|
|
+ total,isOK :=0,0
|
|
|
|
|
|
//elastic.InitElasticSize("http://172.17.145.170:9800", 10,)
|
|
|
elastic.InitElasticSize("http://127.0.0.1:12003", 10,)
|
|
@@ -62,7 +68,7 @@ func toCalculateEsData(gte_time string,lt_time string) map[string]interface{} {
|
|
|
log.Println("连接池异常")
|
|
|
}
|
|
|
query :=es_elastic.NewRangeQuery("comeintime").Gte(gte_time).Lt(lt_time)
|
|
|
- cursor, err := esclient.Scan(st_es_index).Query(es_elastic.NewBoolQuery().Must(query)).
|
|
|
+ cursor, err := esclient.Scan(es_index_st).Query(es_elastic.NewBoolQuery().Must(query)).
|
|
|
Size(200).Do()
|
|
|
if err != nil {
|
|
|
log.Println("cursor",err)
|
|
@@ -73,10 +79,7 @@ func toCalculateEsData(gte_time string,lt_time string) map[string]interface{} {
|
|
|
if cursor.Results.Hits == nil {
|
|
|
log.Println("expected results.Hits != nil; got nil")
|
|
|
}
|
|
|
- log.Println("es total :",cursor.TotalHits(),"处理分析中......")
|
|
|
-
|
|
|
- dict:= make(map[string]interface{},0)
|
|
|
- total,start,isOK :=0, int(time.Now().Unix()),0
|
|
|
+ //log.Println("es total :",cursor.TotalHits(),"处理分析中......")
|
|
|
for {
|
|
|
searchResult, err := cursor.Next()
|
|
|
if err != nil {
|
|
@@ -105,7 +108,7 @@ func toCalculateEsData(gte_time string,lt_time string) map[string]interface{} {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- log.Println("st is es over:",total,isOK,"有效:",len(dict),"用时:",int(time.Now().Unix())-start,"秒")
|
|
|
+ //log.Println("st is es over:",total,isOK,"有效:",len(dict),"用时:",int(time.Now().Unix())-start,"秒")
|
|
|
|
|
|
|
|
|
return map[string]interface{}{
|
|
@@ -129,17 +132,16 @@ func toCalculateMgoData(gte_time int64,lt_time int64) map[string]interface{} {
|
|
|
"$lt": lt_time,
|
|
|
},
|
|
|
}
|
|
|
- log.Println("mgo 查询区间",query)
|
|
|
|
|
|
- sess := sitemgo.GetMgoConn()
|
|
|
- defer sitemgo.DestoryMongoConn(sess)
|
|
|
+ sess := st_mgo.GetMgoConn()
|
|
|
+ defer st_mgo.DestoryMongoConn(sess)
|
|
|
|
|
|
dict:= make(map[string]interface{},0)
|
|
|
//细节才需要遍历
|
|
|
- it := sess.DB(sitemgo.DbName).C(st_collname).Find(&query).Select(map[string]interface{}{
|
|
|
+ it := sess.DB(st_mgo.DbName).C(st_c_name).Find(&query).Select(map[string]interface{}{
|
|
|
"site":1,
|
|
|
}).Iter()
|
|
|
- total,start,isOK :=0, int(time.Now().Unix()),0
|
|
|
+ total,isOK :=0,0
|
|
|
for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
|
|
|
if total%10000==0 {
|
|
|
//log.Println("current index",total,isOK)
|
|
@@ -156,10 +158,6 @@ func toCalculateMgoData(gte_time int64,lt_time int64) map[string]interface{} {
|
|
|
|
|
|
tmp = make(map[string]interface{})
|
|
|
}
|
|
|
-
|
|
|
- log.Println("st is mgo over:",total,isOK,"有效:",len(dict),"用时:",int(time.Now().Unix())-start,"秒")
|
|
|
-
|
|
|
-
|
|
|
return map[string]interface{}{
|
|
|
"totalnum" : total,
|
|
|
"detail": dict,
|