Refactor docs; Add 'ipng_source_tag', add udp listener for nginx-ipng-stats plugin

This commit is contained in:
2026-04-17 09:50:54 +02:00
parent 0ecca06069
commit 577ed3dad5
26 changed files with 1319 additions and 1718 deletions

View File

@@ -21,14 +21,16 @@ const (
CoarseEvery = 5 // fine ticks between coarse writes
)
// Tuple6 is the aggregation key (website, prefix, URI, status, is_tor, asn).
// Tuple6 is the aggregation key (website, prefix, URI, status, is_tor, asn, source_tag).
// The name is kept for source-compat with older call sites; it now carries seven fields.
type Tuple6 struct {
Website string
Prefix string
URI string
Status string
IsTor bool
ASN int32
Website string
Prefix string
URI string
Status string
IsTor bool
ASN int32
SourceTag string
}
// Entry is a labelled count used in snapshots and query results.
@@ -85,12 +87,13 @@ func EncodeTuple(t Tuple6) string {
if t.IsTor {
tor = "1"
}
return t.Website + "\x00" + t.Prefix + "\x00" + t.URI + "\x00" + t.Status + "\x00" + tor + "\x00" + strconv.Itoa(int(t.ASN))
return t.Website + "\x00" + t.Prefix + "\x00" + t.URI + "\x00" + t.Status + "\x00" + tor + "\x00" + strconv.Itoa(int(t.ASN)) + "\x00" + t.SourceTag
}
// LabelTuple decodes a NUL-separated snapshot label back into a Tuple6.
// Labels from older snapshots (6 fields) round-trip with SourceTag=="".
func LabelTuple(label string) Tuple6 {
parts := splitN(label, '\x00', 6)
parts := splitN(label, '\x00', 7)
if len(parts) < 4 {
return Tuple6{}
}
@@ -98,11 +101,14 @@ func LabelTuple(label string) Tuple6 {
if len(parts) >= 5 {
t.IsTor = parts[4] == "1"
}
if len(parts) == 6 {
if len(parts) >= 6 {
if n, err := strconv.Atoi(parts[5]); err == nil {
t.ASN = int32(n)
}
}
if len(parts) == 7 {
t.SourceTag = parts[6]
}
return t
}
@@ -239,6 +245,9 @@ func MatchesFilter(t Tuple6, f *CompiledFilter) bool {
if p.AsnNumber != nil && !matchesAsnOp(t.ASN, p.GetAsnNumber(), p.AsnOp) {
return false
}
if p.IpngSourceTag != nil && t.SourceTag != p.GetIpngSourceTag() {
return false
}
return true
}
@@ -299,6 +308,8 @@ func DimensionLabel(t Tuple6, g pb.GroupBy) string {
return t.Status
case pb.GroupBy_ASN_NUMBER:
return strconv.Itoa(int(t.ASN))
case pb.GroupBy_SOURCE_TAG:
return t.SourceTag
default:
return t.Website
}