nodemetrics.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. package metrics
  2. import (
  3. "strings"
  4. "github.com/opencost/opencost/core/pkg/clustercache"
  5. "github.com/opencost/opencost/core/pkg/log"
  6. "github.com/opencost/opencost/core/pkg/util/promutil"
  7. "github.com/prometheus/client_golang/prometheus"
  8. dto "github.com/prometheus/client_model/go"
  9. v1 "k8s.io/api/core/v1"
  10. )
  11. var (
  12. conditionStatuses = []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionUnknown}
  13. )
  14. //--------------------------------------------------------------------------
  15. // KubeNodeCollector
  16. //--------------------------------------------------------------------------
  17. // KubeNodeCollector is a prometheus collector that generates node sourced metrics.
  18. type KubeNodeCollector struct {
  19. KubeClusterCache clustercache.ClusterCache
  20. metricsConfig MetricsConfig
  21. }
  22. // Describe sends the super-set of all possible descriptors of metrics
  23. // collected by this Collector.
  24. func (nsac KubeNodeCollector) Describe(ch chan<- *prometheus.Desc) {
  25. disabledMetrics := nsac.metricsConfig.GetDisabledMetricsMap()
  26. if _, disabled := disabledMetrics["kube_node_status_capacity"]; !disabled {
  27. ch <- prometheus.NewDesc("kube_node_status_capacity", "Node resource capacity.", []string{}, nil)
  28. }
  29. if _, disabled := disabledMetrics["kube_node_status_capacity_memory_bytes"]; !disabled {
  30. ch <- prometheus.NewDesc("kube_node_status_capacity_memory_bytes", "node capacity memory bytes", []string{}, nil)
  31. }
  32. if _, disabled := disabledMetrics["kube_node_status_capacity_cpu_cores"]; !disabled {
  33. ch <- prometheus.NewDesc("kube_node_status_capacity_cpu_cores", "node capacity cpu cores", []string{}, nil)
  34. }
  35. if _, disabled := disabledMetrics["kube_node_status_allocatable"]; !disabled {
  36. ch <- prometheus.NewDesc("kube_node_status_allocatable", "The allocatable for different resources of a node that are available for scheduling.", []string{}, nil)
  37. }
  38. if _, disabled := disabledMetrics["kube_node_status_allocatable_cpu_cores"]; !disabled {
  39. ch <- prometheus.NewDesc("kube_node_status_allocatable_cpu_cores", "The allocatable cpu cores.", []string{}, nil)
  40. }
  41. if _, disabled := disabledMetrics["kube_node_status_allocatable_memory_bytes"]; !disabled {
  42. ch <- prometheus.NewDesc("kube_node_status_allocatable_memory_bytes", "The allocatable memory in bytes.", []string{}, nil)
  43. }
  44. if _, disabled := disabledMetrics["kube_node_labels"]; !disabled {
  45. ch <- prometheus.NewDesc("kube_node_labels", "all labels for each node prefixed with label_", []string{}, nil)
  46. }
  47. if _, disabled := disabledMetrics["kube_node_status_condition"]; !disabled {
  48. ch <- prometheus.NewDesc("kube_node_status_condition", "The condition of a cluster node.", []string{}, nil)
  49. }
  50. }
  51. // Collect is called by the Prometheus registry when collecting metrics.
  52. func (nsac KubeNodeCollector) Collect(ch chan<- prometheus.Metric) {
  53. nodes := nsac.KubeClusterCache.GetAllNodes()
  54. disabledMetrics := nsac.metricsConfig.GetDisabledMetricsMap()
  55. for _, node := range nodes {
  56. nodeName := node.Name
  57. nodeUID := string(node.UID)
  58. // Node Capacity
  59. for resourceName, quantity := range node.Status.Capacity {
  60. resource, unit, value := toResourceUnitValue(resourceName, quantity)
  61. // failed to parse the resource type
  62. if resource == "" {
  63. log.DedupedWarningf(5, "Failed to parse resource units and quantity for resource: %s", resourceName)
  64. continue
  65. }
  66. // KSM v1 Emission
  67. if _, disabled := disabledMetrics["kube_node_status_capacity_cpu_cores"]; !disabled {
  68. if resource == "cpu" {
  69. ch <- newKubeNodeStatusCapacityCPUCoresMetric("kube_node_status_capacity_cpu_cores", nodeName, nodeUID, value)
  70. }
  71. }
  72. if _, disabled := disabledMetrics["kube_node_status_capacity_memory_bytes"]; !disabled {
  73. if resource == "memory" {
  74. ch <- newKubeNodeStatusCapacityMemoryBytesMetric("kube_node_status_capacity_memory_bytes", nodeName, nodeUID, value)
  75. }
  76. }
  77. if _, disabled := disabledMetrics["kube_node_status_capacity"]; !disabled {
  78. ch <- newKubeNodeStatusCapacityMetric("kube_node_status_capacity", nodeName, resource, unit, nodeUID, value)
  79. }
  80. }
  81. // Node Allocatable Resources
  82. for resourceName, quantity := range node.Status.Allocatable {
  83. resource, unit, value := toResourceUnitValue(resourceName, quantity)
  84. // failed to parse the resource type
  85. if resource == "" {
  86. log.DedupedWarningf(5, "Failed to parse resource units and quantity for resource: %s", resourceName)
  87. continue
  88. }
  89. // KSM v1 Emission
  90. if _, disabled := disabledMetrics["kube_node_status_allocatable_cpu_cores"]; !disabled {
  91. if resource == "cpu" {
  92. ch <- newKubeNodeStatusAllocatableCPUCoresMetric("kube_node_status_allocatable_cpu_cores", nodeName, value, nodeUID)
  93. }
  94. }
  95. if _, disabled := disabledMetrics["kube_node_status_allocatable_memory_bytes"]; !disabled {
  96. if resource == "memory" {
  97. ch <- newKubeNodeStatusAllocatableMemoryBytesMetric("kube_node_status_allocatable_memory_bytes", nodeName, value, nodeUID)
  98. }
  99. }
  100. if _, disabled := disabledMetrics["kube_node_status_allocatable"]; !disabled {
  101. ch <- newKubeNodeStatusAllocatableMetric("kube_node_status_allocatable", nodeName, resource, unit, value, nodeUID)
  102. }
  103. }
  104. // node labels
  105. if _, disabled := disabledMetrics["kube_node_labels"]; !disabled {
  106. labelNames, labelValues := promutil.KubePrependQualifierToLabels(promutil.SanitizeLabels(node.Labels), "label_")
  107. ch <- newKubeNodeLabelsMetric(nodeName, "kube_node_labels", labelNames, labelValues, nodeUID)
  108. }
  109. // kube_node_status_condition
  110. // Collect node conditions and while default to false.
  111. if _, disabled := disabledMetrics["kube_node_status_condition"]; !disabled {
  112. for _, c := range node.Status.Conditions {
  113. conditions := getConditions(c.Status)
  114. for _, cond := range conditions {
  115. ch <- newKubeNodeStatusConditionMetric(nodeName, "kube_node_status_condition", string(c.Type), cond.status, cond.value, nodeUID)
  116. }
  117. }
  118. }
  119. }
  120. }
  121. //--------------------------------------------------------------------------
  122. // KubeNodeStatusCapacityMetric
  123. //--------------------------------------------------------------------------
  124. // KubeNodeStatusCapacityMetric is a prometheus.Metric
  125. type KubeNodeStatusCapacityMetric struct {
  126. fqName string
  127. help string
  128. resource string
  129. unit string
  130. node string
  131. value float64
  132. uid string
  133. }
  134. // Creates a new KubeNodeStatusCapacityMetric, implementation of prometheus.Metric
  135. func newKubeNodeStatusCapacityMetric(fqname, node, resource, unit, uid string, value float64) KubeNodeStatusCapacityMetric {
  136. return KubeNodeStatusCapacityMetric{
  137. fqName: fqname,
  138. help: "kube_node_status_capacity node capacity",
  139. node: node,
  140. resource: resource,
  141. unit: unit,
  142. value: value,
  143. uid: uid,
  144. }
  145. }
  146. // Desc returns the descriptor for the Metric. This method idempotently
  147. // returns the same descriptor throughout the lifetime of the Metric.
  148. func (kpcrr KubeNodeStatusCapacityMetric) Desc() *prometheus.Desc {
  149. l := prometheus.Labels{
  150. "node": kpcrr.node,
  151. "resource": kpcrr.resource,
  152. "unit": kpcrr.unit,
  153. "uid": kpcrr.uid,
  154. }
  155. return prometheus.NewDesc(kpcrr.fqName, kpcrr.help, []string{}, l)
  156. }
  157. // Write encodes the Metric into a "Metric" Protocol Buffer data transmission object.
  158. func (kpcrr KubeNodeStatusCapacityMetric) Write(m *dto.Metric) error {
  159. m.Gauge = &dto.Gauge{
  160. Value: &kpcrr.value,
  161. }
  162. m.Label = []*dto.LabelPair{
  163. {
  164. Name: toStringPtr("node"),
  165. Value: &kpcrr.node,
  166. },
  167. {
  168. Name: toStringPtr("resource"),
  169. Value: &kpcrr.resource,
  170. },
  171. {
  172. Name: toStringPtr("unit"),
  173. Value: &kpcrr.unit,
  174. },
  175. {
  176. Name: toStringPtr("uid"),
  177. Value: &kpcrr.uid,
  178. },
  179. }
  180. return nil
  181. }
  182. //--------------------------------------------------------------------------
  183. // KubeNodeStatusCapacityMemoryBytesMetric
  184. //--------------------------------------------------------------------------
  185. // KubeNodeStatusCapacityMemoryBytesMetric is a prometheus.Metric used to encode
  186. // a duplicate of the deprecated kube-state-metrics metric
  187. // kube_node_status_capacity_memory_bytes
  188. type KubeNodeStatusCapacityMemoryBytesMetric struct {
  189. fqName string
  190. help string
  191. bytes float64
  192. node string
  193. uid string
  194. }
  195. // Creates a new KubeNodeStatusCapacityMemoryBytesMetric, implementation of prometheus.Metric
  196. func newKubeNodeStatusCapacityMemoryBytesMetric(fqname string, node string, uid string, bytes float64) KubeNodeStatusCapacityMemoryBytesMetric {
  197. return KubeNodeStatusCapacityMemoryBytesMetric{
  198. fqName: fqname,
  199. help: "kube_node_status_capacity_memory_bytes Node Capacity Memory Bytes",
  200. node: node,
  201. bytes: bytes,
  202. uid: uid,
  203. }
  204. }
  205. // Desc returns the descriptor for the Metric. This method idempotently
  206. // returns the same descriptor throughout the lifetime of the Metric.
  207. func (nam KubeNodeStatusCapacityMemoryBytesMetric) Desc() *prometheus.Desc {
  208. l := prometheus.Labels{"node": nam.node, "uid": nam.uid}
  209. return prometheus.NewDesc(nam.fqName, nam.help, []string{}, l)
  210. }
  211. // Write encodes the Metric into a "Metric" Protocol Buffer data
  212. // transmission object.
  213. func (nam KubeNodeStatusCapacityMemoryBytesMetric) Write(m *dto.Metric) error {
  214. m.Gauge = &dto.Gauge{
  215. Value: &nam.bytes,
  216. }
  217. m.Label = []*dto.LabelPair{
  218. {
  219. Name: toStringPtr("node"),
  220. Value: &nam.node,
  221. },
  222. {
  223. Name: toStringPtr("uid"),
  224. Value: &nam.uid,
  225. },
  226. }
  227. return nil
  228. }
  229. //--------------------------------------------------------------------------
  230. // KubeNodeStatusCapacityCPUCoresMetric
  231. //--------------------------------------------------------------------------
  232. // KubeNodeStatusCapacityCPUCoresMetric is a prometheus.Metric used to encode
  233. // a duplicate of the deprecated kube-state-metrics metric
  234. // kube_node_status_capacity_memory_bytes
  235. type KubeNodeStatusCapacityCPUCoresMetric struct {
  236. fqName string
  237. help string
  238. cores float64
  239. node string
  240. uid string
  241. }
  242. // Creates a new KubeNodeStatusCapacityCPUCoresMetric, implementation of prometheus.Metric
  243. func newKubeNodeStatusCapacityCPUCoresMetric(fqname string, node string, uid string, cores float64) KubeNodeStatusCapacityCPUCoresMetric {
  244. return KubeNodeStatusCapacityCPUCoresMetric{
  245. fqName: fqname,
  246. help: "kube_node_status_capacity_cpu_cores Node Capacity CPU Cores",
  247. cores: cores,
  248. node: node,
  249. uid: uid,
  250. }
  251. }
  252. // Desc returns the descriptor for the Metric. This method idempotently
  253. // returns the same descriptor throughout the lifetime of the Metric.
  254. func (nam KubeNodeStatusCapacityCPUCoresMetric) Desc() *prometheus.Desc {
  255. l := prometheus.Labels{"node": nam.node, "uid": nam.uid}
  256. return prometheus.NewDesc(nam.fqName, nam.help, []string{}, l)
  257. }
  258. // Write encodes the Metric into a "Metric" Protocol Buffer data
  259. // transmission object.
  260. func (nam KubeNodeStatusCapacityCPUCoresMetric) Write(m *dto.Metric) error {
  261. m.Gauge = &dto.Gauge{
  262. Value: &nam.cores,
  263. }
  264. m.Label = []*dto.LabelPair{
  265. {
  266. Name: toStringPtr("node"),
  267. Value: &nam.node,
  268. },
  269. {
  270. Name: toStringPtr("uid"),
  271. Value: &nam.uid,
  272. },
  273. }
  274. return nil
  275. }
  276. //--------------------------------------------------------------------------
  277. // KubeNodeLabelsMetric
  278. //--------------------------------------------------------------------------
  279. // KubeNodeLabelsMetric is a prometheus.Metric used to encode
  280. // a duplicate of the deprecated kube-state-metrics metric
  281. // kube_node_labels
  282. type KubeNodeLabelsMetric struct {
  283. fqName string
  284. help string
  285. labelNames []string
  286. labelValues []string
  287. node string
  288. uid string
  289. }
  290. // Creates a new KubeNodeLabelsMetric, implementation of prometheus.Metric
  291. func newKubeNodeLabelsMetric(node string, fqname string, labelNames []string, labelValues []string, uid string) KubeNodeLabelsMetric {
  292. return KubeNodeLabelsMetric{
  293. fqName: fqname,
  294. labelNames: labelNames,
  295. labelValues: labelValues,
  296. help: "kube_node_labels all labels for each node prefixed with label_",
  297. node: node,
  298. uid: uid,
  299. }
  300. }
  301. // Desc returns the descriptor for the Metric. This method idempotently
  302. // returns the same descriptor throughout the lifetime of the Metric.
  303. func (nam KubeNodeLabelsMetric) Desc() *prometheus.Desc {
  304. l := prometheus.Labels{
  305. "node": nam.node,
  306. "uid": nam.uid,
  307. }
  308. return prometheus.NewDesc(nam.fqName, nam.help, nam.labelNames, l)
  309. }
  310. // Write encodes the Metric into a "Metric" Protocol Buffer data
  311. // transmission object.
  312. func (nam KubeNodeLabelsMetric) Write(m *dto.Metric) error {
  313. h := float64(1)
  314. m.Gauge = &dto.Gauge{
  315. Value: &h,
  316. }
  317. var labels []*dto.LabelPair
  318. for i := range nam.labelNames {
  319. labels = append(labels, &dto.LabelPair{
  320. Name: &nam.labelNames[i],
  321. Value: &nam.labelValues[i],
  322. })
  323. }
  324. nodeString := "node"
  325. labels = append(labels, &dto.LabelPair{Name: &nodeString, Value: &nam.node})
  326. uidString := "uid"
  327. labels = append(labels, &dto.LabelPair{Name: &uidString, Value: &nam.uid})
  328. m.Label = labels
  329. return nil
  330. }
  331. //--------------------------------------------------------------------------
  332. // KubeNodeStatusConditionMetric
  333. //--------------------------------------------------------------------------
  334. // KubeNodeStatusConditionMetric
  335. type KubeNodeStatusConditionMetric struct {
  336. fqName string
  337. help string
  338. node string
  339. condition string
  340. status string
  341. value float64
  342. uid string
  343. }
  344. // Creates a new KubeNodeStatusConditionMetric, implementation of prometheus.Metric
  345. func newKubeNodeStatusConditionMetric(node, fqname, condition, status string, value float64, uid string) KubeNodeStatusConditionMetric {
  346. return KubeNodeStatusConditionMetric{
  347. fqName: fqname,
  348. help: "kube_node_status_condition condition status for nodes",
  349. node: node,
  350. condition: condition,
  351. status: status,
  352. value: value,
  353. uid: uid,
  354. }
  355. }
  356. // Desc returns the descriptor for the Metric. This method idempotently
  357. // returns the same descriptor throughout the lifetime of the Metric.
  358. func (nam KubeNodeStatusConditionMetric) Desc() *prometheus.Desc {
  359. l := prometheus.Labels{
  360. "node": nam.node,
  361. "condition": nam.condition,
  362. "status": nam.status,
  363. "uid": nam.uid,
  364. }
  365. return prometheus.NewDesc(nam.fqName, nam.help, []string{}, l)
  366. }
  367. // Write encodes the Metric into a "Metric" Protocol Buffer data
  368. // transmission object.
  369. func (nam KubeNodeStatusConditionMetric) Write(m *dto.Metric) error {
  370. m.Gauge = &dto.Gauge{
  371. Value: &nam.value,
  372. }
  373. m.Label = []*dto.LabelPair{
  374. {
  375. Name: toStringPtr("node"),
  376. Value: &nam.node,
  377. },
  378. {
  379. Name: toStringPtr("condition"),
  380. Value: &nam.condition,
  381. },
  382. {
  383. Name: toStringPtr("status"),
  384. Value: &nam.status,
  385. },
  386. {
  387. Name: toStringPtr("uid"),
  388. Value: &nam.uid,
  389. },
  390. }
  391. return nil
  392. }
  393. // helper type for status condition reporting and metric rollup
  394. type statusCondition struct {
  395. status string
  396. value float64
  397. }
  398. // retrieves the total status conditions and the comparison to the provided condition
  399. func getConditions(cs v1.ConditionStatus) []*statusCondition {
  400. ms := make([]*statusCondition, len(conditionStatuses))
  401. for i, status := range conditionStatuses {
  402. ms[i] = &statusCondition{
  403. status: strings.ToLower(string(status)),
  404. value: boolFloat64(cs == status),
  405. }
  406. }
  407. return ms
  408. }
  409. //--------------------------------------------------------------------------
  410. // KubeNodeStatusAllocatableMetric
  411. //--------------------------------------------------------------------------
  412. // KubeNodeStatusAllocatableMetric is a prometheus.Metric
  413. type KubeNodeStatusAllocatableMetric struct {
  414. fqName string
  415. help string
  416. resource string
  417. unit string
  418. node string
  419. value float64
  420. uid string
  421. }
  422. // Creates a new KubeNodeStatusAllocatableMetric, implementation of prometheus.Metric
  423. func newKubeNodeStatusAllocatableMetric(fqname, node, resource, unit string, value float64, uid string) KubeNodeStatusAllocatableMetric {
  424. return KubeNodeStatusAllocatableMetric{
  425. fqName: fqname,
  426. help: "kube_node_status_allocatable node allocatable",
  427. node: node,
  428. resource: resource,
  429. unit: unit,
  430. value: value,
  431. uid: uid,
  432. }
  433. }
  434. // Desc returns the descriptor for the Metric. This method idempotently
  435. // returns the same descriptor throughout the lifetime of the Metric.
  436. func (kpcrr KubeNodeStatusAllocatableMetric) Desc() *prometheus.Desc {
  437. l := prometheus.Labels{
  438. "node": kpcrr.node,
  439. "resource": kpcrr.resource,
  440. "unit": kpcrr.unit,
  441. "uid": kpcrr.uid,
  442. }
  443. return prometheus.NewDesc(kpcrr.fqName, kpcrr.help, []string{}, l)
  444. }
  445. // Write encodes the Metric into a "Metric" Protocol Buffer data transmission object.
  446. func (kpcrr KubeNodeStatusAllocatableMetric) Write(m *dto.Metric) error {
  447. m.Gauge = &dto.Gauge{
  448. Value: &kpcrr.value,
  449. }
  450. m.Label = []*dto.LabelPair{
  451. {
  452. Name: toStringPtr("node"),
  453. Value: &kpcrr.node,
  454. },
  455. {
  456. Name: toStringPtr("resource"),
  457. Value: &kpcrr.resource,
  458. },
  459. {
  460. Name: toStringPtr("unit"),
  461. Value: &kpcrr.unit,
  462. },
  463. {
  464. Name: toStringPtr("uid"),
  465. Value: &kpcrr.uid,
  466. },
  467. }
  468. return nil
  469. }
  470. //--------------------------------------------------------------------------
  471. // KubeNodeStatusAllocatableCPUCoresMetric
  472. //--------------------------------------------------------------------------
  473. // KubeNodeStatusAllocatableCPUCoresMetric is a prometheus.Metric
  474. type KubeNodeStatusAllocatableCPUCoresMetric struct {
  475. fqName string
  476. help string
  477. resource string
  478. unit string
  479. node string
  480. value float64
  481. uid string
  482. }
  483. // Creates a new KubeNodeStatusAllocatableCPUCoresMetric, implementation of prometheus.Metric
  484. func newKubeNodeStatusAllocatableCPUCoresMetric(fqname, node string, value float64, uid string) KubeNodeStatusAllocatableCPUCoresMetric {
  485. return KubeNodeStatusAllocatableCPUCoresMetric{
  486. fqName: fqname,
  487. help: "kube_node_status_allocatable_cpu_cores node allocatable cpu cores",
  488. node: node,
  489. value: value,
  490. uid: uid,
  491. }
  492. }
  493. // Desc returns the descriptor for the Metric. This method idempotently
  494. // returns the same descriptor throughout the lifetime of the Metric.
  495. func (kpcrr KubeNodeStatusAllocatableCPUCoresMetric) Desc() *prometheus.Desc {
  496. l := prometheus.Labels{
  497. "node": kpcrr.node,
  498. "uid": kpcrr.uid,
  499. }
  500. return prometheus.NewDesc(kpcrr.fqName, kpcrr.help, []string{}, l)
  501. }
  502. // Write encodes the Metric into a "Metric" Protocol Buffer data transmission object.
  503. func (kpcrr KubeNodeStatusAllocatableCPUCoresMetric) Write(m *dto.Metric) error {
  504. m.Gauge = &dto.Gauge{
  505. Value: &kpcrr.value,
  506. }
  507. m.Label = []*dto.LabelPair{
  508. {
  509. Name: toStringPtr("node"),
  510. Value: &kpcrr.node,
  511. },
  512. {
  513. Name: toStringPtr("uid"),
  514. Value: &kpcrr.uid,
  515. },
  516. }
  517. return nil
  518. }
  519. //--------------------------------------------------------------------------
  520. // KubeNodeStatusAllocatableMemoryBytesMetric
  521. //--------------------------------------------------------------------------
  522. // KubeNodeStatusAllocatableMemoryBytesMetric is a prometheus.Metric
  523. type KubeNodeStatusAllocatableMemoryBytesMetric struct {
  524. fqName string
  525. help string
  526. resource string
  527. unit string
  528. node string
  529. value float64
  530. uid string
  531. }
  532. // Creates a new KubeNodeStatusAllocatableMemoryBytesMetric, implementation of prometheus.Metric
  533. func newKubeNodeStatusAllocatableMemoryBytesMetric(fqname, node string, value float64, uid string) KubeNodeStatusAllocatableMemoryBytesMetric {
  534. return KubeNodeStatusAllocatableMemoryBytesMetric{
  535. fqName: fqname,
  536. help: "kube_node_status_allocatable_memory_bytes node allocatable memory in bytes",
  537. node: node,
  538. value: value,
  539. uid: uid,
  540. }
  541. }
  542. // Desc returns the descriptor for the Metric. This method idempotently
  543. // returns the same descriptor throughout the lifetime of the Metric.
  544. func (kpcrr KubeNodeStatusAllocatableMemoryBytesMetric) Desc() *prometheus.Desc {
  545. l := prometheus.Labels{
  546. "node": kpcrr.node,
  547. "uid": kpcrr.uid,
  548. }
  549. return prometheus.NewDesc(kpcrr.fqName, kpcrr.help, []string{}, l)
  550. }
  551. // Write encodes the Metric into a "Metric" Protocol Buffer data transmission object.
  552. func (kpcrr KubeNodeStatusAllocatableMemoryBytesMetric) Write(m *dto.Metric) error {
  553. m.Gauge = &dto.Gauge{
  554. Value: &kpcrr.value,
  555. }
  556. m.Label = []*dto.LabelPair{
  557. {
  558. Name: toStringPtr("node"),
  559. Value: &kpcrr.node,
  560. },
  561. {
  562. Name: toStringPtr("uid"),
  563. Value: &kpcrr.uid,
  564. },
  565. }
  566. return nil
  567. }