Back to Resources
Level
Script
General
Standardizing device performance is critical for IT teams managing Linux environments. Devices with insufficient CPU, RAM, or storage can cause performance issues, security vulnerabilities, and unnecessary help desk tickets. This script provides an automated way to verify that Linux machines meet minimum hardware requirements, enabling proactive maintenance and reducing unexpected failures.
This script gathers system specifications—including CPU core count, total RAM, and available disk space—and compares them to the minimum values defined in Level’s custom fields (cf_minimum_cpu, cf_minimum_ram, and cf_minimum_storage). If a device falls short in any category, it generates an alert. Additionally, it checks whether the primary disk is an SSD and warns if an HDD is detected. When configured as a script-based monitor in Level, it allows IT teams to enforce compliance across their Linux fleet and receive alerts when devices fail to meet requirements.
1#!/bin/bash
2
3# This resource is provided as a convenience for Level users. We cannot
4# guarantee it will work in all environments. Please test before deploying
5# to your production environment. We welcome contributions to our community
6# library
7
8# Level Library
9# https://level.io/library/script-linux-monitor-device-standards
10
11# Define minimum standards
12MIN_CORES={{cf_minimum_cpu}}
13MIN_RAM={{cf_minimum_ram}} # in GB
14MIN_DISK={{cf_minimum_storage}} # in GB
15STANDARDS_BYPASS={{cf_standards_bypass}}
16echo "Current STANDARDS_BYPASS value: $STANDARDS_BYPASS"
17
18# Check for standards bypass
19if [ "${STANDARDS_BYPASS}" = "true" ] || [ "${STANDARDS_BYPASS}" = "1" ]; then
20 echo "Standards check bypassed by configuration"
21 exit 0
22fi
23
24# Initialize issues array
25declare -a issues
26
27# Check CPU Cores
28CPU_CORES=$(nproc)
29if [ "$CPU_CORES" -lt "$MIN_CORES" ]; then
30 issues+=("ALERT: CPU has $CPU_CORES cores, below the minimum requirement of $MIN_CORES cores.")
31fi
32
33# Check RAM
34TOTAL_RAM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
35TOTAL_RAM_GB=$((TOTAL_RAM_KB / 1024 / 1024))
36if [ "$TOTAL_RAM_GB" -lt "$MIN_RAM" ]; then
37 issues+=("ALERT: System has $TOTAL_RAM_GB GB of RAM, below the minimum requirement of $MIN_RAM GB.")
38fi
39
40# Check Disk Space
41TOTAL_DISK_KB=$(df / | awk 'NR==2 {print $2}')
42TOTAL_DISK_GB=$((TOTAL_DISK_KB / 1024 / 1024))
43if [ "$TOTAL_DISK_GB" -lt "$MIN_DISK" ]; then
44 issues+=("ALERT: Total disk space is $TOTAL_DISK_GB GB, below the minimum requirement of $MIN_DISK GB.")
45fi
46
47# Check if disk is SSD (handles both standard and LVM setups)
48ROOT_DEVICE=$(lsblk -no pkname,type $(df -P / | awk 'NR==2 {print $1}') 2>/dev/null | grep "disk" | awk '{print $1}')
49if [ -n "$ROOT_DEVICE" ] && [ -f "/sys/block/$ROOT_DEVICE/queue/rotational" ]; then
50 ROTATIONAL=$(cat "/sys/block/$ROOT_DEVICE/queue/rotational")
51 if [ "$ROTATIONAL" = "1" ]; then
52 issues+=("ALERT: The primary disk is not an SSD.")
53 fi
54fi
55
56# Output results
57if [ ${#issues[@]} -gt 0 ]; then
58 printf '%s\n' "${issues[@]}"
59 exit 1
60else
61 echo "System check passed:
62- CPU cores: $CPU_CORES (min: $MIN_CORES)
63- RAM: $TOTAL_RAM_GB GB (min: $MIN_RAM GB)
64- Disk space: $TOTAL_DISK_GB GB (min: $MIN_DISK GB)"
65 exit 0
66fi
Linux Monitor - Device Standards
This Linux Bash script performs system requirement verification using Level Custom Fields as thresholds. It checks CPU cores using nproc, RAM via /proc/meminfo, disk space with df, and SSD status through /sys/block rotational flag. The script stores requirement violations in an array and exits with code 1 and alerts if checks fail, or code 0 with system specifications if all checks pass.
Bash
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.