How to use Probe Command on a Node

Issue

I want to prevent my node to be allocated if Disk Usage is over 80%

Environment

  • CloudBees Jenkins Enterprise
  • CloudBees Jenkins Operations Center

Resolution

First, Node Monitoring can be configured at Manage Jenkins/Manage Nodes/Configure. The default Free Space Threshold is set to 1GB which means that nodes are not allocated if the amount of Free Space is under 1GB. This is a setup for all slaves.

A way to monitor a specific thread is to use the Nodes Plus Plugin. A probe command can be specified to decided whether or not a node is able to accept tasks. If the command return an exit code different to 0, the slave cannot accep tasks. The best way to use this feature is to create a script on the slave machine and launch it as a probe command.

Example

I want to prevent my unix node from being allocated if the Disk Usage is over 80%.

The following command gives me the file system usage on the machine:

my-slave:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/disk1      233G  138G   96G  60% /

My $SLAVE_HOME is located on /dev/disk1 so I can workout a command like the following to grab the usage value (Use% is the fifth value in the line) of this disk:

my-slave:~$ df -h | grep /dev/disk1 | awk '{print $5}' | sed 's/%//g'
60

I can then create a probe.sh located under $SLAVE_HOME to exit with error code -1 when my disk usage is over 80%:

#!/bin/bash
CURRENT=$(df -h | grep /dev/disk1 | awk '{print $5}' | sed 's/%//g')
THRESHOLD=80

if [ $CURRENT -gt $THRESHOLD ]; then
    exit -1
fi

I configure my node with the probe as following:

node-config

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.