Adding StackDriver Monitoring in Google App Engine NodeJs Flexible env ??

113 views
Skip to first unread message

Sudhanshu Gaur

unread,
Apr 4, 2018, 1:32:22 PM4/4/18
to Google App Engine

I am trying to add Stackdriver Monitoring/Trace/Debugger/Profiler in my Google App Engine NodeJs App(Flexible env), now in order to add all of them i have added below code

// Google Trace API
require('@google-cloud/trace-agent').start();
// Google Trace API

//
require('@google-cloud/profiler').start();
//

// Google Debugger
require('@google-cloud/debug-agent').start();
// Google Debugger

But for Adding Monitoring we have to explicity define project-id and other things.

// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Creates a client
const client = new monitoring.MetricServiceClient();

// Prepares an individual data point
const dataPoint = {
  interval: {
    endTime: {
      seconds: Date.now() / 1000,
    },
  },
  value: {
    // The amount of sales
    doubleValue: 123.45,
  },
};

// Prepares the time series request
const request = {
  name: client.projectPath(projectId),
  timeSeries: [
    {
      // Ties the data point to a custom metric
      metric: {
        type: 'custom.googleapis.com/stores/daily_sales',
        labels: {
          store_id: 'Pittsburgh',
        },
      },
      resource: {
        type: 'global',
        labels: {
          project_id: projectId,
        },
      },
      points: [dataPoint],
    },
  ],
};

// Writes time series data
client
  .createTimeSeries(request)
  .then(results => {
    console.log(`Done writing time series data.`, results[0]);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Now i am just wondering are these steps defined for adding CLoud Monitoring to VM's or other machines other than App Engine, or these steps are for App Engine also.

Kenworth (Google Cloud Platform)

unread,
Apr 4, 2018, 6:13:53 PM4/4/18
to Google App Engine
The trace-agent and the monitoring client libraries are two separate libraries, thus the different ways of usage/configuration.

For the profiler (trace-agent), some environments require a configuration to be passed to the start() function and some does not (like GAE flex). See details here for running outside Google Cloud, on GAE Flex, or on Compute/Container engines. 

For the monitoring agent, however, the 'project-id' is required at all times.
Reply all
Reply to author
Forward
0 new messages