schema.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_slurm_table_schemas():
  29. """build_slurm_table_schemas Build Slurm Table Schemas
  30. Build slurm table schemas for storing resource usage metrics obtained from
  31. slurm
  32. Returns:
  33. dict: slurm table schemas
  34. """
  35. table_schemas = {}
  36. add_tables = {
  37. 'memoryusage':{
  38. 'add_columns': ['Value'],
  39. 'add_types': ['REAL']
  40. },
  41. 'memory_used':{
  42. 'add_columns': ['Value'],
  43. 'add_types': ['INT']
  44. },
  45. 'cpu_load':{
  46. 'add_columns': ['Value'],
  47. 'add_types': ['INT']
  48. },
  49. 'state':{
  50. 'add_columns': ['Value'],
  51. 'add_types': ['INT']
  52. },
  53. 'node_jobs':{
  54. 'add_columns': ['Jobs', 'CPUs'],
  55. 'add_types': ['INTEGER[]', 'INTEGER[]']
  56. }
  57. }
  58. try:
  59. for table_name, detail in add_tables.items():
  60. column_names = ['Timestamp', 'NodeID']
  61. column_types = ['TIMESTAMPTZ NOT NULL', 'INT NOT NULL']
  62. column_names.extend(detail['add_columns'])
  63. column_types.extend(detail['add_types'])
  64. table_schemas.update({
  65. table_name: {
  66. 'column_names': column_names,
  67. 'column_types': column_types
  68. }
  69. })
  70. except Exception as err:
  71. log.error(f'Cannot build slurm table schemas: {err}')
  72. return table_schemas