Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AppMonitorSubscriber
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nongyingchen
AppMonitorSubscriber
Commits
d5aa9d35
Commit
d5aa9d35
authored
Jul 14, 2019
by
trace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加在线时长计数
parent
150b64f6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
123 additions
and
10 deletions
+123
-10
play.js
+123
-10
No files found.
play.js
View file @
d5aa9d35
...
@@ -13,7 +13,7 @@ let release = `<div><br/>
...
@@ -13,7 +13,7 @@ let release = `<div><br/>
// 依赖
// 依赖
var
gplay
=
require
(
'google-play-scraper'
)
var
gplay
=
require
(
'google-play-scraper'
)
var
nodemailer
=
require
(
'nodemailer'
)
var
nodemailer
=
require
(
'nodemailer'
)
//
var moment = require('moment')
var
moment
=
require
(
'moment'
)
let
developer
=
[
'yingchen.nong@starwin.com'
]
let
developer
=
[
'yingchen.nong@starwin.com'
]
let
notifyEmail
=
developer
let
notifyEmail
=
developer
...
@@ -239,10 +239,18 @@ function generateDailyOnlineReport() {
...
@@ -239,10 +239,18 @@ function generateDailyOnlineReport() {
let
daichaoOnlines
=
daichaoApps
.
filter
(
val
=>
status
[
val
]
&&
status
[
val
].
status
||
false
)
let
daichaoOnlines
=
daichaoApps
.
filter
(
val
=>
status
[
val
]
&&
status
[
val
].
status
||
false
)
let
daichaoOfflines
=
daichaoApps
.
filter
(
val
=>
!
daichaoOnlines
.
includes
(
val
))
let
daichaoOfflines
=
daichaoApps
.
filter
(
val
=>
!
daichaoOnlines
.
includes
(
val
))
let
content
=
''
let
content
=
''
content
+=
wrapSummary
(
`Gitlab 在线 app (
${
onlineApps
.
length
}
/
${
ourAppIds
.
length
}
)`
,
onlineApps
.
map
(
val
=>
link
(
val
)),
'green'
)
let
calTime
=
(
val
)
=>
{
content
+=
wrapSummary
(
`Gitlab 下线 app (
${
offlineApps
.
length
}
/
${
ourAppIds
.
length
}
)`
,
offlineApps
.
map
(
val
=>
link
(
val
)),
'red'
)
return
`<br/>在线:
${
status
[
val
].
onlineDuration
}
| 下线:
${
status
[
val
].
offlineDuration
}
`
content
+=
wrapSummary
(
`贷超在线 App (
${
daichaoOnlines
.
length
}
/
${
daichaoApps
.
length
}
)`
,
daichaoOnlines
.
map
(
val
=>
link
(
val
)),
'green'
)
}
content
+=
wrapSummary
(
`贷超下线 App (
${
daichaoOfflines
.
length
}
/
${
daichaoApps
.
length
}
)`
,
daichaoOfflines
.
map
(
val
=>
link
(
val
)),
'red'
)
content
+=
wrapSummary
(
`Gitlab 在线 app (
${
onlineApps
.
length
}
/
${
ourAppIds
.
length
}
)`
,
onlineApps
.
map
(
val
=>
link
(
val
)
+
calTime
(
val
)),
'green'
)
content
+=
'在线时长情况:'
content
+=
rankOnlineTime
(
onlineApps
)
content
+=
wrapSummary
(
`Gitlab 下线 app (
${
offlineApps
.
length
}
/
${
ourAppIds
.
length
}
)`
,
offlineApps
.
map
(
val
=>
link
(
val
)
+
calTime
(
val
)),
'red'
)
content
+=
'<br/><br/>贷超------------------------------'
content
+=
wrapSummary
(
`贷超在线 App (
${
daichaoOnlines
.
length
}
/
${
daichaoApps
.
length
}
)`
,
daichaoOnlines
.
map
(
val
=>
link
(
val
)
+
calTime
(
val
)),
'green'
)
content
+=
'在线时长情况:'
content
+=
rankOnlineTime
(
daichaoOnlines
)
content
+=
wrapSummary
(
`贷超下线 App (
${
daichaoOfflines
.
length
}
/
${
daichaoApps
.
length
}
)`
,
daichaoOfflines
.
map
(
val
=>
link
(
val
)
+
calTime
(
val
)),
'red'
)
return
content
return
content
}
}
...
@@ -461,21 +469,51 @@ async function monitorIfOnline(names) {
...
@@ -461,21 +469,51 @@ async function monitorIfOnline(names) {
await
gplay
.
app
({
appId
:
name
,
requestOptions
:
{
timeout
:
requestTimeout
}
})
await
gplay
.
app
({
appId
:
name
,
requestOptions
:
{
timeout
:
requestTimeout
}
})
.
then
((
val
)
=>
{
.
then
((
val
)
=>
{
log
(
`获取到(
${
status
[
name
]
&&
status
[
name
].
category
||
'noType'
}
):
${
name
}
`
)
log
(
`获取到(
${
status
[
name
]
&&
status
[
name
].
category
||
'noType'
}
):
${
name
}
`
)
judgeNewOnline
(
name
)
// judgePermissionChanged(name, val)
// judgePermissionChanged(name, val)
// 第一次运行上下架时长功能时没有 updated 字段, 使用gp 最近更新时间
if
(
!
(
status
[
name
]
&&
status
[
name
].
updated
))
{
status
[
name
]
=
{
...(
status
[
name
]
||
{}),
updated
:
val
.
updated
}
}
// 标记 gp 更新时间, 普通更新不会计入, 下了再上的会重置更新时间
if
(
judgeNewOnline
(
name
))
{
status
[
name
]
=
{
...(
status
[
name
]
||
{}),
updated
:
val
.
updated
,
onlineDuration
:
calDuration
(
moment
.
now
(),
(
status
[
name
]
&&
status
[
name
].
updated
||
moment
.
now
())),
}
}
else
{
// 非新上架, 一直在线, 统计在线时长
status
[
name
]
=
{
...(
status
[
name
]
||
{}),
onlineDuration
:
calDuration
(
moment
.
now
(),
(
status
[
name
]
&&
status
[
name
].
updated
||
moment
.
now
()))
}
}
status
[
name
]
=
{
status
[
name
]
=
{
...(
status
[
name
]
||
{}),
...(
status
[
name
]
||
{}),
// permissions: val,
// permissions: val,
status
:
true
,
status
:
true
,
date
:
Date
().
toString
()
date
:
Date
().
toString
()
,
}
}
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
if
(
err
.
toString
().
includes
(
'404'
))
{
if
(
err
.
toString
().
includes
(
'404'
))
{
log
(
`获取不到:
${
name
}
, error:
${
err
}
`
,
true
)
log
(
`获取不到:
${
name
}
, error:
${
err
}
`
,
true
)
failedApps
.
push
(
name
)
failedApps
.
push
(
name
)
judgeNewOffline
(
name
)
let
a
=
status
[
name
]
||
{}
let
a
=
status
[
name
]
||
{}
// 记录被下架时间
if
(
judgeNewOffline
(
name
))
{
status
[
name
]
=
{
...
a
,
offlineDuration
:
0
,
offlineDate
:
moment
.
now
()
}
}
else
{
// 一直在下架状态, 统计下架持续时间
status
[
name
]
=
{
...
a
,
offlineDuration
:
calDuration
(
moment
.
now
(),
(
status
[
name
].
offlineDate
||
moment
.
now
()))
}
}
a
=
status
[
name
]
||
{}
status
[
name
]
=
{
...
a
,
status
:
false
,
date
:
Date
().
toString
()
}
status
[
name
]
=
{
...
a
,
status
:
false
,
date
:
Date
().
toString
()
}
}
else
if
(
err
.
toString
().
includes
(
'ETIMEDOUT'
))
{
}
else
if
(
err
.
toString
().
includes
(
'ETIMEDOUT'
))
{
log
(
`连接超时:
${
err
.
toString
()}
`
,
true
)
log
(
`连接超时:
${
err
.
toString
()}
`
,
true
)
...
@@ -622,7 +660,7 @@ function genMail() {
...
@@ -622,7 +660,7 @@ function genMail() {
newOffline
.
forEach
(
name
=>
{
newOffline
.
forEach
(
name
=>
{
let
his
=
(
status
[
name
]
&&
status
[
name
].
permissionHis
&&
status
[
name
].
permissionHis
)
||
{}
let
his
=
(
status
[
name
]
&&
status
[
name
].
permissionHis
&&
status
[
name
].
permissionHis
)
||
{}
his
.
lastPermissions
=
(
status
[
name
]
&&
status
[
name
].
permissions
&&
status
[
name
].
permissions
)
||
[]
his
.
lastPermissions
=
(
status
[
name
]
&&
status
[
name
].
permissions
&&
status
[
name
].
permissions
)
||
[]
emailContent
+=
getPermissionChangeContent
(
name
,
his
,
`新下架ಥ_ಥ(及上次权限情况)`
,
'下'
)
emailContent
+=
getPermissionChangeContent
(
name
,
his
,
`新下架ಥ_ಥ(及上次权限情况)
[上次在线持续:
${
status
[
name
].
onlineDuration
||
0
}
]
`
,
'下'
)
// emailContent += `<div>检测到新下架ಥ_ಥ: ${link(name)}</div>`
// emailContent += `<div>检测到新下架ಥ_ಥ: ${link(name)}</div>`
})
})
emailContent
+=
`<br/>/>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br/>`
emailContent
+=
`<br/>/>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br/>`
...
@@ -638,7 +676,7 @@ function genMail() {
...
@@ -638,7 +676,7 @@ function genMail() {
emailContent
+=
`<br/>/>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br/>`
emailContent
+=
`<br/>/>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br/>`
delete
permissionChange
[
name
]
delete
permissionChange
[
name
]
}
else
{
}
else
{
emailContent
+=
wrapSummary
(
`<div>新上架^_^
:
${
link
(
name
,
"上"
)}
</div>`
,
emailContent
+=
wrapSummary
(
`<div>新上架^_^
[上次下架持续时间:
${
status
[
name
].
offlineDuration
||
0
}
]: <br/>
${
link
(
name
,
"上"
)}
</div>`
,
((
status
[
name
]
&&
status
[
name
].
permissions
&&
status
[
name
].
permissions
)
||
[]))
((
status
[
name
]
&&
status
[
name
].
permissions
&&
status
[
name
].
permissions
)
||
[]))
emailContent
+=
`<br/>/>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br/>`
emailContent
+=
`<br/>/>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br/>`
}
}
...
@@ -669,6 +707,11 @@ function genMail() {
...
@@ -669,6 +707,11 @@ function genMail() {
status
.
sendListDate
=
today
.
toString
()
status
.
sendListDate
=
today
.
toString
()
}
}
// 发送在线时长情况
// emailContent += '<br/><br/><br/>'
// emailContent += '在线时长情况:'
// emailContent += rankOnlineTime()
// 有变化也发送当前监控在线情况
// 有变化也发送当前监控在线情况
emailContent
+=
'<br/><br/><br/>'
emailContent
+=
'<br/><br/><br/>'
emailContent
+=
'在线/下线 情况:'
emailContent
+=
'在线/下线 情况:'
...
@@ -868,17 +911,23 @@ function sleep(ms) {
...
@@ -868,17 +911,23 @@ function sleep(ms) {
return
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
ms
));
return
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
ms
));
}
}
function
judgeNewOnline
(
name
)
{
function
judgeNewOnline
(
name
)
{
log
(
`判断
${
name
}
是否新上架`
)
if
(
status
[
name
]
&&
status
[
name
].
status
==
false
)
{
if
(
status
[
name
]
&&
status
[
name
].
status
==
false
)
{
log
(
`
${
name
}
新上架 😃`
)
log
(
`
${
name
}
新上架 😃`
)
newOnline
.
push
(
name
)
newOnline
.
push
(
name
)
return
true
}
}
return
false
}
}
function
judgeNewOffline
(
name
)
{
function
judgeNewOffline
(
name
)
{
log
(
`判断
${
name
}
是否新下架`
)
if
(
status
[
name
]
&&
status
[
name
].
status
==
true
)
{
if
(
status
[
name
]
&&
status
[
name
].
status
==
true
)
{
log
(
`
${
name
}
被下架了 ಥ_ಥ`
)
log
(
`
${
name
}
被下架了 ಥ_ಥ`
)
newOffline
.
push
(
name
)
newOffline
.
push
(
name
)
return
true
}
}
return
false
}
}
function
judgePermissionChanged
(
name
,
newPermission
)
{
function
judgePermissionChanged
(
name
,
newPermission
)
{
...
@@ -950,3 +999,67 @@ function isInTimeInRangeToday(start, end) {
...
@@ -950,3 +999,67 @@ function isInTimeInRangeToday(start, end) {
return
false
return
false
}
}
function
getMoment
(
timestamp
)
{
return
moment
(
timestamp
)
}
function
calDuration
(
laterTime
,
updateTime
,
unit
=
'day'
)
{
let
duration
=
getMoment
(
laterTime
).
diff
(
getMoment
(
updateTime
),
unit
)
let
ret
=
`
${
duration
}
天`
if
(
unit
==
'day'
&&
duration
==
0
)
{
duration
=
getMoment
(
laterTime
).
diff
(
getMoment
(
updateTime
),
'hours'
)
ret
=
`
${
duration
}
小时`
}
return
ret
}
function
rankOnlineTime
(
apps
)
{
let
rankApps
=
apps
||
ourAppIds
.
filter
(
val
=>
status
[
val
]
&&
status
[
val
].
status
||
false
)
let
onlineApps
=
rankApps
let
day30Up
=
[]
let
day14_30
=
[]
let
day5_14
=
[]
let
day5Down
=
[]
let
day1
=
[]
for
(
id
of
onlineApps
)
{
let
duration
=
status
[
id
].
onlineDuration
||
'0 小时'
durations
=
duration
.
split
(
' '
)
duration
=
durations
[
0
]
let
unit
=
durations
[
1
]
if
(
unit
==
'天'
)
{
if
(
duration
>=
30
)
{
day30Up
=
day30Up
.
concat
({
id
,
duration
})
}
else
if
(
duration
>=
14
&&
duration
<
30
)
{
day14_30
=
day14_30
.
concat
({
id
,
duration
})
}
else
if
(
duration
>=
5
&&
duration
<
14
)
{
day5_14
=
day5_14
.
concat
({
id
,
duration
})
}
else
{
day5Down
=
day5Down
.
concat
({
id
,
duration
})
}
}
else
{
day1
=
day1
.
concat
({
id
,
duration
})
}
}
let
sortFoo
=
(
val1
,
val2
)
=>
{
return
val2
.
duration
-
val1
.
duration
}
day30Up
=
day30Up
.
sort
(
sortFoo
).
map
(
val
=>
val
.
id
)
day14_30
=
day14_30
.
sort
(
sortFoo
).
map
(
val
=>
val
.
id
)
day5_14
=
day5_14
.
sort
(
sortFoo
).
map
(
val
=>
val
.
id
)
day5Down
=
day5Down
.
sort
(
sortFoo
).
map
(
val
=>
val
.
id
)
day1
=
day1
.
sort
(
sortFoo
).
map
(
val
=>
val
.
id
)
let
calTime
=
(
val
)
=>
{
return
`<br/>在线时长:
${
status
[
val
].
onlineDuration
}
| 下线时长:
${
status
[
val
].
offlineDuration
}
`
}
let
content
=
''
content
+=
wrapSummary
(
`30天及以上app (
${
day30Up
.
length
}
/
${
ourAppIds
.
length
}
)`
,
day30Up
.
map
(
val
=>
link
(
val
)
+
calTime
(
val
)),
'green'
)
content
+=
wrapSummary
(
`[14, 30)天app (
${
day14_30
.
length
}
/
${
ourAppIds
.
length
}
)`
,
day14_30
.
map
(
val
=>
link
(
val
)
+
calTime
(
val
)),
'green'
)
content
+=
wrapSummary
(
`[5, 14)天app (
${
day5_14
.
length
}
/
${
ourAppIds
.
length
}
)`
,
day5_14
.
map
(
val
=>
link
(
val
)
+
calTime
(
val
)),
'green'
)
content
+=
wrapSummary
(
`[1, 5)天app (
${
day5Down
.
length
}
/
${
ourAppIds
.
length
}
)`
,
day5Down
.
map
(
val
=>
link
(
val
)
+
calTime
(
val
)),
'green'
)
content
+=
wrapSummary
(
`[0, 1)天app (
${
day1
.
length
}
/
${
ourAppIds
.
length
}
)`
,
day1
.
map
(
val
=>
link
(
val
)
+
calTime
(
val
)),
'green'
)
return
content
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment