1. Home
  2. Creating Custom Driver Table Variables

Creating Custom Driver Table Variables

This article covers creating custom driver table variables.

To start off, Custom Driver Tables enable you to extract structured data that is well-organized and easy to understand. On the other hand, Custom Driver Variables allow you to monitor scalar values.

For example, with the Custom Driver Table Variables you can display resource consumption statistics for the all running docker containers on the host devices. The table contains a unique identifier for each row, in this case the Docker Container ID, and columns in a table show your defined value, which is an instance of various key/value pairs.

Note: Learn how to create a custom driver.

How to create Custom Driver Table Variables

Through a simple JavaScript code, you can now create your Custom Driver Table Variables.

Custom driver table variables

To start, you can define the communication protocol, for example SSH. You can do that, by creating an object and its properties such as command, username, password, timeout, and so on:

For more information on Custom Driver API communication SSH protocol options please see: https://portal.domotz.com/custom-driver/global.html#:~:text=in%20an%20error-,SshOptions,-The%20SSH%20Library

as in the example below:

var options = {
	"command": "docker stats --no-stream --format \"table {{.Container}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemPerc}}\"",
	"username": D.device.username(),
	"password": D.device.password(),
	"timeout": 5000
	};

Then, define a variable and create a driver table, name it, and assign column labels as follows:

var MyTable = D.createTable("My Driver Table", [{"label": "Column A"}, {"label": "Column B", "unit": "%"}])

For more information on Custom Driver Tables please see: https://portal.domotz.com/custom-driver/D.html#:~:text=(static)%20createTable(label%2C%20columnHeaders)

After parsing the response of the communication protocol variable, simply insert the result into the custom driver table object by:

MyTable.insertRecored(id, values)

and the final table and values will be send to the cloud with the D.success() callback implicitly.

D.success(MyTable)

Example: Docker Containers monitoring with Domotz Custom Driver Table

Note: Follow the GitHub page to create a custom driver table that displays the ID, Name, CPU, and Memory utilization as a percentage: https://github.com/domotz/custom-driver/blob/master/examples/ssh/docker_stats.js

Below you can see a Custom Driver Table (with a 5 minute scheduled update). The Id column in this case is the Docker container ID, the column Name is the container name, the CPU and Memory column are self explanatory.

Get more general information on Custom Drivers Table in our documentation.

Updated on November 28, 2022

Was this article helpful?