| 1 | package ddsnmp |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | |
| 6 | "github.com/netdata/netdata/go/plugins/plugin/go.d/collector/snmp/ddsnmp/ddprofiledefinition" |
| 7 | ) |
| 8 | |
| 9 | type ProfileMetrics struct { |
| 10 | Source string |
| 11 | DeviceMetadata map[string]MetaTag |
| 12 | Tags map[string]string |
| 13 | Metrics []Metric |
| 14 | TopologyMetrics []Metric |
| 15 | LicenseRows []LicenseRow |
| 16 | BGPRows []BGPRow |
| 17 | BGPCollectError error |
| 18 | HiddenMetrics []Metric |
| 19 | Stats CollectionStats |
| 20 | } |
| 21 | |
| 22 | type Metric struct { |
| 23 | Profile *ProfileMetrics |
| 24 | Name string |
| 25 | Description string |
| 26 | Family string |
| 27 | Unit string |
| 28 | ChartType string |
| 29 | MetricType ddprofiledefinition.ProfileMetricType |
| 30 | StaticTags map[string]string |
| 31 | Tags map[string]string |
| 32 | Table string |
| 33 | Value int64 |
| 34 | MultiValue map[string]int64 |
| 35 | |
| 36 | TopologyKind ddprofiledefinition.TopologyKind |
| 37 | IsTable bool |
| 38 | } |
| 39 | |
| 40 | type MetaTag struct { |
| 41 | Value string |
| 42 | IsExactMatch bool // whether this value is from an exact match context |
| 43 | } |
| 44 | |
| 45 | type LicenseRow struct { |
| 46 | OriginProfileID string |
| 47 | TableOID string |
| 48 | Table string |
| 49 | RowKey string |
| 50 | StructuralID string |
| 51 | |
| 52 | ID string |
| 53 | Name string |
| 54 | Feature string |
| 55 | Component string |
| 56 | Type string |
| 57 | Impact string |
| 58 | |
| 59 | IsPerpetual bool |
| 60 | IsUnlimited bool |
| 61 | |
| 62 | State LicenseState |
| 63 | Expiry LicenseTimer |
| 64 | Authorization LicenseTimer |
| 65 | Certificate LicenseTimer |
| 66 | Grace LicenseTimer |
| 67 | Usage LicenseUsage |
| 68 | |
| 69 | Tags map[string]string |
| 70 | } |
| 71 | |
| 72 | type LicenseState struct { |
| 73 | Has bool |
| 74 | Severity int64 |
| 75 | Raw string |
| 76 | Policy ddprofiledefinition.LicenseStatePolicy |
| 77 | SourceOID string |
| 78 | } |
| 79 | |
| 80 | type LicenseTimer struct { |
| 81 | Has bool |
| 82 | Timestamp int64 |
| 83 | RemainingSeconds int64 |
| 84 | SourceOID string |
| 85 | } |
| 86 | |
| 87 | type LicenseUsage struct { |
| 88 | HasUsed bool |
| 89 | Used int64 |
| 90 | HasCapacity bool |
| 91 | Capacity int64 |
| 92 | HasAvailable bool |
| 93 | Available int64 |
| 94 | HasPercent bool |
| 95 | Percent int64 |
| 96 | } |
| 97 | |
| 98 | type BGPRow struct { |
| 99 | OriginProfileID string |
| 100 | Kind ddprofiledefinition.BGPRowKind |
| 101 | TableOID string |
| 102 | Table string |
| 103 | RowKey string |
| 104 | StructuralID string |
| 105 | |
| 106 | Identity BGPIdentity |
| 107 | Descriptors BGPDescriptors |
| 108 | Admin BGPAdmin |
| 109 | State BGPState |
| 110 | Previous BGPState |
| 111 | Connection BGPConnection |
| 112 | Traffic BGPTraffic |
| 113 | Transitions BGPTransitions |
| 114 | Timers BGPTimers |
| 115 | LastError BGPLastError |
| 116 | LastNotify BGPLastNotifications |
| 117 | Reasons BGPReasons |
| 118 | Restart BGPGracefulRestart |
| 119 | Routes BGPRoutes |
| 120 | RouteLimits BGPRouteLimits |
| 121 | Device BGPDeviceCounts |
| 122 | Tags map[string]string |
| 123 | } |
| 124 | |
| 125 | type BGPIdentity struct { |
| 126 | RoutingInstance string |
| 127 | Neighbor string |
| 128 | RemoteAS string |
| 129 | AddressFamily ddprofiledefinition.BGPAddressFamily |
| 130 | SubsequentAddressFamily ddprofiledefinition.BGPSubsequentAddressFamily |
| 131 | } |
| 132 | |
| 133 | type BGPDescriptors struct { |
| 134 | LocalAddress string |
| 135 | LocalAS string |
| 136 | LocalIdentifier string |
| 137 | PeerIdentifier string |
| 138 | PeerType string |
| 139 | BGPVersion string |
| 140 | Description string |
| 141 | } |
| 142 | |
| 143 | type BGPState struct { |
| 144 | Has bool |
| 145 | State ddprofiledefinition.BGPPeerState |
| 146 | Raw string |
| 147 | SourceOID string |
| 148 | } |
| 149 | |
| 150 | type BGPAdmin struct { |
| 151 | Enabled BGPBool |
| 152 | } |
| 153 | |
| 154 | type BGPInt64 struct { |
| 155 | Has bool |
| 156 | Value int64 |
| 157 | Raw string |
| 158 | SourceOID string |
| 159 | } |
| 160 | |
| 161 | type BGPText struct { |
| 162 | Has bool |
| 163 | Value string |
| 164 | Raw string |
| 165 | SourceOID string |
| 166 | } |
| 167 | |
| 168 | type BGPBool struct { |
| 169 | Has bool |
| 170 | Value bool |
| 171 | Raw string |
| 172 | SourceOID string |
| 173 | } |
| 174 | |
| 175 | type BGPConnection struct { |
| 176 | EstablishedUptime BGPInt64 |
| 177 | LastReceivedUpdateAge BGPInt64 |
| 178 | } |
| 179 | |
| 180 | type BGPDirectional struct { |
| 181 | Received BGPInt64 |
| 182 | Sent BGPInt64 |
| 183 | } |
| 184 | |
| 185 | type BGPTraffic struct { |
| 186 | Messages BGPDirectional |
| 187 | Updates BGPDirectional |
| 188 | Notifications BGPDirectional |
| 189 | RouteRefreshes BGPDirectional |
| 190 | Opens BGPDirectional |
| 191 | Keepalives BGPDirectional |
| 192 | } |
| 193 | |
| 194 | type BGPTransitions struct { |
| 195 | Established BGPInt64 |
| 196 | Down BGPInt64 |
| 197 | Up BGPInt64 |
| 198 | Flaps BGPInt64 |
| 199 | } |
| 200 | |
| 201 | type BGPTimers struct { |
| 202 | Negotiated BGPTimerPair |
| 203 | Configured BGPTimerPair |
| 204 | } |
| 205 | |
| 206 | type BGPTimerPair struct { |
| 207 | ConnectRetry BGPInt64 |
| 208 | HoldTime BGPInt64 |
| 209 | KeepaliveTime BGPInt64 |
| 210 | MinASOriginationInterval BGPInt64 |
| 211 | MinRouteAdvertisementInterval BGPInt64 |
| 212 | } |
| 213 | |
| 214 | type BGPLastError struct { |
| 215 | Code BGPInt64 |
| 216 | Subcode BGPInt64 |
| 217 | Text string |
| 218 | } |
| 219 | |
| 220 | type BGPLastNotification struct { |
| 221 | Code BGPInt64 |
| 222 | Subcode BGPInt64 |
| 223 | Reason BGPText |
| 224 | } |
| 225 | |
| 226 | type BGPLastNotifications struct { |
| 227 | Received BGPLastNotification |
| 228 | Sent BGPLastNotification |
| 229 | } |
| 230 | |
| 231 | type BGPReasons struct { |
| 232 | LastDown BGPText |
| 233 | Unavailability BGPText |
| 234 | } |
| 235 | |
| 236 | type BGPGracefulRestart struct { |
| 237 | State BGPText |
| 238 | } |
| 239 | |
| 240 | type BGPRoutes struct { |
| 241 | Current BGPRouteCounters |
| 242 | Total BGPRouteCounters |
| 243 | } |
| 244 | |
| 245 | type BGPRouteCounters struct { |
| 246 | Received BGPInt64 |
| 247 | Accepted BGPInt64 |
| 248 | Rejected BGPInt64 |
| 249 | Active BGPInt64 |
| 250 | Advertised BGPInt64 |
| 251 | Suppressed BGPInt64 |
| 252 | Withdrawn BGPInt64 |
| 253 | } |
| 254 | |
| 255 | type BGPRouteLimits struct { |
| 256 | Limit BGPInt64 |
| 257 | Threshold BGPInt64 |
| 258 | ClearThreshold BGPInt64 |
| 259 | } |
| 260 | |
| 261 | type BGPDeviceCounts struct { |
| 262 | Peers BGPInt64 |
| 263 | InternalPeers BGPInt64 |
| 264 | ExternalPeers BGPInt64 |
| 265 | ByState map[ddprofiledefinition.BGPPeerState]int64 |
| 266 | ByStateHas bool |
| 267 | } |
| 268 | |
| 269 | // CollectionStats contains statistics for a single profile collection cycle. |
| 270 | type CollectionStats struct { |
| 271 | Timing TimingStats |
| 272 | SNMP SNMPOperationStats |
| 273 | Metrics MetricCountStats |
| 274 | TableCache TableCacheStats |
| 275 | Errors ErrorStats |
| 276 | } |
| 277 | |
| 278 | // TimingStats captures duration of each collection phase. |
| 279 | type TimingStats struct { |
| 280 | // Scalar is time spent collecting scalar (non-table) metrics. |
| 281 | Scalar time.Duration |
| 282 | // Table is time spent collecting table metrics. |
| 283 | Table time.Duration |
| 284 | // Licensing is time spent collecting typed licensing rows. |
| 285 | Licensing time.Duration |
| 286 | // BGP is time spent collecting typed BGP rows. |
| 287 | BGP time.Duration |
| 288 | // VirtualMetrics is time spent computing derived/aggregated metrics. |
| 289 | VirtualMetrics time.Duration |
| 290 | } |
| 291 | |
| 292 | func (s TimingStats) Total() time.Duration { |
| 293 | return s.Scalar + s.Table + s.Licensing + s.BGP + s.VirtualMetrics |
| 294 | } |
| 295 | |
| 296 | // SNMPOperationStats captures SNMP protocol-level operations. |
| 297 | type SNMPOperationStats struct { |
| 298 | // GetRequests is the number of SNMP GET operations performed. |
| 299 | GetRequests int64 |
| 300 | // GetOIDs is the total number of OIDs requested across all GETs. |
| 301 | GetOIDs int64 |
| 302 | // WalkRequests is the number of SNMP Walk/BulkWalk operations. |
| 303 | WalkRequests int64 |
| 304 | // WalkPDUs is the total number of PDUs returned from all walks. |
| 305 | WalkPDUs int64 |
| 306 | // TablesWalked is the count of tables that required walking. |
| 307 | TablesWalked int64 |
| 308 | // TablesCached is the count of tables served from cache. |
| 309 | TablesCached int64 |
| 310 | } |
| 311 | |
| 312 | // MetricCountStats captures the number of metrics produced. |
| 313 | type MetricCountStats struct { |
| 314 | // Scalar is the count of scalar (non-table) metrics. |
| 315 | Scalar int64 |
| 316 | // Table is the count of table metrics. |
| 317 | Table int64 |
| 318 | // Virtual is the count of computed/derived metrics. |
| 319 | Virtual int64 |
| 320 | // Licensing is the count of typed licensing rows produced. |
| 321 | Licensing int64 |
| 322 | // BGP is the count of typed BGP rows produced. |
| 323 | BGP int64 |
| 324 | // Tables is the count of unique regular metric tables. Typed licensing |
| 325 | // and BGP rows are counted separately. |
| 326 | Tables int64 |
| 327 | // Rows is the total number of regular metric table rows. Typed licensing |
| 328 | // and BGP rows are counted separately. |
| 329 | Rows int64 |
| 330 | } |
| 331 | |
| 332 | // TableCacheStats captures table cache performance. |
| 333 | type TableCacheStats struct { |
| 334 | // Hits is the number of table configs served from cache. |
| 335 | Hits int64 |
| 336 | // Misses is the number of table configs that required walking. |
| 337 | Misses int64 |
| 338 | } |
| 339 | |
| 340 | // ErrorStats captures categorized error counts. |
| 341 | type ErrorStats struct { |
| 342 | // SNMP is the count of SNMP-level errors (timeouts, network issues). |
| 343 | SNMP int64 |
| 344 | // Processing is the count of value conversion/transform errors. |
| 345 | Processing struct { |
| 346 | Scalar int64 |
| 347 | Table int64 |
| 348 | Licensing int64 |
| 349 | BGP int64 |
| 350 | } |
| 351 | // MissingOIDs is the count of NoSuchObject/NoSuchName responses. |
| 352 | MissingOIDs int64 |
| 353 | } |