Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
flink-monitor
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵建伟
flink-monitor
Commits
2fb0f6f1
Commit
2fb0f6f1
authored
Mar 19, 2020
by
赵建伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update codes
parent
a9e7cbb1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
9 deletions
+91
-9
PortraitMonitorMain.java
src/main/java/com/gmei/data/monitor/PortraitMonitorMain.java
+3
-2
PortraitMonitorErrOperator.java
...mei/data/monitor/operator/PortraitMonitorErrOperator.java
+25
-2
PortraitMonitorShdOperator.java
...mei/data/monitor/operator/PortraitMonitorShdOperator.java
+0
-0
PortraitMonitorSucOperator.java
...mei/data/monitor/operator/PortraitMonitorSucOperator.java
+11
-3
DateUtils.java
src/main/java/com/gmei/data/monitor/utils/DateUtils.java
+52
-2
No files found.
src/main/java/com/gmei/data/monitor/PortraitMonitorMain.java
View file @
2fb0f6f1
...
...
@@ -36,7 +36,7 @@ public class PortraitMonitorMain {
String
portraitErrGroupId
=
parameterTool
.
get
(
"portraitErrGroupId"
,
"flink_monitor_err"
);
String
portraitShdGroupId
=
parameterTool
.
get
(
"portraitShdGroupId"
,
"flink_monitor_shd"
);
String
portraitSucGroupId
=
parameterTool
.
get
(
"portraitSucGroupId"
,
"flink_monitor_suc"
);
Integer
windowSize
=
parameterTool
.
getInt
(
"windowSize"
,
3
);
Integer
windowSize
=
parameterTool
.
getInt
(
"windowSize"
,
60000
);
Integer
slideSize
=
parameterTool
.
getInt
(
"slideSize"
,
3
);
String
outJdbcUrl
=
parameterTool
.
get
(
"outJdbcUrl"
,
"jdbc:mysql://test002:3306/flink_monitor?user=root&password=5OqYM^zLwotJ3oSo&autoReconnect=true&useSSL=false"
);
...
...
@@ -49,13 +49,14 @@ public class PortraitMonitorMain {
// 获得流处理环境对象
StreamExecutionEnvironment
env
=
StreamExecutionEnvironment
.
getExecutionEnvironment
();
env
.
setStreamTimeCharacteristic
(
TimeCharacteristic
.
EventTime
);
env
.
enableCheckpointing
(
1000
);
env
.
setStateBackend
(
new
FsStateBackend
(
checkpointPath
));
env
.
setRestartStrategy
(
RestartStrategies
.
fixedDelayRestart
(
1
,
3000
));
CheckpointConfig
config
=
env
.
getCheckpointConfig
();
config
.
enableExternalizedCheckpoints
(
CheckpointConfig
.
ExternalizedCheckpointCleanup
.
RETAIN_ON_CANCELLATION
);
// env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
// 获取数据源
DataStream
portraitErrDataStream
=
new
PortraitKafkaSource
(
...
...
src/main/java/com/gmei/data/monitor/operator/PortraitMonitorErrOperator.java
View file @
2fb0f6f1
...
...
@@ -8,8 +8,11 @@ import org.apache.flink.api.common.functions.FilterFunction;
import
org.apache.flink.api.common.functions.MapFunction
;
import
org.apache.flink.api.java.tuple.Tuple2
;
import
org.apache.flink.streaming.api.datastream.DataStream
;
import
org.joda.time.format.DateTimeFormatter
;
import
org.joda.time.format.ISODateTimeFormat
;
import
java.util.Arrays
;
import
java.util.Date
;
/**
* @ClassName PortraitMonitorErr
...
...
@@ -24,6 +27,8 @@ public class PortraitMonitorErrOperator implements BaseOperator{
private
int
maxRetry
;
private
long
retryInteral
;
private
int
parallelism
;
public
static
final
DateTimeFormatter
dateTimeFormat
=
ISODateTimeFormat
.
dateTime
();
public
static
final
DateTimeFormatter
dateTimeNoMillisFormat
=
ISODateTimeFormat
.
dateTimeNoMillis
();
public
PortraitMonitorErrOperator
(
DataStream
dataStream
,
String
outJdbcUrl
,
int
maxRetry
,
long
retryInteral
,
int
parallelism
)
{
this
.
dataStream
=
dataStream
;
...
...
@@ -104,8 +109,26 @@ public class PortraitMonitorErrOperator implements BaseOperator{
.
map
(
new
MapFunction
<
String
,
Tuple2
<
String
,
String
>>()
{
@Override
public
Tuple2
<
String
,
String
>
map
(
String
value
)
throws
Exception
{
String
monitorTime
=
DateUtils
.
getCurrentTimeStr
();
return
new
Tuple2
<>(
value
,
monitorTime
);
long
logTime
=
0
;
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
value
);
String
maidianEventTime
=
jsonObject
.
getString
(
"create_at"
);
if
(
StringUtils
.
isNotBlank
(
maidianEventTime
)){
logTime
=
Long
.
valueOf
(
maidianEventTime
);
}
String
backendEventTime
=
jsonObject
.
getString
(
"TIME"
);
if
(
StringUtils
.
isNotBlank
(
backendEventTime
)){
try
{
logTime
=
dateTimeFormat
.
parseMillis
(
backendEventTime
)/
1000
;
}
catch
(
IllegalArgumentException
e
)
{
try
{
logTime
=
dateTimeNoMillisFormat
.
parseMillis
(
backendEventTime
)/
1000
;
}
catch
(
IllegalArgumentException
e2
)
{
e2
.
printStackTrace
();
}
}
}
String
eventTime
=
DateUtils
.
secondToDate
(
logTime
);
return
new
Tuple2
<>(
value
,
eventTime
);
}
})
.
addSink
(
new
PortraitErrMysqlSink
(
outJdbcUrl
,
maxRetry
,
retryInteral
))
...
...
src/main/java/com/gmei/data/monitor/operator/PortraitMonitorShdOperator.java
View file @
2fb0f6f1
This diff is collapsed.
Click to expand it.
src/main/java/com/gmei/data/monitor/operator/PortraitMonitorSucOperator.java
View file @
2fb0f6f1
...
...
@@ -16,6 +16,8 @@ import org.apache.flink.streaming.api.windowing.time.Time;
import
org.apache.flink.streaming.api.windowing.windows.TimeWindow
;
import
org.apache.flink.util.Collector
;
import
java.util.Date
;
/**
* @ClassName PortraitMonitorSucOperator
* @Description: 用户画像成功打点数监控
...
...
@@ -77,11 +79,17 @@ public class PortraitMonitorSucOperator implements BaseOperator{
@Override
public
void
process
(
Tuple
key
,
Context
context
,
Iterable
<
GmPortraitResult
>
elements
,
Collector
<
TblMonitorPortraitSuc
>
out
)
{
Integer
count
=
0
;
Date
date
=
new
Date
();
long
currentTimestamp
=
DateUtils
.
getCurrentTimestamp
(
date
);
long
tenMinitesAgoTimestamp
=
DateUtils
.
getTenMinitesAgoTimestamp
(
date
);
for
(
GmPortraitResult
element
:
elements
)
{
++
count
;
long
logTime
=
Long
.
valueOf
(
element
.
getLog_time
());
if
(
logTime
>=
tenMinitesAgoTimestamp
&&
logTime
<=
currentTimestamp
){
++
count
;
}
}
String
monitorTime
=
DateUtils
.
getCurrentTimeStr
(
);
TblMonitorPortraitSuc
tblMonitorPortraitSuc
=
new
TblMonitorPortraitSuc
(
key
.
getField
(
0
),
count
,
monitorTime
);
String
currentTimeStr
=
DateUtils
.
getCurrentTimeStr
(
date
);
TblMonitorPortraitSuc
tblMonitorPortraitSuc
=
new
TblMonitorPortraitSuc
(
key
.
getField
(
0
),
count
,
currentTimeStr
);
out
.
collect
(
tblMonitorPortraitSuc
);
}
})
...
...
src/main/java/com/gmei/data/monitor/utils/DateUtils.java
View file @
2fb0f6f1
...
...
@@ -2,6 +2,7 @@ package com.gmei.data.monitor.utils;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
/**
...
...
@@ -17,10 +18,45 @@ public class DateUtils {
/**
* 获取当前时间字符串
* @param date
* @return
*/
public
static
String
getCurrentTimeStr
()
{
return
new
SimpleDateFormat
(
DATE_FORMATE_YMDHMS
).
format
(
new
Date
());
public
static
String
getCurrentTimeStr
(
Date
date
)
{
return
new
SimpleDateFormat
(
DATE_FORMATE_YMDHMS
).
format
(
date
);
}
/**
* 获取十分钟以前的时间字符串
* @param date
* @return
*/
public
static
String
getTenMinitesAgoTimeStr
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
add
(
Calendar
.
MINUTE
,-
10
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
DATE_FORMATE_YMDHMS
);
return
sdf
.
format
(
calendar
.
getTime
());
}
/**
* 获取当前时间戳
* @param date
* @return
*/
public
static
long
getCurrentTimestamp
(
Date
date
)
{
return
date
.
getTime
();
}
/**
* 获取十分钟以前的时间戳
* @param date
* @return
*/
public
static
long
getTenMinitesAgoTimestamp
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
add
(
Calendar
.
MINUTE
,-
10
);
return
calendar
.
getTime
().
getTime
();
}
/**
...
...
@@ -33,4 +69,18 @@ public class DateUtils {
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
DATE_FORMATE_YMDHMS
);
return
simpleDateFormat
.
parse
(
dateStr
).
getTime
();
}
/**
* 将秒值转为指定格式的日期
* @param second
* @return
*/
public
static
String
secondToDate
(
long
second
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTimeInMillis
(
second
*
1000
);
Date
date
=
calendar
.
getTime
();
SimpleDateFormat
format
=
new
SimpleDateFormat
(
DATE_FORMATE_YMDHMS
);
String
dateString
=
format
.
format
(
date
);
return
dateString
;
}
}
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