mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-05-29 21:42:30 +02:00
Solo mining stats
This commit is contained in:
parent
66869ad699
commit
fe4d209709
@ -10,6 +10,7 @@ module.exports.typeDefs = `
|
|||||||
|
|
||||||
type MinerStatsResult {
|
type MinerStatsResult {
|
||||||
stats: [MinerStats]
|
stats: [MinerStats]
|
||||||
|
ckpool: MinerStatsCkpool
|
||||||
}
|
}
|
||||||
|
|
||||||
type MinerStats {
|
type MinerStats {
|
||||||
@ -24,7 +25,6 @@ module.exports.typeDefs = `
|
|||||||
temperature: MinerStatsTemperature
|
temperature: MinerStatsTemperature
|
||||||
slots: MinerStatsSlots
|
slots: MinerStatsSlots
|
||||||
slaves: [MinerStatsSlave]
|
slaves: [MinerStatsSlave]
|
||||||
ckpool: MinerStatsCkpool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MinerStatsVersion {
|
type MinerStatsVersion {
|
||||||
|
@ -14,7 +14,8 @@ module.exports = ({ define }) => {
|
|||||||
const settings = await dispatch('api/settings/collection/read');
|
const settings = await dispatch('api/settings/collection/read');
|
||||||
const { items: pools } = await dispatch('api/pools/collection/read', {});
|
const { items: pools } = await dispatch('api/pools/collection/read', {});
|
||||||
const stats = await getMinerStats(errors, settings, pools);
|
const stats = await getMinerStats(errors, settings, pools);
|
||||||
return { stats };
|
const ckpoolStats = await getCkpoolStats(errors, settings, pools);
|
||||||
|
return { stats, ckpool: ckpoolStats };
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
auth: true,
|
auth: true,
|
||||||
@ -33,7 +34,7 @@ const parseFileToJsonArray = async (filePath) => {
|
|||||||
const allKeys = {};
|
const allKeys = {};
|
||||||
|
|
||||||
// Analyze each line
|
// Analyze each line
|
||||||
lines.forEach(line => {
|
lines.forEach((line) => {
|
||||||
if (line.trim() !== '') {
|
if (line.trim() !== '') {
|
||||||
try {
|
try {
|
||||||
const jsonObject = JSON.parse(line);
|
const jsonObject = JSON.parse(line);
|
||||||
@ -46,7 +47,9 @@ const parseFileToJsonArray = async (filePath) => {
|
|||||||
allKeys[key] = value;
|
allKeys[key] = value;
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error during the parsing of the line: ${error.message}`);
|
console.error(
|
||||||
|
`Error during the parsing of the line: ${error.message}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -56,25 +59,15 @@ const parseFileToJsonArray = async (filePath) => {
|
|||||||
console.error(`Error during the reading of the file: ${error.message}`);
|
console.error(`Error during the reading of the file: ${error.message}`);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const getMinerStats = async (errors, settings, pools) => {
|
const getCkpoolStats = async (errors, settings, pools) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
// Get ckpool data
|
||||||
|
let ckpoolData = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const statsDir = path.resolve(
|
|
||||||
__dirname,
|
|
||||||
'../../../../backend/apollo-miner/'
|
|
||||||
);
|
|
||||||
const statsFilePattern = 'apollo-miner.*';
|
|
||||||
let statsFiles = await fs.readdir(statsDir);
|
|
||||||
statsFiles = _.filter(statsFiles, (f) => {
|
|
||||||
return f.match(statsFilePattern);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get ckpool data
|
|
||||||
let ckpoolData = null;
|
|
||||||
|
|
||||||
if (settings?.nodeEnableSoloMining) {
|
if (settings?.nodeEnableSoloMining) {
|
||||||
const poolUsername = pools[0] && pools[0].username;
|
const poolUsername = pools[0] && pools[0].username;
|
||||||
const ckpoolPoolStatsFile = path.resolve(
|
const ckpoolPoolStatsFile = path.resolve(
|
||||||
@ -93,8 +86,13 @@ const getMinerStats = async (errors, settings, pools) => {
|
|||||||
) {
|
) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
(async () => {
|
(async () => {
|
||||||
let ckpoolPoolData = await parseFileToJsonArray(ckpoolPoolStatsFile);
|
let ckpoolPoolData = await parseFileToJsonArray(
|
||||||
let ckpoolUsersData = await fs.readFile(ckpoolUsersStatsFile, 'utf8');
|
ckpoolPoolStatsFile
|
||||||
|
);
|
||||||
|
let ckpoolUsersData = await fs.readFile(
|
||||||
|
ckpoolUsersStatsFile,
|
||||||
|
'utf8'
|
||||||
|
);
|
||||||
|
|
||||||
ckpoolUsersData = JSON.parse(ckpoolUsersData);
|
ckpoolUsersData = JSON.parse(ckpoolUsersData);
|
||||||
|
|
||||||
@ -107,6 +105,28 @@ const getMinerStats = async (errors, settings, pools) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolve(ckpoolData);
|
||||||
|
} catch (err) {
|
||||||
|
reject(new errors.InternalError(err.toString()));
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMinerStats = async (errors, settings, pools) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const statsDir = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
'../../../../backend/apollo-miner/'
|
||||||
|
);
|
||||||
|
const statsFilePattern = 'apollo-miner.*';
|
||||||
|
let statsFiles = await fs.readdir(statsDir);
|
||||||
|
statsFiles = _.filter(statsFiles, (f) => {
|
||||||
|
return f.match(statsFilePattern);
|
||||||
|
});
|
||||||
|
|
||||||
let stats = [];
|
let stats = [];
|
||||||
|
|
||||||
const findFileDetails = (fileName) => {
|
const findFileDetails = (fileName) => {
|
||||||
@ -167,8 +187,6 @@ const getMinerStats = async (errors, settings, pools) => {
|
|||||||
.utcOffset(offset)
|
.utcOffset(offset)
|
||||||
.format();
|
.format();
|
||||||
|
|
||||||
if (ckpoolData) received.ckpool = ckpoolData;
|
|
||||||
|
|
||||||
stats.push(received);
|
stats.push(received);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -179,4 +197,4 @@ const getMinerStats = async (errors, settings, pools) => {
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
@ -105,6 +105,9 @@ module.exports.auth = {
|
|||||||
exec('sudo systemctl daemon-reload');
|
exec('sudo systemctl daemon-reload');
|
||||||
exec('sudo systemctl enable ckpool');
|
exec('sudo systemctl enable ckpool');
|
||||||
exec('sudo systemctl restart ckpool');
|
exec('sudo systemctl restart ckpool');
|
||||||
|
} else {
|
||||||
|
exec('sudo systemctl stop ckpool');
|
||||||
|
exec('sudo systemctl disable ckpool');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.nodeEnableTor) {
|
if (settings.nodeEnableTor) {
|
||||||
|
Loading…
Reference in New Issue
Block a user