forked from bkconrad/screeps-grafana
-
Notifications
You must be signed in to change notification settings - Fork 27
/
stats.js
38 lines (33 loc) · 1.32 KB
/
stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Call this function at the end of your main loop
function exportStats() {
// Reset stats object
Memory.stats = {
gcl: {},
rooms: {},
cpu: {},
};
Memory.stats.time = Game.time;
// Collect room stats
for (let roomName in Game.rooms) {
let room = Game.rooms[roomName];
let isMyRoom = (room.controller ? room.controller.my : false);
if (isMyRoom) {
let roomStats = Memory.stats.rooms[roomName] = {};
roomStats.storageEnergy = (room.storage ? room.storage.store.energy : 0);
roomStats.terminalEnergy = (room.terminal ? room.terminal.store.energy : 0);
roomStats.energyAvailable = room.energyAvailable;
roomStats.energyCapacityAvailable = room.energyCapacityAvailable;
roomStats.controllerProgress = room.controller.progress;
roomStats.controllerProgressTotal = room.controller.progressTotal;
roomStats.controllerLevel = room.controller.level;
}
}
// Collect GCL stats
Memory.stats.gcl.progress = Game.gcl.progress;
Memory.stats.gcl.progressTotal = Game.gcl.progressTotal;
Memory.stats.gcl.level = Game.gcl.level;
// Collect CPU stats
Memory.stats.cpu.bucket = Game.cpu.bucket;
Memory.stats.cpu.limit = Game.cpu.limit;
Memory.stats.cpu.used = Game.cpu.getUsed();
}