Skip to content

Commit

Permalink
Fix avgElapsed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhiguo.Chen committed Aug 20, 2015
1 parent 48fc23a commit 3a36945
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright 2006-2015 handu.com
*
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -23,9 +23,9 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
Expand All @@ -43,6 +43,10 @@ public class StatisticsController {

@RequestMapping()
public String index(@ModelAttribute DubboInvoke dubboInvoke, Model model) {
// Set default Search Date
if (dubboInvoke.getInvokeDate() == null && dubboInvoke.getInvokeDateFrom() == null && dubboInvoke.getInvokeDateTo() == null) {
dubboInvoke.setInvokeDate(new Date());
}
//获取Service方法
List<String> methods = dubboMonitorService.getMethodsByService(dubboInvoke);
List<DubboInvoke> dubboInvokes;
Expand All @@ -60,7 +64,7 @@ public String index(@ModelAttribute DubboInvoke dubboInvoke, Model model) {
}
dubboStatistics.setProviderSuccess(di.getSuccess());
dubboStatistics.setProviderFailure(di.getFailure());
dubboStatistics.setProviderAvgElapsed(di.getElapsed());
dubboStatistics.setProviderAvgElapsed(di.getSuccess() != 0 ? di.getElapsed() / di.getSuccess() : 0);
dubboStatistics.setProviderMaxElapsed(di.getMaxElapsed());
dubboStatistics.setProviderMaxConcurrent(di.getMaxConcurrent());
}
Expand All @@ -72,7 +76,7 @@ public String index(@ModelAttribute DubboInvoke dubboInvoke, Model model) {
}
dubboStatistics.setConsumerSuccess(di.getSuccess());
dubboStatistics.setConsumerFailure(di.getFailure());
dubboStatistics.setConsumerAvgElapsed(di.getElapsed());
dubboStatistics.setConsumerAvgElapsed(di.getSuccess() != 0 ? di.getElapsed() / di.getSuccess() : 0);
dubboStatistics.setConsumerMaxElapsed(di.getMaxElapsed());
dubboStatistics.setConsumerMaxConcurrent(di.getMaxConcurrent());
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/mappers/DubboInvokeMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@
<if test="invokeDate != null">
AND invoke_date = DATE_FORMAT(#{invokeDate},'%Y-%m-%d')
</if>
<if test="invokeDateFrom != null">
AND dubbo_invoke.invoke_date &gt;= DATE_FORMAT(#{invokeDateFrom},'%Y-%m-%d')
</if>
<if test="invokeDateTo != null">
AND dubbo_invoke.invoke_date &lt;= DATE_FORMAT(#{invokeDateTo},'%Y-%m-%d')
</if>
<if test="service != null and service!= '' ">
AND service = #{service}
</if>
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/resources/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function loadChartsData() {
$.ajax({
type: "POST", url: "loadTopData", dataType: "json", data: {
"invokeDateFrom": new Date($('#invokeDateFrom').val() + ' 00:00:00'),
"invokeDateTo": new Date($('#invokeDateTo').val() + ' 23:59:59')
"invokeDateTo": new Date($('#invokeDateTo').val() + ' 23:59:59'),
"type": 'provider'
}, error: function (req, status, err) {
alert('Failed reason: ' + err);
}, success: function (data) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/resources/scripts/service/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function loadChartsData() {
$.ajax({
type: "POST", url: "services/charts/loadChartsData", dataType: "json", data: {
"service": $('#invokeSearchService').val(),
"invokeDateFrom": new Date($('#invokeDateFrom').val()),
"invokeDateTo": new Date($('#invokeDateTo').val())
"invokeDateFrom": new Date($('#invokeDateFrom').val() + ' 00:00:00'),
"invokeDateTo": new Date($('#invokeDateTo').val() + ' 23:59:59')
}, error: function (req, status, err) {
alert('Failed reason: ' + err);
}, success: function (data) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/resources/scripts/service/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ $(function () {
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}, format: dateFormat
}).on('apply.daterangepicker', function (ev, picker) {
dateFrom.val(new Date(picker.startDate.format(dateFormat)));
dateTo.val(new Date(picker.endDate.format(dateFormat)));
dateFrom.val(new Date(picker.startDate.format(dateFormat) + ' 00:00:00'));
dateTo.val(new Date(picker.endDate.format(dateFormat) + ' 23:59:59'));
//rangeSpan.text(dateFrom.val() + ' ~ ' + dateTo.val());
$("#statisticsSearchForm").submit();
});
dateFrom.val(new Date(moment().format(dateFormat)));
dateTo.val(new Date(moment().format(dateFormat)));
dateFrom.val(new Date(moment().format(dateFormat) + ' 00:00:00'));
dateTo.val(new Date(moment().format(dateFormat) + ' 23:59:59'));
//rangeSpan.text(dateFrom.val() + ' ~ ' + dateTo.val());
rangeSpan.text("Choose Count Period");
});

0 comments on commit 3a36945

Please sign in to comment.