Skip to content

Commit a266949

Browse files
committed
Enable appmetrics to read properties
1 parent 53db39a commit a266949

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

headless_zip.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function onError(err) {
2727
}
2828

2929
function deleteDir(directory) {
30-
console.log('Deleting directory: ' + directory)
3130
// Delete temporary directory
3231
if(fs.existsSync(directory)) {
3332
fs.readdirSync(directory).forEach(function(file,index){
@@ -65,7 +64,6 @@ module.exports.headlessZip = function headlessZip(dirToZip) {
6564
} else {
6665
outputFileName = 'nodeappmetrics' + timestamp() + '.hcd'
6766
}
68-
console.log("zipping: " + dirToZip + " to file: " + outputFileName + "\n")
6967

7068
var packer = tar.Pack({ fromBase: true })
7169
.on('error', onError)

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ module.exports.monitor = function() {
249249

250250
if (typeof(this.api) == 'undefined') {
251251
agent.start();
252-
this.api = hcAPI.getAPI(agent, module.exports);
252+
this.api = hcAPI.getAPI(agent, module.exports);
253+
var headlessOutputDir = agent.getOption('com.ibm.diagnostics.healthcenter.headless.output.directory');
254+
if(headlessOutputDir) {
255+
headlessZip.setHeadlessOutputDir(headlessOutputDir);
256+
}
253257
}
254258
return this.api;
255259
};
@@ -287,8 +291,13 @@ module.exports.getJSONProfilingMode = function() {
287291

288292
module.exports.start = function () {
289293
agent.setOption(propertyMappings['applicationID'], main_filename);
294+
var headlessOutputDir = agent.getOption('com.ibm.diagnostics.healthcenter.headless.output.directory');
295+
if(headlessOutputDir) {
296+
headlessZip.setHeadlessOutputDir(headlessOutputDir);
297+
}
290298
agent.start();
291299
}
300+
292301
module.exports.nodereport = function() {
293302
return nodereport;
294303
}

src/appmetrics.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,24 @@ NAN_METHOD(setOption) {
299299
}
300300
}
301301

302+
// set the property to given value (called from index.js)
303+
NAN_METHOD(getOption) {
304+
if (info.Length() > 0) {
305+
//Nan::NanScope();
306+
Local<String> value = info[0]->ToString();
307+
printf(toStdString(value).c_str());
308+
std::string property = loaderApi->getProperty(toStdString(value).c_str());
309+
printf("*** HEADLESS OUTPUT PROPERTY =");
310+
printf(property.c_str());
311+
printf(" ***\n");
312+
v8::Local<v8::String> v8str = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), property.c_str());
313+
info.GetReturnValue().Set<v8::String>(v8str);
314+
//Nan::NanReturnValue(NanNew<String>(loaderApi->getProperty(toStdString(value).c_str())));
315+
} else {
316+
loaderApi->logMessage(warning, "Incorrect number of parameters passed to getOption");
317+
}
318+
}
319+
302320
NAN_METHOD(start) {
303321
if (!running) {
304322
running = true;
@@ -659,6 +677,7 @@ void init(Local<Object> exports, Local<Object> module) {
659677
/*
660678
* Set exported functions
661679
*/
680+
exports->Set(Nan::New<String>("getOption").ToLocalChecked(), Nan::New<FunctionTemplate>(getOption)->GetFunction());
662681
exports->Set(Nan::New<String>("setOption").ToLocalChecked(), Nan::New<FunctionTemplate>(setOption)->GetFunction());
663682
exports->Set(Nan::New<String>("start").ToLocalChecked(), Nan::New<FunctionTemplate>(start)->GetFunction());
664683
exports->Set(Nan::New<String>("spath").ToLocalChecked(), Nan::New<FunctionTemplate>(spath)->GetFunction());

0 commit comments

Comments
 (0)