Created
August 21, 2018 15:15
-
-
Save dave-malone/e035684cd93d2fe550db0a61d4228132 to your computer and use it in GitHub Desktop.
A simple node program that uses the fast-speedtest-api npm package to test internet bandwidth and publishes it to CloudWatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FastSpeedtest = require("fast-speedtest-api") | |
const AWS = require('aws-sdk') | |
AWS.config.update({region: 'us-east-1'}) | |
const cloudwatch = new AWS.CloudWatch() | |
let speedtest = new FastSpeedtest({ | |
token: "INSERT-YOUR-TOKEN-HERE", | |
verbose: false, | |
timeout: 10000, | |
https: true, | |
urlCount: 5, | |
bufferSize: 8, | |
unit: FastSpeedtest.UNITS.Mbps | |
}) | |
speedtest.getSpeed().then((s) => { | |
console.log(`Speed: ${s} Mbps`) | |
let cloudWatchPayload = { | |
MetricData: [ | |
{ | |
MetricName: 'bandwidth_mbps', | |
StorageResolution: 1, | |
Timestamp: new Date(), | |
Unit: "Megabytes/Second", | |
Value: s | |
}, | |
], | |
Namespace: 'FastSpeedtest' | |
} | |
cloudwatch.putMetricData(cloudWatchPayload, (err, response) => { | |
if(err){ | |
console.log(`Failed to publish speed test metrics to CloudWatch: ${err}`, err.stack) | |
}else{ | |
console.log(`CloudWatch publish response: ${JSON.stringify(response)}`) | |
} | |
}) | |
}).catch(e => { | |
console.error(`An error occurred when attempting to run the speed test: ${e.message}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses fast.com via fast-speedtest-api