Is your home server offline again? Did your IP camera stop streaming video? Has the internet gone down completely, or is just one website not loading? To get instant answers to these questions, you can create a simple yet effective monitoring system.
In this article, we'll set up a script that will regularly check the availability of any internet resources (IP addresses, ports, websites) and send response times to the VizIoT server. If a resource becomes unavailable, we'll see it immediately on the graph and receive a notification in Telegram.
Before we begin, let's see what we'll achieve.
You'll be able to create a visual dashboard that displays the status of your key services in real time.
What you can monitor in this configuration:
How to interpret the graph:
This approach allows you to instantly identify the source of the problem: your local network, internet provider, or a specific remote service.
Seeing a problem on the graph is good, but receiving an instant notification about it is even better. VizIoT allows you to set up alerts that will come to you via Telegram or email as soon as one of your resources becomes unavailable, as well as when it comes back online.

Interested? Let's set up such a system step by step.
It's recommended to install NodeJS via NVM (Node Version Manager).
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# Connect without restarting the shell
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Install the latest LTS version of Node.js
nvm install --lts
# Check version
node -v
npm -v
Download the installer from the official website: https://nodejs.org
mkdir ./VizIoTPinger
cd ./VizIoTPinger
npm init -y
npm install tcp-ping --save
npm install viziot-mqtt-client-nodejs --save
Create the index.js file:
nano ./index.js
Insert the following code into the file. Don't forget to specify your access keys and configure the list of resources to monitor.
'use strict';
// Insert your VizIoT device key and password here
const keyDevice = '__________________';
const passDevice = '______________________';
// List of resources to monitor
// key — parameter name that will appear in VizIoT
// address — domain or IP address
// port — port (optional, default is 80)
const pingList = [
{
key: "microsoft_ping",
address: 'microsoft.com',
port: 80
},
{
key: "google_ping",
address: 'google.com'
},
{
key: "ipCamera_ping",
address: '192.168.0.158',
port: 554 // Standard port for RTSP stream
}
];
const tcpp = require('tcp-ping');
const viziotMQTT = require('viziot-mqtt-client-nodejs');
const viziotMQTTClient = new viziotMQTT(keyDevice, passDevice);
// Function: ping by IP/port
function pingIpAndPortAddress(item, callback) {
const pingItem = {
address: item.address,
port: item.port || 80,
attempts: 3,
timeout: 5000
};
tcpp.ping(pingItem, function (err, data) {
if (data.avg >= 0) {
callback(item, +data.avg.toFixed(2));
} else {
callback(item, -500); // Send -500 if resource is unavailable
}
});
}
// Form data and send to VizIoT
function getPacketAndSendToServer() {
let countResults = 0;
const packet = { date: Math.floor(Date.now() / 1000) };
for (let i = 0; i < pingList.length; i++) {
pingIpAndPortAddress(pingList[i], function (item, timeout) {
packet[item.key] = timeout;
console.log(`Pinging ${item.address}:${item.port || 80} -> ${timeout} ms`);
countResults++;
if (countResults === pingList.length) {
viziotMQTTClient.sendDataToVizIoT(packet, function (err) {
if (err) {
console.log("Publish error:", err);
} else {
console.log("Packet sent successfully!");
}
});
}
});
}
}
// Check interval (60 seconds)
const intervalTime = 60000;
// Initial connection and startup
viziotMQTTClient.connect(function () {
console.log("Connected to VizIoT MQTT broker.");
getPacketAndSendToServer(); // First run immediately after connection
setInterval(getPacketAndSendToServer, intervalTime);
});
PM2 is an advanced process manager for Node.js that will ensure automatic script restart on failures and convenient management.
npm install pm2 -g
pm2 start index.js --name "VizIoTPinger"
pm2 save
pm2 startup
This command will output another command (usually with sudo) that you need to copy and execute.
pm2 list # Show list of running processes
pm2 logs VizIoTPinger # Show logs in real time
pm2 restart VizIoTPinger# Restart process
pm2 stop VizIoTPinger # Stop process
Now that data is flowing in, all that's left is to set up the interface.
microsoft_ping, google_ping, ipCamera_pingipCamera_ping).Detailed instructions for setting up notifications can be found in this article.
You've created a complete monitoring system for the availability of your key services with visual dashboards and instant alerts.