應該很多人知道可以用 fast.com 來看目前網速, 但如何透過X-平台來監控自家或公司的網路狀況呢?
以下為簡單的案例分享
可以透過以下三個步驟:
設定資料
設定通知規則
寫一個nodeJS App
以下分享一個nodeJS的App, 裡面要用到的token可以參考這個 連結
const SpeedTest = require('fast-speedtest-api');
const axios = require('axios');
async function testInternetSpeed() {
try {
const speedtest = new SpeedTest({
token: 'xxxxxxxxxxxxxx', // get your token
verbose: false,
timeout: 10000,
https: true,
urlCount: 5,
bufferSize: 8,
unit: SpeedTest.UNITS.Mbps
});
const speed = await speedtest.getSpeed();
console.log('Speed:', speed, 'Mbps');
const response = await axios.post('https://api.xplatform.tranx.io/staging/xxxx', { "yyy": speed }, { //replace the "xxxx" with your data source name. replace "yyy" with your data name.
headers: {
'x-api-key': 'xxxxxxxxxxxxxx' //replace the "xxxxxxxxxxxxxx" with your API KEY.
}
});
console.log('Data sent to API:', response.data);
} catch (error) {
console.error('Error testing internet speed:', error);
}
}
setInterval(testInternetSpeed, 30000);
再將nodeJS 跑起來,就可以囉!
Have Fun!