forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,241 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/enum/consts"
|
||||
"stat/common/log"
|
||||
"stat/models/appInfoMod"
|
||||
"stat/models/channelmod"
|
||||
"stat/models/downloadinfo"
|
||||
"stat/models/registermod"
|
||||
"stat/statg"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LanpageMonitor struct {
|
||||
Minute int64
|
||||
LastDay int64
|
||||
}
|
||||
|
||||
var lastIosCount int64
|
||||
var lastAndroidCount int64
|
||||
|
||||
var lastBiliIosCount int64
|
||||
var lastNhavIosCount int64
|
||||
|
||||
var lastHuawenIosCount int64
|
||||
|
||||
var lastZhihuIosCount int64
|
||||
|
||||
var lanpages = []string{"madougg.com"}
|
||||
var channels = []string{"xza00267", "xza00182", "xza00082", "xza00139", "xza00242", "sqt00120", "xza00274", "xza00258", "ysa00021", "fabuye", channelmod.OfficialChannelName, "mdapp01", "mdapp", "modelweb", "mdapp02", "mdapp03"}
|
||||
|
||||
func RunMonitor() error {
|
||||
msg := RunLandPageMonitor()
|
||||
statg.Bot.SendDownloadMessage(msg)
|
||||
|
||||
channelMsg := ChannelMonitor()
|
||||
statg.Bot.SendDownloadMessage(channelMsg)
|
||||
return nil
|
||||
}
|
||||
|
||||
func RunLandPageMonitor() string {
|
||||
ctx := context.Background()
|
||||
appid := int32(888) // 麻豆
|
||||
end := time.Now()
|
||||
start := end.Add(-30 * time.Minute)
|
||||
|
||||
lanpageMap := make(map[string]*LanpageMonitor)
|
||||
|
||||
downloadList, serr := downloadinfo.GetAccessCountByTime(ctx, appid, start, end)
|
||||
if serr != nil {
|
||||
log.Error("RunMonitor, GetAccessCountByTime", log.E(serr))
|
||||
return ""
|
||||
}
|
||||
|
||||
for _, valueInfo := range downloadList {
|
||||
if len(valueInfo.Domain) > 0 {
|
||||
domain := valueInfo.Domain
|
||||
if strings.Contains(valueInfo.Domain, "https://") {
|
||||
domain = strings.Replace(valueInfo.Domain, "https://", "", -1)
|
||||
} else if strings.Contains(valueInfo.Domain, "http://") {
|
||||
domain = strings.Replace(valueInfo.Domain, "http://", "", -1)
|
||||
}
|
||||
|
||||
if value, ok := lanpageMap[domain]; ok {
|
||||
value.Minute += 1
|
||||
} else {
|
||||
lanpageMap[domain] = &LanpageMonitor{
|
||||
Minute: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastDayEnd := time.Now().AddDate(0, 0, -1)
|
||||
lastDayStart := lastDayEnd.Add(-30 * time.Minute)
|
||||
|
||||
LastDownloadList, serr := downloadinfo.GetAccessCountByTime(ctx, appid, lastDayStart, lastDayEnd)
|
||||
if serr != nil {
|
||||
log.Error("RunMonitor, GetAccessCountByTime", log.E(serr))
|
||||
return ""
|
||||
}
|
||||
for _, valueInfo := range LastDownloadList {
|
||||
if len(valueInfo.Domain) > 0 {
|
||||
domain := valueInfo.Domain
|
||||
if strings.Contains(valueInfo.Domain, "https://") {
|
||||
domain = strings.Replace(valueInfo.Domain, "https://", "", -1)
|
||||
} else if strings.Contains(valueInfo.Domain, "http://") {
|
||||
domain = strings.Replace(valueInfo.Domain, "http://", "", -1)
|
||||
}
|
||||
|
||||
if value, ok := lanpageMap[domain]; ok {
|
||||
value.LastDay += 1
|
||||
} else {
|
||||
lanpageMap[domain] = &LanpageMonitor{
|
||||
LastDay: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 整理渠道数据
|
||||
tgTxt := "落地页监控:\n"
|
||||
// tgTxt += fmt.Sprintf("开始: %s\n结束: %s\n", start.Format("2006-01-02T15:04:05"), end.Format("2006-01-02T15:04:05"))
|
||||
for _, lanpage := range lanpages {
|
||||
for k, value := range lanpageMap {
|
||||
if k == lanpage {
|
||||
message := fmt.Sprintf("%s: 当日:%d 昨日:%d\n", k, value.Minute, value.LastDay)
|
||||
tgTxt += message
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(lanpageMap) > 0 {
|
||||
return tgTxt
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func ChannelMonitor() string {
|
||||
ctx := context.Background()
|
||||
appid := int32(888) // 麻豆
|
||||
end := time.Now()
|
||||
start := end.Add(-30 * time.Minute)
|
||||
lastDayEnd := time.Now().AddDate(0, 0, -1)
|
||||
lastDayStart := lastDayEnd.Add(-30 * time.Minute)
|
||||
|
||||
channelMap := make(map[string]*LanpageMonitor)
|
||||
for _, channelinfo := range channels {
|
||||
registerList, err := registermod.RegisterUsersInfoByDistrict(ctx, appid, channelinfo, start, end)
|
||||
if err != nil {
|
||||
log.Error("NewCountMethod RegisterUsersInfoByDistrict ", log.E(err))
|
||||
return ""
|
||||
}
|
||||
|
||||
for _, valueInfo := range registerList {
|
||||
if valueInfo.IsDirect {
|
||||
if value, ok := channelMap[valueInfo.DistrictCode]; ok {
|
||||
value.Minute += 1
|
||||
} else {
|
||||
channelMap[valueInfo.DistrictCode] = &LanpageMonitor{
|
||||
Minute: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LastDayRegisterList, err := registermod.RegisterUsersInfoByDistrict(ctx, appid, channelinfo, lastDayStart, lastDayEnd)
|
||||
if err != nil {
|
||||
log.Error("NewCountMethod RegisterUsersInfoByDistrict ", log.E(err))
|
||||
return ""
|
||||
}
|
||||
|
||||
for _, valueInfo := range LastDayRegisterList {
|
||||
if valueInfo.IsDirect {
|
||||
if value, ok := channelMap[valueInfo.DistrictCode]; ok {
|
||||
value.LastDay += 1
|
||||
} else {
|
||||
channelMap[valueInfo.DistrictCode] = &LanpageMonitor{
|
||||
LastDay: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 自来量
|
||||
fissionCount, err := registermod.FissionAddUserCount(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("NewCountMethod RegisterUsersInfoByDistrict ", log.E(err))
|
||||
return ""
|
||||
}
|
||||
|
||||
LastDayFissionCount, err := registermod.FissionAddUserCount(ctx, appid, lastDayStart, lastDayEnd)
|
||||
if err != nil {
|
||||
log.Error("NewCountMethod RegisterUsersInfoByDistrict ", log.E(err))
|
||||
return ""
|
||||
}
|
||||
|
||||
channelMap["裂变"] = &LanpageMonitor{
|
||||
LastDay: LastDayFissionCount,
|
||||
Minute: fissionCount,
|
||||
}
|
||||
|
||||
// 整理渠道数据
|
||||
tgTxt := "麻豆渠道监控:\n"
|
||||
// tgTxt += fmt.Sprintf("开始: %s\n结束: %s\n", start.Format("2006-01-02T15:04:05"), end.Format("2006-01-02T15:04:05"))
|
||||
for k, value := range channelMap {
|
||||
if channelmod.IsOfficialChannelName(k) {
|
||||
k = "自来量"
|
||||
}
|
||||
message := fmt.Sprintf("%s: 当日:%d 昨日:%d\n", k, value.Minute, value.LastDay)
|
||||
tgTxt += message
|
||||
}
|
||||
if len(channelMap) > 0 {
|
||||
return tgTxt
|
||||
}
|
||||
|
||||
// 统计数据
|
||||
return ""
|
||||
}
|
||||
|
||||
func NewCountMonitor() error {
|
||||
ctx := context.Background()
|
||||
end := time.Now()
|
||||
start := end.Add(-time.Minute * 10)
|
||||
|
||||
appIds := []int32{999, 694, 594, 494, 888, 444, 66666}
|
||||
|
||||
for _, appid := range appIds {
|
||||
iosCount, err := registermod.IosAddUserCount(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("DirectVisitCountMethod IosAddUserCount", log.E(err))
|
||||
return err
|
||||
}
|
||||
androidCount, err := registermod.AndroidAddUserCount(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("DirectVisitCountMethod IosAddUserCount", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if statg.Conf.RunMod == consts.RunModRelease {
|
||||
if androidCount <= 10 || iosCount <= 5 {
|
||||
appinfo, _ := appInfoMod.GetAppInfoById(ctx, appid)
|
||||
// 必须存在
|
||||
if appinfo.AppId == appid {
|
||||
text := fmt.Sprintf("[警告]:应用名称:%s\n2分钟新增异常:\n时间:%s\nandroid:%d\nios:%d\n", appinfo.Name, start, androidCount, iosCount)
|
||||
err = statg.Bot.SendMonitorMessage(text)
|
||||
if err != nil {
|
||||
log.Error("tg Send ", log.E(err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user