web: support to clear offline proxies data on dashboard (#3963)

This commit is contained in:
fatedier
2024-02-01 10:54:57 +08:00
committed by GitHub
parent 8023d147b0
commit b31c67d7c0
39 changed files with 1999 additions and 2933 deletions

View File

@@ -61,23 +61,23 @@ func (m *serverMetrics) run() {
for {
time.Sleep(12 * time.Hour)
start := time.Now()
count, total := m.clearUselessInfo()
count, total := m.clearUselessInfo(time.Duration(7*24) * time.Hour)
log.Debug("clear useless proxy statistics data count %d/%d, cost %v", count, total, time.Since(start))
}
}()
}
func (m *serverMetrics) clearUselessInfo() (int, int) {
func (m *serverMetrics) clearUselessInfo(continuousOfflineDuration time.Duration) (int, int) {
count := 0
total := 0
// To check if there are proxies that closed than 7 days and drop them.
// To check if there are any proxies that have been closed for more than continuousOfflineDuration and remove them.
m.mu.Lock()
defer m.mu.Unlock()
total = len(m.info.ProxyStatistics)
for name, data := range m.info.ProxyStatistics {
if !data.LastCloseTime.IsZero() &&
data.LastStartTime.Before(data.LastCloseTime) &&
time.Since(data.LastCloseTime) > time.Duration(7*24)*time.Hour {
time.Since(data.LastCloseTime) > continuousOfflineDuration {
delete(m.info.ProxyStatistics, name)
count++
log.Trace("clear proxy [%s]'s statistics data, lastCloseTime: [%s]", name, data.LastCloseTime.String())
@@ -86,6 +86,10 @@ func (m *serverMetrics) clearUselessInfo() (int, int) {
return count, total
}
func (m *serverMetrics) ClearOfflineProxies() (int, int) {
return m.clearUselessInfo(0)
}
func (m *serverMetrics) NewClient() {
m.info.ClientCounts.Inc(1)
}

View File

@@ -79,4 +79,5 @@ type Collector interface {
GetProxiesByType(proxyType string) []*ProxyStats
GetProxiesByTypeAndName(proxyType string, proxyName string) *ProxyStats
GetProxyTraffic(name string) *ProxyTrafficInfo
ClearOfflineProxies() (int, int)
}