Skip to content

Commit

Permalink
ADD: CPU usage monitoring command (#304)
Browse files Browse the repository at this point in the history
* ADD: CPU usage monitoring command

* bump to v2.0.2 [skip ci]

Co-authored-by: Automated Version Bump <[email protected]>
Co-authored-by: stefa2k <[email protected]>
  • Loading branch information
3 people authored May 20, 2022
1 parent a297e0e commit 35e55d7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions launcher/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion launcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stereum-launcher",
"version": "2.0.0",
"version": "2.0.3",
"private": true,
"description": "Stereum Ethereum Node Setup Launcher",
"author": "stereum.net",
Expand Down
17 changes: 17 additions & 0 deletions launcher/src/backend/NodeConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,21 @@ export class NodeConnection {
rm -rf /etc/stereum`)
return 'Node destroyed'
}


// cpuUsage return values:
// rc: 0 if everything went fine
// stdout: console output normally CPU-Usage
// stderr: console error output empty when rc is 0 else the occured error

// use "import ControlService from '@/store/ControlService'"" in the file you need the data
// you then can call it with "await ControlService.getServerVitals()"
// use await or handle the promise with .then and .catch
// the function needs to be async
async getServerVitals(){
let response = {}
const cpuUsage = await this.sshService.exec(`sar -u 1 1 | awk '{if ($7 != "%idle") print 100.000-$NF}' | tail -1`) //CPU usage
response.cpuUsage = cpuUsage;
return response
}
}
4 changes: 4 additions & 0 deletions launcher/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ promiseIpc.on("startOneClickServices", async () => {
return await oneClickInstall.startServices();
});

promiseIpc.on("getServerVitals", async () => {
return await nodeConnection.getServerVitals();
})

// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } },
Expand Down
10 changes: 7 additions & 3 deletions launcher/src/store/ControlService.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,23 @@ class ControlService extends EventEmitter {

async getOneClickConstellation (args) {
return await this.promiseIpc.send('getOneClickConstellation', args)
}
}

async prepareOneClickInstallation (args) {
return await this.promiseIpc.send('prepareOneClickInstallation', args)
}
}

async writeOneClickConfiguration () {
return await this.promiseIpc.send('writeOneClickConfiguration')
}
}

async startOneClickServices () {
return await this.promiseIpc.send('startOneClickServices')
}

async getServerVitals(){
return await this.promiseIpc.send('getServerVitals')
}
}
if (!instance) {
instance = new ControlService(window.electron)
Expand Down

0 comments on commit 35e55d7

Please sign in to comment.