| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package snmp |
| 4 | |
| 5 | import "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi" |
| 6 | |
| 7 | const ( |
| 8 | prioLicenseRemainingTime = prioPingStdDev + 1 + iota |
| 9 | prioLicenseAuthorizationRemainingTime |
| 10 | prioLicenseCertificateRemainingTime |
| 11 | prioLicenseGraceRemainingTime |
| 12 | prioLicenseUsagePercent |
| 13 | prioLicenseState |
| 14 | ) |
| 15 | |
| 16 | var ( |
| 17 | licenseRemainingTimeChart = collectorapi.Chart{ |
| 18 | ID: "snmp_device_license_remaining_time", |
| 19 | Title: "License remaining time", |
| 20 | Units: "seconds", |
| 21 | Fam: "Licensing/Time", |
| 22 | Ctx: "snmp.license.remaining_time", |
| 23 | Priority: prioLicenseRemainingTime, |
| 24 | SkipGaps: true, |
| 25 | Dims: collectorapi.Dims{ |
| 26 | {ID: "snmp_device_license_remaining_time", Name: "remaining_time"}, |
| 27 | }, |
| 28 | } |
| 29 | licenseAuthorizationRemainingTimeChart = collectorapi.Chart{ |
| 30 | ID: "snmp_device_license_authorization_remaining_time", |
| 31 | Title: "License authorization remaining time", |
| 32 | Units: "seconds", |
| 33 | Fam: "Licensing/Time", |
| 34 | Ctx: "snmp.license.authorization_remaining_time", |
| 35 | Priority: prioLicenseAuthorizationRemainingTime, |
| 36 | SkipGaps: true, |
| 37 | Dims: collectorapi.Dims{ |
| 38 | {ID: "snmp_device_license_authorization_remaining_time", Name: "remaining_time"}, |
| 39 | }, |
| 40 | } |
| 41 | licenseCertificateRemainingTimeChart = collectorapi.Chart{ |
| 42 | ID: "snmp_device_license_certificate_remaining_time", |
| 43 | Title: "License certificate remaining time", |
| 44 | Units: "seconds", |
| 45 | Fam: "Licensing/Time", |
| 46 | Ctx: "snmp.license.certificate_remaining_time", |
| 47 | Priority: prioLicenseCertificateRemainingTime, |
| 48 | SkipGaps: true, |
| 49 | Dims: collectorapi.Dims{ |
| 50 | {ID: "snmp_device_license_certificate_remaining_time", Name: "remaining_time"}, |
| 51 | }, |
| 52 | } |
| 53 | licenseGraceRemainingTimeChart = collectorapi.Chart{ |
| 54 | ID: "snmp_device_license_grace_remaining_time", |
| 55 | Title: "License grace remaining time", |
| 56 | Units: "seconds", |
| 57 | Fam: "Licensing/Time", |
| 58 | Ctx: "snmp.license.grace_remaining_time", |
| 59 | Priority: prioLicenseGraceRemainingTime, |
| 60 | SkipGaps: true, |
| 61 | Dims: collectorapi.Dims{ |
| 62 | {ID: "snmp_device_license_grace_remaining_time", Name: "remaining_time"}, |
| 63 | }, |
| 64 | } |
| 65 | licenseUsagePercentChart = collectorapi.Chart{ |
| 66 | ID: "snmp_device_license_usage_percent", |
| 67 | Title: "License usage pressure", |
| 68 | Units: "percentage", |
| 69 | Fam: "Licensing/Usage", |
| 70 | Ctx: "snmp.license.usage_percent", |
| 71 | Priority: prioLicenseUsagePercent, |
| 72 | Type: collectorapi.Area, |
| 73 | SkipGaps: true, |
| 74 | Dims: collectorapi.Dims{ |
| 75 | {ID: "snmp_device_license_usage_percent", Name: "usage_percent"}, |
| 76 | }, |
| 77 | } |
| 78 | licenseStateChart = collectorapi.Chart{ |
| 79 | ID: "snmp_device_license_state", |
| 80 | Title: "License state counts", |
| 81 | Units: "licenses", |
| 82 | Fam: "Licensing/State", |
| 83 | Ctx: "snmp.license.state", |
| 84 | Priority: prioLicenseState, |
| 85 | Type: collectorapi.Stacked, |
| 86 | SkipGaps: true, |
| 87 | Dims: collectorapi.Dims{ |
| 88 | {ID: metricIDLicenseStateHealthy, Name: string(licenseStateBucketHealthy)}, |
| 89 | {ID: metricIDLicenseStateInformational, Name: string(licenseStateBucketInformational)}, |
| 90 | {ID: metricIDLicenseStateDegraded, Name: string(licenseStateBucketDegraded)}, |
| 91 | {ID: metricIDLicenseStateBroken, Name: string(licenseStateBucketBroken)}, |
| 92 | {ID: metricIDLicenseStateIgnored, Name: string(licenseStateBucketIgnored)}, |
| 93 | }, |
| 94 | } |
| 95 | ) |
| 96 | |
| 97 | func (c *Collector) addLicenseCharts(agg licenseAggregate) { |
| 98 | if agg.hasRemainingTime { |
| 99 | c.addLicenseChart(licenseRemainingTimeChart) |
| 100 | } |
| 101 | if agg.hasAuthRemaining { |
| 102 | c.addLicenseChart(licenseAuthorizationRemainingTimeChart) |
| 103 | } |
| 104 | if agg.hasCertRemaining { |
| 105 | c.addLicenseChart(licenseCertificateRemainingTimeChart) |
| 106 | } |
| 107 | if agg.hasGraceRemaining { |
| 108 | c.addLicenseChart(licenseGraceRemainingTimeChart) |
| 109 | } |
| 110 | if agg.hasUsagePercent { |
| 111 | c.addLicenseChart(licenseUsagePercentChart) |
| 112 | } |
| 113 | if agg.hasStateCounts { |
| 114 | c.addLicenseChart(licenseStateChart) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | func (c *Collector) addLicenseChart(chart collectorapi.Chart) { |
| 119 | if c.Charts().Get(chart.ID) != nil { |
| 120 | return |
| 121 | } |
| 122 | |
| 123 | ch := chart.Copy() |
| 124 | labels := c.chartBaseLabels() |
| 125 | labels["component"] = "licensing" |
| 126 | |
| 127 | for k, v := range labels { |
| 128 | ch.Labels = append(ch.Labels, collectorapi.Label{Key: k, Value: v}) |
| 129 | } |
| 130 | |
| 131 | if err := c.Charts().Add(ch); err != nil { |
| 132 | c.Warningf("failed to add license chart %q: %v", ch.ID, err) |
| 133 | } |
| 134 | } |