Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking total RAM #502

Merged
merged 5 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions public/services/resolves/check-ram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Wazuh app - Module to check total RAM available
* Copyright (C) 2018 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
export default async (genericReq, errorHandler) => {
try {
const data = await genericReq.request('GET', '/api/wazuh-api/ram');
const totalRAM = data.data.ram
if(totalRAM < 3072 && totalRAM > 2048) {
errorHandler.handle(`Kibana server has ${totalRAM}MB of RAM, performance will suffer. Please increase it.`, 'RAM', true);
} else if(totalRAM <= 2048) {
errorHandler.handle(`Kibana server has ${totalRAM}MB of RAM, performance will suffer. Please increase it.`, 'RAM');
}
} catch (error){
errorHandler.handle(`Kibana server has an unknown amount of RAM, please review it.`, 'RAM', true);
}
}
3 changes: 2 additions & 1 deletion public/services/resolves/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ import settingsWizard from './settings-wizard'
import getSavedSearch from './get-saved-search'
import goToKibana from './go-to-kibana'
import getIp from './get-ip'
import totalRAM from './check-ram'

export { checkTimestamp, healthCheck, settingsWizard, getSavedSearch, goToKibana, getIp }
export { checkTimestamp, healthCheck, settingsWizard, getSavedSearch, goToKibana, getIp, totalRAM }
3 changes: 3 additions & 0 deletions public/services/resolves/settings-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
*/
import checkTimestamp from './check-timestamp'
import healthCheck from './health-check'
import totalRAM from './check-ram'

export default ($rootScope, $location, $q, $window, testAPI, appState, genericReq, errorHandler) => {
try {
const deferred = $q.defer();

totalRAM(genericReq,errorHandler);

// Save current location if we aren't performing a health-check, to later be able to come back to the same tab
if (!$location.path().includes("/health-check")) {
$rootScope.previousLocation = $location.path();
Expand Down
13 changes: 12 additions & 1 deletion server/controllers/wazuh-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import monitoring from '../monitoring'
import ErrorResponse from './error-response'
import { Parser } from 'json2csv';
import getConfiguration from '../lib/get-configuration'
import { totalmem } from 'os'

const blueWazuh = colors.blue('wazuh');

Expand Down Expand Up @@ -386,7 +387,7 @@ export default class WazuhApi {
if(req.payload.method !== 'GET' && req.payload.body && req.payload.body.devTools){
const configuration = getConfiguration();
if(!configuration || (configuration && !configuration['devtools.allowall'])){
return ErrorResponse('Allowed method: [GET]', 3023, 400, reply);
return ErrorResponse('Allowed method: [GET]', 3029, 400, reply);
}
}
if(req.payload.body.devTools) {
Expand Down Expand Up @@ -528,4 +529,14 @@ export default class WazuhApi {
return res({ error: error.message || error }).code(500)
}
}

async totalRam(req,reply) {
try{
// RAM in MB
const ram = Math.ceil(totalmem()/1024/1024);
return reply({ statusCode: 200, error: 0, ram });
} catch (error) {
return ErrorResponse(error.message || error, 3030, 500, reply);
}
}
}
3 changes: 3 additions & 0 deletions server/routes/wazuh-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ export default (server, options) => {

// Returns data from the Wazuh API on CSV readable format
server.route({ method: 'POST', path: '/api/wazuh-api/csv', handler: (req,res) => ctrl.csv(req,res)})

// Returns total RAM available from the current machine where Kibana is being executed
server.route({ method: 'GET', path: '/api/wazuh-api/ram', handler: (req,res) => ctrl.totalRam(req,res)})
};