首页增加在线人数统计
This commit is contained in:
+25
@@ -52,6 +52,7 @@ public class AggregationServiceImpl implements IAggregationService {
|
|||||||
* "currDate_uv": 219,
|
* "currDate_uv": 219,
|
||||||
* "currDate_pv": 2730,
|
* "currDate_pv": 2730,
|
||||||
* "currWeek_pv": 10309,
|
* "currWeek_pv": 10309,
|
||||||
|
* "currHour_uv": 20,
|
||||||
* "browser_datas": [
|
* "browser_datas": [
|
||||||
* {
|
* {
|
||||||
* "name": "CHROME",
|
* "name": "CHROME",
|
||||||
@@ -168,6 +169,20 @@ public class AggregationServiceImpl implements IAggregationService {
|
|||||||
.terms("operatingSystem")
|
.terms("operatingSystem")
|
||||||
.field("operatingSystem.keyword")
|
.field("operatingSystem.keyword")
|
||||||
)
|
)
|
||||||
|
.addAggregation(
|
||||||
|
//聚合查询1小时内的数据
|
||||||
|
AggregationBuilders
|
||||||
|
.dateRange("currHour")
|
||||||
|
.field("timestamp")
|
||||||
|
.addRange(
|
||||||
|
currDt.minusHours(1), currDt
|
||||||
|
)
|
||||||
|
.subAggregation(
|
||||||
|
AggregationBuilders
|
||||||
|
.cardinality("uv")
|
||||||
|
.field("ip.keyword")
|
||||||
|
)
|
||||||
|
)
|
||||||
.setSize(0)
|
.setSize(0)
|
||||||
.get();
|
.get();
|
||||||
Aggregations aggregations = response.getAggregations();
|
Aggregations aggregations = response.getAggregations();
|
||||||
@@ -179,6 +194,7 @@ public class AggregationServiceImpl implements IAggregationService {
|
|||||||
setCurrMonth(result, aggregations);
|
setCurrMonth(result, aggregations);
|
||||||
setTermsData(result, aggregations, "browser");
|
setTermsData(result, aggregations, "browser");
|
||||||
setTermsData(result, aggregations, "operatingSystem");
|
setTermsData(result, aggregations, "operatingSystem");
|
||||||
|
setCurrHour(result, aggregations);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -247,4 +263,13 @@ public class AggregationServiceImpl implements IAggregationService {
|
|||||||
result.put("statWeek_uv", uv);
|
result.put("statWeek_uv", uv);
|
||||||
result.put("statWeek_pv", pv);
|
result.put("statWeek_pv", pv);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 赋值小时内统计-当前在线数
|
||||||
|
*/
|
||||||
|
private void setCurrHour(Map<String, Object> result, Aggregations aggregations) {
|
||||||
|
InternalDateRange currDate = aggregations.get("currHour");
|
||||||
|
InternalDateRange.Bucket bucket = currDate.getBuckets().get(0);
|
||||||
|
Cardinality cardinality = bucket.getAggregations().get("uv");
|
||||||
|
result.put("currHour_uv", cardinality.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,17 @@
|
|||||||
|
|
||||||
<div class="layui-card-body" style="text-align: center;">
|
<div class="layui-card-body" style="text-align: center;">
|
||||||
<div class="layui-row layui-col-space10">
|
<div class="layui-row layui-col-space10">
|
||||||
<div class="layui-col-sm3 layui-col-md3">
|
<div class="layui-col-sm2 layui-col-md2">
|
||||||
|
<div class="layui-card">
|
||||||
|
<div class="layui-card-header">在线人数
|
||||||
|
<span class="layui-badge layui-bg-cyan layuiadmin-badge">时</span>
|
||||||
|
</div>
|
||||||
|
<div class="layui-card-body layuiadmin-card-list">
|
||||||
|
<p class="big-font" id="userCnt"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-col-sm2 layui-col-md2">
|
||||||
<div class="layui-card">
|
<div class="layui-card">
|
||||||
<div class="layui-card-header">PV
|
<div class="layui-card-header">PV
|
||||||
<span class="layui-badge layui-bg-green layuiadmin-badge">天</span>
|
<span class="layui-badge layui-bg-green layuiadmin-badge">天</span>
|
||||||
@@ -36,7 +46,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-col-sm3 layui-col-md3">
|
<div class="layui-col-sm2 layui-col-md2">
|
||||||
<div class="layui-card">
|
<div class="layui-card">
|
||||||
<div class="layui-card-header">UV
|
<div class="layui-card-header">UV
|
||||||
<span class="layui-badge layui-bg-green layuiadmin-badge">天</span>
|
<span class="layui-badge layui-bg-green layuiadmin-badge">天</span>
|
||||||
@@ -168,6 +178,7 @@
|
|||||||
$('#uv').html(data.currDate_uv);
|
$('#uv').html(data.currDate_uv);
|
||||||
$('#weekPv').html(data.currWeek_pv);
|
$('#weekPv').html(data.currWeek_pv);
|
||||||
$('#monthPv').html(data.currMonth_pv);
|
$('#monthPv').html(data.currMonth_pv);
|
||||||
|
$('#userCnt').html(data.currHour_uv);
|
||||||
|
|
||||||
browserChart.hideLoading()
|
browserChart.hideLoading()
|
||||||
browserChart.setOption({
|
browserChart.setOption({
|
||||||
|
|||||||
Reference in New Issue
Block a user