var AWS = require('aws-sdk'); var os = require('os'); new AWS.MetadataService().request("/latest/meta-data/instance-id", function (err, data) { var instanceId = data; var total = os.totalmem(); var free = os.freemem(); var value = (total - free) * 100 / total; var cloudwatch = new AWS.CloudWatch({region: 'ap-northeast-1'}); var params = { MetricData: [ { MetricName: 'FreeMemorySpace', Dimensions: [ { Name: 'InstanceId', Value: instanceId }, ], Timestamp: new Date (), Unit: 'Megabytes', Value: free / 1048576.0 }, ], Namespace: 'Windows System' /* required */ }; cloudwatch.putMetricData(params, function(err, data) { if (err) console.log(err, err.stack); // an error occurred else console.log(data); // successful response }); });