mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 00:23:12 +09:00
Added new plugin for reporting production/kills/construction statistics to Prometheus
This commit is contained in:
1 parent
aaf4d8b6f1
commit
52d35ab955
4 files changed
+127
No files matched your search
@@ -0,0 +1,40 @@
|
||||
const needle = require("needle");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const clusterTools = require("_app/clusterTools")();
|
||||
const pluginConfig = require("./config");
|
||||
|
||||
module.exports = class remoteCommands {
|
||||
constructor(mergedConfig, messageInterface, extras){
|
||||
this.messageInterface = messageInterface;
|
||||
this.config = mergedConfig;
|
||||
|
||||
const needleOptionsWithTokenAuthHeader = {
|
||||
headers: {
|
||||
'x-access-token': this.config.masterAuthToken
|
||||
},
|
||||
};
|
||||
|
||||
// Gather and submit statistics every 15 seconds
|
||||
setInterval(async () => {
|
||||
let stats = await this.getStats();
|
||||
stats.forEach(force => {
|
||||
needle.post(`${mergedConfig.masterIP}:${mergedConfig.masterPort}/api/logStats`, {
|
||||
instanceID: this.config.unique,
|
||||
force: force.forceName,
|
||||
data: force.data,
|
||||
}, needleOptionsWithTokenAuthHeader, (err, resp) => {
|
||||
if(!err && resp.body && resp.body.ok == false) console.log(resp.body);
|
||||
});
|
||||
});
|
||||
}, 15000);
|
||||
}
|
||||
async getStats(){
|
||||
let command = fs.readFileSync(path.join(__dirname, "Lua/exportStatistics.lua"), "utf8")//clusterTools.getLua(path.join(__dirname, "Lua/exportStatistics.lua"), false);
|
||||
let string = await this.messageInterface(`/silent-command ${command}`);
|
||||
var data;
|
||||
eval(`data = ${string}`);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user