schema.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. """
  2. MIT License
  3. Copyright (c) 2022 Texas Tech University
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. """
  21. This file is part of MonSter.
  22. Author:
  23. Jie Li, jie.li@ttu.edu
  24. """
  25. import utils
  26. import logger
  27. log = logger.get_logger(__name__)
  28. def build_idrac_table_schemas(metric_definitions: list):
  29. """build_table_schemas Build iDRAC Table Schemas
  30. Build table schemas based on the idrac telemetry metric definitions
  31. Args:
  32. metric_definitions (list): idrac telemetry metric definitions
  33. Returns:
  34. dict: iDRAC table schemas
  35. """
  36. table_schemas = {}
  37. try:
  38. for metric in metric_definitions:
  39. table_name = metric['Id']
  40. metric_type = metric['MetricDataType']
  41. metric_unit = metric.get('Units', None)
  42. # For network metrics, use BIG INT for storing the metric readings
  43. if metric_unit == 'By' or metric_unit == 'Pkt':
  44. value_type = 'BIGINT'
  45. else:
  46. value_type = utils.data_type_mapping.get(metric_type, 'TEXT')
  47. column_names = ['Timestamp', 'NodeID', 'Source', 'FQDD', 'Value']
  48. column_types = ['TIMESTAMPTZ NOT NULL', 'INT NOT NULL', 'TEXT', \
  49. 'TEXT', value_type]
  50. table_schemas.update({
  51. table_name: {
  52. 'column_names': column_names,
  53. 'column_types': column_types,
  54. }
  55. })
  56. except Exception as err:
  57. log.error(f"Cannot build idrac table schemas: {err}")
  58. return table_schemas
  59. def build_slurm_table_schemas():
  60. """build_slurm_table_schemas Build Slurm Table Schemas
  61. Build slurm table schemas for storing resource usage metrics obtained from
  62. slurm
  63. Returns:
  64. dict: slurm table schemas
  65. """
  66. table_schemas = {}
  67. add_tables = {
  68. 'memoryusage':{
  69. 'add_columns': ['Value'],
  70. 'add_types': ['REAL']
  71. },
  72. 'memory_used':{
  73. 'add_columns': ['Value'],
  74. 'add_types': ['INT']
  75. },
  76. 'cpu_load':{
  77. 'add_columns': ['Value'],
  78. 'add_types': ['INT']
  79. },
  80. 'state':{
  81. 'add_columns': ['Value'],
  82. 'add_types': ['INT']
  83. },
  84. 'node_jobs':{
  85. 'add_columns': ['Jobs', 'CPUs'],
  86. 'add_types': ['INTEGER[]', 'INTEGER[]']
  87. }
  88. }
  89. try:
  90. for table_name, detail in add_tables.items():
  91. column_names = ['Timestamp', 'NodeID']
  92. column_types = ['TIMESTAMPTZ NOT NULL', 'INT NOT NULL']
  93. column_names.extend(detail['add_columns'])
  94. column_types.extend(detail['add_types'])
  95. table_schemas.update({
  96. table_name: {
  97. 'column_names': column_names,
  98. 'column_types': column_types
  99. }
  100. })
  101. except Exception as err:
  102. log.error(f'Cannot build slurm table schemas: {err}')
  103. return table_schemas