ElijahCrafter

Server Rack Test

Dec 5th, 2025 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.62 KB | Source Code | 0 0
  1. -- Server Rack Cluster Test Script
  2. -- Supports multiple server racks using peripheral.group()
  3.  
  4. local racks = peripheral.group("server_rack")
  5. local lights = peripheral.group("led_floor_light")
  6.  
  7. if racks.count() == 0 then
  8.     print("No server racks found!")
  9.     return
  10. end
  11.  
  12. -- Light up all floor lights blue
  13. if lights.count() > 0 then
  14.     print("Lighting up " .. lights.count() .. " floor lights blue...")
  15.     lights.setColor(4)  -- Blue color
  16.     lights.turnOn()
  17. else
  18.     print("No LED floor lights found")
  19. end
  20.  
  21. print("")
  22. print("=== Server Rack Cluster ===")
  23. print("Connected Racks: " .. racks.count())
  24. print("")
  25.  
  26. -- Aggregate totals across all racks
  27. local totalRacks = 0
  28. local totalSlots = 0
  29. local activeServers = 0
  30. local emptySlots = 0
  31. local totalMemoryKB = 0
  32. local totalStorageKB = 0
  33. local totalComputePower = 0
  34. local maxCpuTier = 0
  35. local maxGpuTier = 0
  36. local maxRamTier = 0
  37. local maxStorageTier = 0
  38.  
  39. -- Collect info from each rack
  40. local rackInfos = {}
  41. racks.forEach(function(name, rack)
  42.     local info = rack.getClusterInfo()
  43.     rackInfos[name] = info
  44.    
  45.     totalRacks = totalRacks + info.rackCount
  46.     totalSlots = totalSlots + info.totalSlots
  47.     activeServers = activeServers + info.activeServers
  48.     emptySlots = emptySlots + info.emptySlots
  49.     totalMemoryKB = totalMemoryKB + info.totalMemoryKB
  50.     totalStorageKB = totalStorageKB + info.totalStorageKB
  51.     totalComputePower = totalComputePower + info.computePower
  52.    
  53.     -- Track highest tier components
  54.     maxCpuTier = math.max(maxCpuTier, info.cpuTier)
  55.     maxGpuTier = math.max(maxGpuTier, info.gpuTier)
  56.     maxRamTier = math.max(maxRamTier, info.ramTier)
  57.     maxStorageTier = math.max(maxStorageTier, info.storageTier)
  58. end)
  59.  
  60. -- Calculate average speed multiplier
  61. local avgSpeedMultiplier = 0
  62. local rackCount = racks.count()
  63. racks.forEach(function(name, rack)
  64.     local info = rack.getClusterInfo()
  65.     avgSpeedMultiplier = avgSpeedMultiplier + info.speedMultiplier
  66. end)
  67. avgSpeedMultiplier = avgSpeedMultiplier / rackCount
  68.  
  69. -- Show individual rack details
  70. print("=== Individual Racks ===")
  71. local i = 1
  72. for name, info in pairs(rackInfos) do
  73.     print(i .. ". " .. name)
  74.     print("   Servers: " .. info.activeServers .. "/" .. info.totalSlots)
  75.     print("   Memory: " .. math.floor(info.totalMemoryKB / 1024) .. " MB")
  76.     print("   Storage: " .. math.floor(info.totalStorageKB / 1024) .. " MB")
  77.     print("   Compute: " .. info.computePower)
  78.     i = i + 1
  79. end
  80.  
  81. -- Utility functions for cluster management
  82. print("")
  83. print("=== Cluster Commands ===")
  84. print("Use: cluster status  - Show this info")
  85. print("Use: cluster list    - List all racks")
  86. print("Use: cluster <name>  - Show specific rack")
  87.  
  88.  
  89. print("=== Cluster Totals ===")
  90. print("Total Rack Units: " .. totalRacks)
  91. print("Total Slots: " .. totalSlots)
  92. print("Active Servers: " .. activeServers)
  93. print("Empty Slots: " .. emptySlots)
  94. print("")
  95.  
  96. print("=== Best Hardware Tiers ===")
  97. print("Max CPU Tier: " .. maxCpuTier)
  98. print("Max GPU Tier: " .. maxGpuTier)
  99. print("Max RAM Tier: " .. maxRamTier)
  100. print("Max Storage Tier: " .. maxStorageTier)
  101. print("")
  102.  
  103. print("=== Combined Resources ===")
  104. print("Total Memory: " .. totalMemoryKB .. " KB (" .. math.floor(totalMemoryKB / 1024) .. " MB)")
  105. print("Total Storage: " .. totalStorageKB .. " KB (" .. math.floor(totalStorageKB / 1024) .. " MB)")
  106. print("Total Compute Power: " .. totalComputePower)
  107. print("Avg Speed Multiplier: " .. string.format("%.2f", avgSpeedMultiplier))
  108. print("")
  109. -- Handle command line arguments
  110. local args = {...}
  111. if args[1] == "list" then
  112.     print("")
  113.     print("Connected Racks:")
  114.     for _, name in ipairs(racks.getNames()) do
  115.         print("  - " .. name)
  116.     end
  117. elseif args[1] and args[1] ~= "status" then
  118.     -- Try to get specific rack
  119.     local rack = racks.getByName(args[1])
  120.     if not rack then
  121.         -- Try with server_rack_ prefix
  122.         rack = racks.getByName("server_rack_" .. args[1])
  123.     end
  124.     if rack then
  125.         local info = rack.getClusterInfo()
  126.         print("")
  127.         print("=== " .. args[1] .. " Details ===")
  128.         print("Slots: " .. info.activeServers .. "/" .. info.totalSlots)
  129.         print("CPU Tier: " .. info.cpuTier)
  130.         print("GPU Tier: " .. info.gpuTier)
  131.         print("RAM Tier: " .. info.ramTier)
  132.         print("Storage Tier: " .. info.storageTier)
  133.         print("Memory: " .. info.totalMemoryKB .. " KB")
  134.         print("Storage: " .. info.totalStorageKB .. " KB")
  135.         print("Compute Power: " .. info.computePower)
  136.         print("Speed Multiplier: " .. info.speedMultiplier)
  137.     else
  138.         print("Rack '" .. args[1] .. "' not found!")
  139.     end
  140. end
Add Comment
Please, Sign In to add comment