Skip to content

Commit c533e2e

Browse files
committed
2021-12-31 22:04:08 : stat update
1 parent 19ed1ed commit c533e2e

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

README.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1-
# dnssrc
1+
# datahub
22

33
*datahub* - a CoreDNS Data Manage Plugin
44

5+
## 相关项目
56

6-
# Example
7+
[]
78

9+
## 配置案例
810

11+
```
12+
.:53 {
13+
datahub {
14+
bootstrap 114.114.114.114:53 # 引导 DNS
15+
jwt_secret 9b6de5cc-vcty-4bf1-zpms-0f568ac9da37
16+
geoip_path conf/geoip.dat
17+
geosite_path conf/geosite.dat
18+
geoip_cache cn hk jp google apple
19+
geosite_cache cn hk jp private apple
20+
geodat_upgrade_url http://teamsacs.mydomain.cn/geodat
21+
geodat_upgrade_cron 0 30 0 * * *
22+
# datatables conf/datatables.txt
23+
keyword_table cn,google conf/keywords.txt
24+
domain_table cn,aliyun,ads conf/domains.txt
25+
netlist_table cn,aliyun,local,office conf/networks.txt
26+
ecs_table global conf/ecs_table.txt
27+
datapub_listen :9800
28+
notify_server https://teamsacs.appsway.cn
29+
reload @every 3s
30+
}
31+
}
32+
33+
```

plugin/datahub/dataapi_stat.go

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ func (dh *Datahub) GetMetricSValue(name string) int64 {
1616
return dh.metricsStat.GetValue(name)
1717
}
1818

19+
func (dh *Datahub) GetDomainTop(count int) []stats.Counter {
20+
return dh.queryStat.GetTopValues(count)
21+
}
22+
23+
func (dh *Datahub) GetClientTop(count int) []stats.Counter {
24+
return dh.clientStat.GetTopValues(count)
25+
}
26+
1927
// GetDomainDayLineStat 查询域名标签匹配 24小时趋势图
2028
func (dh *Datahub) GetDomainDayLineStat() *stats.LineChartData {
2129
return dh.dayaDomainChartStat.LineChartData("最近 24 小时域名匹配统计").ChartData()

plugin/datahub/sched.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (dh *Datahub) startSched() {
1515
dh.cronUpdateKeywordTableMap()
1616
})
1717

18-
_, _ = dh.sched.AddFunc("@every 10s", func() {
18+
_, _ = dh.sched.AddFunc("@every 60s", func() {
1919
dh.dayaDomainChartStat.Update(dh.domainMatchStat)
2020
dh.dayNetworkChartStat.Update(dh.networkMatchStat)
2121
})

plugin/pkg/stats/stats.go

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package stats
22

33
import (
4+
"sort"
45
"sync"
56
"sync/atomic"
67
)
@@ -80,3 +81,14 @@ func (c *CounterStat) GetValue(name string) int64 {
8081
return 0
8182
}
8283
}
84+
85+
func (c *CounterStat) GetTopValues(count int) []Counter {
86+
values := c.Values()
87+
sort.Slice(values, func(i, j int) bool {
88+
return values[i].Value > values[j].Value
89+
})
90+
if len(values) < count {
91+
return values
92+
}
93+
return values[0:count]
94+
}

0 commit comments

Comments
 (0)