aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorJakob Borg <jakob@kastelo.net>2023-10-26 15:07:52 +0200
committerJakob Borg <jakob@kastelo.net>2023-11-08 12:18:59 +0100
commit58bd931d90bfd94ab5c5bcaf6574dbe962604608 (patch)
tree6eb77a1bf9321540dc14c648cbbd9e01522bddfe /cmd
parent854499382e20e39a43b1643939b5fa9f167537f5 (diff)
downloadsyncthing-58bd931d90bfd94ab5c5bcaf6574dbe962604608.tar.gz
syncthing-58bd931d90bfd94ab5c5bcaf6574dbe962604608.zip
cmd/stdiscosrv: Account IPv4 & IPv6
Diffstat (limited to 'cmd')
-rw-r--r--cmd/stdiscosrv/database.go34
1 files changed, 32 insertions, 2 deletions
diff --git a/cmd/stdiscosrv/database.go b/cmd/stdiscosrv/database.go
index 92ed45db6..1bc841df5 100644
--- a/cmd/stdiscosrv/database.go
+++ b/cmd/stdiscosrv/database.go
@@ -12,6 +12,8 @@ package main
import (
"context"
"log"
+ "net"
+ "net/url"
"sort"
"time"
@@ -218,7 +220,7 @@ func (s *levelDBStore) statisticsServe(trigger <-chan struct{}, done chan<- stru
cutoff24h := t0.Add(-24 * time.Hour).UnixNano()
cutoff1w := t0.Add(-7 * 24 * time.Hour).UnixNano()
cutoff2Mon := t0.Add(-60 * 24 * time.Hour).UnixNano()
- current, last24h, last1w, inactive, errors := 0, 0, 0, 0, 0
+ current, currentIPv4, currentIPv6, last24h, last1w, inactive, errors := 0, 0, 0, 0, 0, 0, 0
iter := s.db.NewIterator(&util.Range{}, nil)
for iter.Next() {
@@ -233,9 +235,35 @@ func (s *levelDBStore) statisticsServe(trigger <-chan struct{}, done chan<- stru
// If there are addresses that have not expired it's a current
// record, otherwise account it based on when it was last seen
// (last 24 hours or last week) or finally as inactice.
+ addrs := expire(rec.Addresses, nowNanos)
switch {
- case len(expire(rec.Addresses, nowNanos)) > 0:
+ case len(addrs) > 0:
current++
+ seenIPv4, seenIPv6 := false, false
+ for _, addr := range addrs {
+ uri, err := url.Parse(addr.Address)
+ if err != nil {
+ continue
+ }
+ host, _, err := net.SplitHostPort(uri.Host)
+ if err != nil {
+ continue
+ }
+ if ip := net.ParseIP(host); ip != nil && ip.To4() != nil {
+ seenIPv4 = true
+ } else if ip != nil {
+ seenIPv6 = true
+ }
+ if seenIPv4 && seenIPv6 {
+ break
+ }
+ }
+ if seenIPv4 {
+ currentIPv4++
+ }
+ if seenIPv6 {
+ currentIPv6++
+ }
case rec.Seen > cutoff24h:
last24h++
case rec.Seen > cutoff1w:
@@ -259,6 +287,8 @@ func (s *levelDBStore) statisticsServe(trigger <-chan struct{}, done chan<- stru
iter.Release()
databaseKeys.WithLabelValues("current").Set(float64(current))
+ databaseKeys.WithLabelValues("currentIPv4").Set(float64(currentIPv4))
+ databaseKeys.WithLabelValues("currentIPv6").Set(float64(currentIPv6))
databaseKeys.WithLabelValues("last24h").Set(float64(last24h))
databaseKeys.WithLabelValues("last1w").Set(float64(last1w))
databaseKeys.WithLabelValues("inactive").Set(float64(inactive))