master
go 56 lines 1.18 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package snmp
4
5 import (
6 "time"
7
8 "github.com/netdata/netdata/go/plugins/pkg/funcapi"
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/collector/snmp/ddsnmp"
10 )
11
12 type licensingIntegration struct {
13 cache *licenseCache
14 }
15
16 func newLicensingIntegration() *licensingIntegration {
17 return &licensingIntegration{cache: newLicenseCache()}
18 }
19
20 func (li *licensingIntegration) registerFunction(r *funcRouter) {
21 if li == nil || r == nil {
22 return
23 }
24 r.registerHandler(licensesMethodID, newFuncLicenses(li.cache))
25 }
26
27 func snmpMethods() []funcapi.MethodConfig {
28 methods := snmpBaseMethods()
29 return append(methods, licensesMethodConfig())
30 }
31
32 func (c *Collector) collectLicensing(mx map[string]int64, pms []*ddsnmp.ProfileMetrics) {
33 if c.licensing == nil {
34 return
35 }
36 c.licensing.collect(c, mx, pms)
37 }
38
39 func (li *licensingIntegration) collect(c *Collector, mx map[string]int64, pms []*ddsnmp.ProfileMetrics) {
40 now := time.Now().UTC()
41 rows := extractLicenseRows(pms, now)
42
43 if li.cache != nil {
44 li.cache.store(now, rows)
45 }
46
47 if len(rows) == 0 {
48 return
49 }
50
51 agg := aggregateLicenseRows(rows, now)
52 if !agg.empty() {
53 c.addLicenseCharts(agg)
54 }
55 agg.writeTo(mx)
56 }