Reference Source

js/metrics/host/metrics_host_state.js

  1. // NPM IMPORTS
  2. import assert from 'assert'
  3.  
  4. // COMMON IMPORTS
  5. import T from 'devapt-core-common/dist/js/utils/types'
  6.  
  7. // SERVER IMPORTS
  8. import MetricsState from '../base/metrics_state'
  9.  
  10.  
  11. /**
  12. * Contextual constant for this file logs.
  13. * @private
  14. * @type {string}
  15. */
  16. const context = 'server/metrics/host/metrics_host_state'
  17.  
  18.  
  19.  
  20. /**
  21. * @file Host metrics state class.
  22. * @author Luc BORIES
  23. * @license Apache-2.0
  24. */
  25. export default class MetricHostState extends MetricsState
  26. {
  27. /**
  28. * Metrics host state constructor.
  29. *
  30. * @returns {nothing}
  31. */
  32. constructor()
  33. {
  34. super('host')
  35. /**
  36. * Class test flag.
  37. * @type {boolean}
  38. */
  39. this.is_metrics_host_state = true
  40. }
  41. /**
  42. * Add hostname state values.
  43. *
  44. * @param {string} arg_hostname - hostname valid string.
  45. *
  46. * @returns {nothing}
  47. */
  48. add_hostname(arg_hostname)
  49. {
  50. assert( T.isString(arg_hostname) && arg_hostname.length > 0, context + ':add_hostname: bad hostname string')
  51. if (arg_hostname in this.values)
  52. {
  53. return
  54. }
  55. // CREATE HOSTNAME VALUES
  56. this.values[arg_hostname] = {}
  57. // LAST SNAPSHOT
  58. this.values[arg_hostname].last_metric = undefined
  59. // CONTINUOUS AGGREGATION
  60. const aggregated_init = {
  61. hostname:undefined,
  62. count:0,
  63. cpus_arch:undefined,
  64. cpus_count:undefined,
  65. cpus_user_sum:0,
  66. cpus_nice_sum:0,
  67. cpus_sys_sum:0,
  68. cpus_idle_sum:0,
  69. cpus_irq_sum:0,
  70. cpus_user_mean:undefined,
  71. cpus_nice_mean:undefined,
  72. cpus_sys_mean:undefined,
  73. cpus_idle_mean:undefined,
  74. cpus_irq_mean:undefined
  75. }
  76. this.values[arg_hostname].aggregated = Object.assign({}, aggregated_init)
  77. }
  78. }