Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


Appdynamics node js custom instrument

14 Oct 2021 »
var http = require('http');

var appd = require("appdynamics")
appd.profile({
  controllerHostName: '<controllerhostname>',
  controllerPort: 443,
  controllerSslEnabled: true,  // Set to true if controllerPort is SSL
  accountName: '<accname>',
  accountAccessKey: '<accesskey>', //required
  applicationName: 'demo_app',
  tierName: 'node_tier', 
  nodeName: 'pod-dfasdf' 
});

//The url we want is `www.nodejitsu.com:1337/`
var options = {
  host: 'quarkus2-lab',
  path: '/challenges/list',
  //since we are listening on a custom port, we need to specify it by hand
  port: '8000',
  //This is what changes the request to a POST request
  method: 'GET'
};
var options2 = {
  host: 'localhost',
  path: '/api/books',
  //since we are listening on a custom port, we need to specify it by hand
  port: '8702',
  //This is what changes the request to a POST request
  method: 'GET'
};

callback = function(response) {
  var str = ''
  response.on('data', function (chunk) {
      str += chunk
  });

  response.on('end', function () {
    console.log(str);
  });
}

const run = () => {
    setTimeout(async function runner(){
        var transaction = appd.startTransaction('node_runner')
        const res = await http.request(options, callback).end()
        transaction.end()
        var transaction2 = appd.startTransaction('quarkus_runner')
        const res2 = await http.request(options2, callback).end()
        transaction2.end()
        run()
        
    }, 2000)
}

run()