Selaa lähdekoodia

添加数据量监控

wcc 1 vuosi sitten
vanhempi
commit
5a6f61db8b
4 muutettua tiedostoa jossa 28 lisäystä ja 0 poistoa
  1. 6 0
      bidding_listen/config.go
  2. 3 0
      bidding_listen/config.toml
  3. 4 0
      bidding_listen/main.go
  4. 15 0
      bidding_listen/utils.go

+ 6 - 0
bidding_listen/config.go

@@ -7,6 +7,7 @@ type GlobalConf struct {
 	Mysql       MysqlConf
 	Log         Log
 	Mongospider MgoConf
+	Email       EmailConf
 }
 
 type MgoConf struct {
@@ -50,3 +51,8 @@ type Log struct {
 	LogLevel   string
 	Format     string
 }
+
+type EmailConf struct {
+	Api string
+	To  string
+}

+ 3 - 0
bidding_listen/config.toml

@@ -45,6 +45,9 @@
     password= "=PDT49#80Z!RVv52_z"
     table = "ods_datamonitoring_bidding"    ## 存储结果数据表
 
+[email]
+    api = "http://172.17.145.179:19281/_send/_mail"
+    to = "wangchengcheng@topnet.net.cn"
 
 ## 日志
 # 日志

+ 4 - 0
bidding_listen/main.go

@@ -203,6 +203,10 @@ func dealBidding() {
 
 	wg.Wait()
 	log.Info("dealBidding", zap.Int("over ", count))
+	//没有数据时,发送邮件
+	if count == 0 {
+		SendMail("每日数据监控", "查询数据为空,请处理")
+	}
 }
 
 //saveBidding 保存bidding数据

+ 15 - 0
bidding_listen/utils.go

@@ -1,7 +1,10 @@
 package main
 
 import (
+	"app.yhyue.com/data_processing/common_utils/log"
 	"fmt"
+	"go.uber.org/zap"
+	"net/http"
 	"sort"
 	"time"
 )
@@ -26,3 +29,15 @@ func IsInStringArray(str string, arr []string) bool {
 	// 如果找到了则返回 true,否则返回 false
 	return pos < len(arr) && arr[pos] == str
 }
+
+//SendMail 发送邮件
+func SendMail(title, content string) {
+	url := fmt.Sprintf("%s?to=%s&title=%s&body=%s", GF.Email.Api, GF.Email.To, title, content)
+	fmt.Println("url=>", url)
+	res, err := http.Get(url)
+	if err != nil {
+		log.Info("SendMail", zap.Any("err", err))
+	} else {
+		log.Info("SendMail", zap.Any("res", res))
+	}
+}