Advertisement
osmarks

AE2 metric exporter

Jun 7th, 2021 (edited)
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. local ae2 = peripheral.wrap "right"
  2. local m = peripheral.find "modem"
  3.  
  4. local items = {
  5.     "minecraft:redstone",
  6.     "minecraft:quartz",
  7.     "minecraft:glowstone_dust",
  8.     "minecraft:iron_ingot",
  9.     "appliedenergistics2:material",
  10.     { name="minecraft:planks", damage = 5 },
  11.     "minecraft:coal",
  12.     "minecraft:diamond"
  13. }
  14. local dn_cache = {}
  15.  
  16. local function send_metric(...)
  17.     m.transmit(3054, 3054, {...})
  18. end
  19.  
  20. while true do
  21.     local cpus = ae2.getCraftingCPUs()
  22.     local cpucount = 0
  23.     for _, cpu in pairs(cpus) do if cpu.busy then cpucount = cpucount + 1 end end
  24.     send_metric("busy_crafting_cpus", "number of crafting CPUs operating", "set", cpucount)
  25.     for _, id in pairs(items) do
  26.         local ok, i = pcall(ae2.findItem, id)
  27.         local count = 0
  28.         if ok and i then
  29.             local meta = i.getMetadata()
  30.             dn_cache[id] = meta.displayName
  31.             count = meta.count
  32.         end
  33.         if dn_cache[id] then
  34.             send_metric("items/" .. dn_cache[id], "stored items in ME network", "set", count)
  35.         end
  36.     end
  37.     sleep(1)
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement