Linux HTTP -> CPU temperature

Let's consider an example that will allow you to monitor the temperature of the processor of your Server, PC or Mining farm on Linux.

Required materials:

  • Computer: Any computer with a Linux operating system
  • Programs:
    • nano — command-line text editor
    • grep — command-line utility for searching plain-text data sets
    • cURL — command-line program for working with HTTP
    • lm_sensors – command-line program for get value temperature sensors PC
    • cron — software utility used to periodically perform tasks at a specific time or interval.

Device adding and setting:

  1. Add a new device under the name of «CPU temperature test» in VizIoT
  2. Let's configure the device parameters. In our example, we will have a four-core processor, we will monitor the temperature of the processor and each core separately, for this we need to add five parameters:
    1. phys0 key of «Temperature, °C» type;
    2. core0 key of «Temperature, °C» type;
    3. core1 key of «Temperature, °C» type;
    4. core2 key of «Temperature, °C» type;
    5. core3 key of «Temperature, °C» type;
  3. Copy pass key and access password in «Basic settings» of the device.

Setting up programs.

We will use «cURL» to send data, and we will use the «lm_sensors» package to get data about the processor temperature.

Typically, the packages "cURL" and "lm_sensors" are already preinstalled on most systems and configured to work. But if your system does not have them, then the programs are not that difficult to install.

  • On RedHat or CentOS:
    sudo yum install lm_sensors curl
  • On Debian, Ubuntu, or Linux Mint:
    sudo apt-get install lm-sensors curl

When the installation is complete, we need to perform a setup to identify all the sensors connected to the system. To do:

> sudo sensors-detect

The sensors-detect utility tries to find all installed hardware and load the recommended kernel modules for it. In most cases, you will only need to press the Enter button in response to all program questions, thereby giving the default answers.

The setting is complete and now you can go to view the available temperature. To do this:

> sudo sensors

In response, you will receive something like this:

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +29.0°C  (high = +80.0°C, crit = +100.0°C)
Core 0:         +23.0°C  (high = +80.0°C, crit = +100.0°C)
Core 1:         +26.0°C  (high = +80.0°C, crit = +100.0°C)
Core 2:         +24.0°C  (high = +80.0°C, crit = +100.0°C)
Core 3:         +24.0°C  (high = +80.0°C, crit = +100.0°C) 

Test the commands

In order to send a value to the server, we first need to extract the desired value from these lines, for this we use the grep command to filter the values of the sensors command. Example of a command to get the temperature "Core 0":

sensors | grep -Eo '^Core 0: +\+[0-9]+\.[0-9]+' | grep -Eo '\+[0-9]+\.[0-9]+'

We will use CURL to send HTTP GET requests. Example command with a request:

curl --silent "https://VizIoT.com/update?key=______________&pass=______________&temp=28" > /dev/null

Now let's write a script that will send information about the temperature of the processor and its cores to the server.

Script creation.

Let's create a script using a text editor

> nano /var/viziot.sh

Script content:

key='_____________'
pass='_________________'
phys0=$(sensors | grep -Eo '^Physical id 0: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+')
core0=$(sensors | grep -Eo '^Core 0: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+')
core1=$(sensors | grep -Eo '^Core 1: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+')
core2=$(sensors | grep -Eo '^Core 2: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+')
core3=$(sensors | grep -Eo '^Core 3: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+')
curl --silent "https://viziot.com/update?key=$key&pass=$pass&phys0=$phys0&core0=$core0&core1=$core1&core2=$core2&core3=$core3" > /dev/null

Give the right to execute

> chmod +x /var/viziot.sh 

We'll use the cron daemon to send every minute. Let's start the cron editor

> crontab -e

And at the very end, add a line that will run the script "/var/viziot.sh" every minute:

0-59 * * * * /var/viziot.sh

Adding widgets:

  1. Create a new dashboard under the name «CPU temperature dashboard».
  2. Add widgets «CPU temperature»
    • type: «Chart»;
    • device: «CPU temperature test»;
    • parameter: phys0, core0, core1, core2, core3;

Now the setup is complete and you have to wait until your device connected to the server.