Guest User

Untitled

a guest
Jul 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import pygame
  5. import sys
  6. import time
  7. from subprocess import check_output
  8.  
  9. threshold = 1000
  10.  
  11.  
  12. def render_stat(stat, font, screen):
  13. for i, (machine, status) in enumerate(stat.items()):
  14. textsurface = None
  15. if status == 'busy':
  16. text = u"{} is busy".format(machine)
  17. color = (255, 0, 0)
  18. elif status == 'free':
  19. text = u"{} is free".format(machine)
  20. color = (0, 255, 0)
  21. else:
  22. text = u"{} is unavailable".format(machine)
  23. color = (128, 0, 128)
  24. textsurface = font.render(text, False, color)
  25. screen.blit(textsurface, (20, 200 + 250 * i))
  26.  
  27.  
  28. def check_local():
  29. try:
  30. free_mem = int(
  31. check_output(
  32. [
  33. 'nvidia-smi', '--query-gpu=memory.used',
  34. '--format=csv,nounits,noheader'
  35. ],
  36. timeout=10))
  37. if free_mem > threshold:
  38. return 'busy'
  39. else:
  40. return 'free'
  41. except:
  42. return 'err'
  43.  
  44.  
  45. def check_remote(address, port=22):
  46. try:
  47. free_mem = int(
  48. check_output(
  49. [
  50. 'ssh', address, '-p',
  51. str(port), '-t', 'nvidia-smi', '--query-gpu=memory.used',
  52. '--format=csv,nounits,noheader'
  53. ],
  54. timeout=10))
  55. if free_mem > threshold:
  56. return 'busy'
  57. else:
  58. return 'free'
  59. except:
  60. return 'err'
  61.  
  62.  
  63. pygame.init()
  64. size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
  65. screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
  66. pygame.font.init()
  67. myfont = pygame.font.SysFont('DejaVuSans', 100, bold=True)
  68. stat = {}
  69.  
  70. while True:
  71. stat[u'Name1'] = check_local()
  72. stat[u'Name2'] = check_remote('user@address')
  73.  
  74. screen.fill((0, 0, 0))
  75. render_stat(stat, myfont, screen)
  76. pygame.display.flip()
  77. time.sleep(10)
Add Comment
Please, Sign In to add comment