Level Verified

Linux Monitor - Device Standards Script

Ensure Linux devices meet minimum CPU, RAM, and storage requirements using Level’s custom fields. Use this script within a script-based monitor to detect and alert on non-compliant devices.

Import into Level

Problem overview

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.

Bash 100s timeout Runs as Local system Linux
#!/bin/bash

# This resource is provided as a convenience for Level users. We cannot 
# guarantee it will work in all environments. Please test before deploying 
# to your production environment. We welcome contributions to our community 
# library

# Level Library
# https://level.io/library/script-linux-monitor-device-standards

# Define minimum standards
MIN_CORES={{cf_minimum_cpu}}
MIN_RAM={{cf_minimum_ram}}  # in GB
MIN_DISK={{cf_minimum_storage}}  # in GB
STANDARDS_BYPASS={{cf_standards_bypass}}
echo "Current STANDARDS_BYPASS value: $STANDARDS_BYPASS"

# Check for standards bypass
if [ "${STANDARDS_BYPASS}" = "true" ] || [ "${STANDARDS_BYPASS}" = "1" ]; then
   echo "Standards check bypassed by configuration"
   exit 0
fi

# Initialize issues array
declare -a issues

# Check CPU Cores
CPU_CORES=$(nproc)
if [ "$CPU_CORES" -lt "$MIN_CORES" ]; then
   issues+=("ALERT: CPU has $CPU_CORES cores, below the minimum requirement of $MIN_CORES cores.")
fi

# Check RAM
TOTAL_RAM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
TOTAL_RAM_GB=$((TOTAL_RAM_KB / 1024 / 1024))
if [ "$TOTAL_RAM_GB" -lt "$MIN_RAM" ]; then
   issues+=("ALERT: System has $TOTAL_RAM_GB GB of RAM, below the minimum requirement of $MIN_RAM GB.")
fi

# Check Disk Space
TOTAL_DISK_KB=$(df / | awk 'NR==2 {print $2}')
TOTAL_DISK_GB=$((TOTAL_DISK_KB / 1024 / 1024))
if [ "$TOTAL_DISK_GB" -lt "$MIN_DISK" ]; then
   issues+=("ALERT: Total disk space is $TOTAL_DISK_GB GB, below the minimum requirement of $MIN_DISK GB.")
fi

# Check if disk is SSD (handles both standard and LVM setups)
ROOT_DEVICE=$(lsblk -no pkname,type $(df -P / | awk 'NR==2 {print $1}') 2>/dev/null | grep "disk" | awk '{print $1}')
if [ -n "$ROOT_DEVICE" ] && [ -f "/sys/block/$ROOT_DEVICE/queue/rotational" ]; then
   ROTATIONAL=$(cat "/sys/block/$ROOT_DEVICE/queue/rotational")
   if [ "$ROTATIONAL" = "1" ]; then
       issues+=("ALERT: The primary disk is not an SSD.")
   fi
fi

# Output results
if [ ${#issues[@]} -gt 0 ]; then
   printf '%s\n' "${issues[@]}"
   exit 1
else
   echo "System check passed:
- CPU cores: $CPU_CORES (min: $MIN_CORES)
- RAM: $TOTAL_RAM_GB GB (min: $MIN_RAM GB)
- Disk space: $TOTAL_DISK_GB GB (min: $MIN_DISK GB)"
   exit 0
fi

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.

Use cases

  • Ensure Linux endpoints meet minimum hardware standards for performance and reliability.
  • Identify underperforming devices that require upgrades or replacement.
  • Reduce IT support requests caused by outdated hardware configurations.
  • Maintain compliance across a diverse Linux environment, from servers to workstations.
  • Integrate with Level’s device standards monitoring policy for cross-platform enforcement (Windows, macOS, Linux).

Recommendations

  • Testing: Run the script manually on a Linux test system before deploying it across production environments.
  • Deployment: Use a script-based monitor in Level to schedule and trigger automatic compliance checks.
  • Customization: Modify cf_minimum_cpu, cf_minimum_ram, and cf_minimum_storage in Level’s custom fields to reflect your organization’s minimum standards.
  • Automation: Combine this script with auto-remediation workflows, such as flagging non-compliant devices for upgrades.
  • Scheduled Audits: Run this script on a schedule to maintain ongoing compliance across Linux devices.

Frequently asked questions.

How do I configure this script in Level?

Create a script-based monitor in Level and assign this script to run at regular intervals or on-demand to ensure compliance.

What happens when a device fails the compliance check?

The script outputs a list of hardware deficiencies and exits with a failure code (exit 1), allowing Level to detect and flag the issue.

Can I adjust the minimum hardware requirements dynamically?

Yes, the script retrieves minimum values from Level’s custom fields, allowing changes without modifying the script itself.

Does this script check all storage drives?

No, it calculates disk space based on the root (/) partition and verifies whether the primary disk is an SSD.

Is there a version of this script for Windows or macOS?

Yes, Level provides equivalent device standards monitoring policies for Windows and macOS, ensuring consistent compliance across platforms.

Ready when you are.

No credit card. No sales call. Just sign up and start managing.