首页增加在线人数统计
This commit is contained in:
+25
@@ -52,6 +52,7 @@ public class AggregationServiceImpl implements IAggregationService {
|
||||
* "currDate_uv": 219,
|
||||
* "currDate_pv": 2730,
|
||||
* "currWeek_pv": 10309,
|
||||
* "currHour_uv": 20,
|
||||
* "browser_datas": [
|
||||
* {
|
||||
* "name": "CHROME",
|
||||
@@ -168,6 +169,20 @@ public class AggregationServiceImpl implements IAggregationService {
|
||||
.terms("operatingSystem")
|
||||
.field("operatingSystem.keyword")
|
||||
)
|
||||
.addAggregation(
|
||||
//聚合查询1小时内的数据
|
||||
AggregationBuilders
|
||||
.dateRange("currHour")
|
||||
.field("timestamp")
|
||||
.addRange(
|
||||
currDt.minusHours(1), currDt
|
||||
)
|
||||
.subAggregation(
|
||||
AggregationBuilders
|
||||
.cardinality("uv")
|
||||
.field("ip.keyword")
|
||||
)
|
||||
)
|
||||
.setSize(0)
|
||||
.get();
|
||||
Aggregations aggregations = response.getAggregations();
|
||||
@@ -179,6 +194,7 @@ public class AggregationServiceImpl implements IAggregationService {
|
||||
setCurrMonth(result, aggregations);
|
||||
setTermsData(result, aggregations, "browser");
|
||||
setTermsData(result, aggregations, "operatingSystem");
|
||||
setCurrHour(result, aggregations);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -247,4 +263,13 @@ public class AggregationServiceImpl implements IAggregationService {
|
||||
result.put("statWeek_uv", uv);
|
||||
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-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-header">PV
|
||||
<span class="layui-badge layui-bg-green layuiadmin-badge">天</span>
|
||||
@@ -36,7 +46,7 @@
|
||||
</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-header">UV
|
||||
<span class="layui-badge layui-bg-green layuiadmin-badge">天</span>
|
||||
@@ -168,6 +178,7 @@
|
||||
$('#uv').html(data.currDate_uv);
|
||||
$('#weekPv').html(data.currWeek_pv);
|
||||
$('#monthPv').html(data.currMonth_pv);
|
||||
$('#userCnt').html(data.currHour_uv);
|
||||
|
||||
browserChart.hideLoading()
|
||||
browserChart.setOption({
|
||||
|
||||
Reference in New Issue
Block a user