Job to clean up outdated monitoring data.
This commit is contained in:
parent
b84bfb5c99
commit
e03be8bf51
3 changed files with 36 additions and 1 deletions
13
server/jobs/nodeInformationCleanupJob.js
Normal file
13
server/jobs/nodeInformationCleanupJob.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng').factory('NodeInformationCleanupJob', function (MonitoringService, Logger) {
|
||||
return {
|
||||
run: function () {
|
||||
MonitoringService.cleanupNodeInformation(function (err) {
|
||||
if (err) {
|
||||
Logger.tag('monitoring', 'information-cleanup').error('Error cleaning up node data:', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -32,7 +32,7 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger, confi
|
|||
|
||||
if (config.client.monitoring.enabled) {
|
||||
schedule('30 */5 * * * *', 'NodeInformationRetrievalJob');
|
||||
// schedule('0 */1 * * * *', 'NodeInformationCleanupJob');
|
||||
schedule('0 0 3 * * *', 'NodeInformationCleanupJob'); // every night at 3:00
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
|
|
@ -307,6 +307,28 @@ angular.module('ffffng')
|
|||
);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
cleanupNodeInformation: function (callback) {
|
||||
var daysBeforeCleanup = 30;
|
||||
Logger
|
||||
.tag('monitoring', 'information-cleanup')
|
||||
.info('Cleaning up node data not updated for %s days...', daysBeforeCleanup);
|
||||
Database.run(
|
||||
'DELETE FROM node_state WHERE modified_at < ?',
|
||||
[moment().subtract(daysBeforeCleanup, 'days').unix()],
|
||||
function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Logger
|
||||
.tag('monitoring', 'information-retrieval')
|
||||
.info('Node data cleanup done.');
|
||||
|
||||
callback();
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue