-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAppClientCostTimeTotalStatDao.xml
More file actions
64 lines (59 loc) · 4.51 KB
/
AppClientCostTimeTotalStatDao.xml
File metadata and controls
64 lines (59 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sohu.cache.dao.AppClientCostTimeTotalStatDao">
<sql id="columns">
app_id,collect_time,create_time,command,mean,median,ninety_percent_max,ninety_nine_percent_max,
hundred_max,total_cost,total_count,max_instance_host,max_instance_port,max_instance_id,max_client_ip,accumulation
</sql>
<insert id="save" parameterType="AppClientCostTimeTotalStat" keyProperty="id" useGeneratedKeys="true">
insert into app_client_costtime_minute_stat_total
(<include refid="columns"/>)
values
(#{appId},#{collectTime},#{createTime},#{command},${mean},#{median},
#{ninetyPercentMax},#{ninetyNinePercentMax},#{hundredMax},#{totalCost},#{totalCount},#{maxInstanceHost},#{maxInstancePort},#{maxInstanceId},#{maxClientIp}, 1)
on duplicate key update
total_cost = total_cost + #{totalCost},
total_count = total_count + #{totalCount},
median = if(median>#{median},median,#{median}),
ninety_percent_max = if(ninety_percent_max>#{ninetyPercentMax},ninety_percent_max,#{ninetyPercentMax}),
ninety_nine_percent_max = if(ninety_nine_percent_max>#{ninetyNinePercentMax},ninety_nine_percent_max,#{ninetyNinePercentMax}),
hundred_max = if(hundred_max>#{hundredMax},hundred_max,#{hundredMax}),
max_instance_host = if(hundred_max>#{hundredMax},max_instance_host,#{maxInstanceHost}),
max_instance_port = if(hundred_max>#{hundredMax},max_instance_port,#{maxInstancePort}),
max_instance_id = if(hundred_max>#{hundredMax},max_instance_id,#{maxInstanceId}),
max_client_ip = if(hundred_max>#{hundredMax},max_client_ip,#{maxClientIp}),
mean = CONVERT(total_cost/total_count,DECIMAL(12,2)),
create_time = now(),
accumulation = accumulation + 1;
</insert>
<insert id="batchSave">
insert into app_client_costtime_minute_stat_total(<include refid="columns"/>)
values
<foreach collection="appClientCostTimeTotalStatList" item="clientCostTime" separator=",">
(#{clientCostTime.appId},#{clientCostTime.collectTime},#{clientCostTime.createTime},#{clientCostTime.command},${clientCostTime.mean},#{clientCostTime.median},
#{clientCostTime.ninetyPercentMax},#{clientCostTime.ninetyNinePercentMax},#{clientCostTime.hundredMax},#{clientCostTime.totalCost},#{clientCostTime.totalCount},#{clientCostTime.maxInstanceHost},#{clientCostTime.maxInstancePort},#{clientCostTime.maxInstanceId},#{clientCostTime.maxClientIp}, 1)
</foreach>
on duplicate key update
total_cost = total_cost + #{clientCostTime.totalCost},
total_count = total_count + #{clientCostTime.totalCount},
median = if(median>#{clientCostTime.median},median,#{clientCostTime.median}),
ninety_percent_max = if(ninety_percent_max>#{clientCostTime.ninetyPercentMax},ninety_percent_max,#{clientCostTime.ninetyPercentMax}),
ninety_nine_percent_max = if(ninety_nine_percent_max>#{clientCostTime.ninetyNinePercentMax},ninety_nine_percent_max,#{clientCostTime.ninetyNinePercentMax}),
hundred_max = if(hundred_max>#{clientCostTime.hundredMax},hundred_max,#{clientCostTime.hundredMax}),
max_instance_host = if(hundred_max>#{clientCostTime.hundredMax},max_instance_host,#{clientCostTime.maxInstanceHost}),
max_instance_port = if(hundred_max>#{clientCostTime.hundredMax},max_instance_port,#{clientCostTime.maxInstancePort}),
max_instance_id = if(hundred_max>#{clientCostTime.hundredMax},max_instance_id,#{clientCostTime.maxInstanceId}),
max_client_ip = if(hundred_max>#{clientCostTime.hundredMax},max_client_ip,#{clientCostTime.maxClientIp}),
mean = CONVERT(total_cost/total_count,DECIMAL(12,2)),
create_time = now(),
accumulation = accumulation + 1;
</insert>
<select id="getAppDistinctCommand" resultType="string">
select command from app_client_costtime_minute_stat_total where app_id=#{appId} and collect_time between #{startTime} and #{endTime} group by command order by sum(total_count) desc;
</select>
<select id="getAppClientCommandStat" resultType="AppClientCostTimeTotalStat">
select id,<include refid="columns"/> from app_client_costtime_minute_stat_total
where app_id=#{appId} and collect_time between #{startTime} and #{endTime} and command=#{command}
</select>
</mapper>