Posting memory utilization metrics of aws instance by using nodeJs

I want to get Memory utilization metrics' data of aws instance on my project using nodeJs but i found out that memory Utilization metrics is not a default metrics so i have tried what's given on this page - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html and it worked as shown in figure memory Utilization metrics but i want to know how to post this metric using nodeJs.

This is the params i have written while using putMetricData -

AWS.config.update({ region: 'ap-south-1' });
var instanceId = 'i-096d2fed45f9ee1'
var params = {
    MetricData: [ /* required */
      {
        MetricName: 'MemoryUtilization', /* required */
        // Counts: [
        //   'NUMBER_VALUE',
        //   /* more items */
        // ],
        Dimensions: [
          {
            Name: 'InstanceId', /* required */
            Value: instanceId /* required */
          },
          /* more items */
        ],
        StatisticValues: {
          Maximum: 100, /* required */
          Minimum: 5, /* required */
          SampleCount: 1, /* required */
          Sum: 5 /* required */
        },
        // Timestamp: new Date || 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)' || 123456789,
        // Unit: Percent,
        // Value: 'NUMBER_VALUE',
        // Values: [
        //   'NUMBER_VALUE',
        //   /* more items */
        // ]
      },
      /* more items */
    ],
    Namespace: 'System/Linux' /* required */
};
cw.putMetricData(params, function(err, data) {
        if (err) {
          console.log("Error", err);
        } else {
          console.log("Metrics", JSON.stringify(data));
        }
});

I didn't get any error but value of memory utilization are coming like this as shown in image - memory Util metrics after posting through putMetricsData which is not correct if you see memory Utilization metrics generated by CloudWatch monitoring scripts.

1 answer