apmd Command in Linux

Introduction

In this practical guide, you will discover how to leverage the apmd command, a valuable utility for systemadmin tasks, specifically designed for monitoring and controlling the power consumption of your Linux system. This is especially relevant for laptops and other devices reliant on battery power. You'll begin by installing the apmd package and initiating the service. Then, you'll explore various apmd commands to effectively monitor the battery status. Finally, you will learn how to fine-tune apmd for automated power management to extend battery life and optimize energy usage.

Keep in mind that the apmd command might require manual installation on certain Linux distributions, as it isn't always included in the default installation. Furthermore, apmd represents a legacy approach to power management, and contemporary solutions like tlp or powertop might be more suitable in some scenarios.

Introduction to the apmd Command

In this section, we'll delve into the apmd command, a tool vital for monitoring and governing your system's power status. The apmd command shines when used with laptops and similar battery-operated devices, providing the means to monitor battery levels and configure tailored power management settings.

First, let's verify whether the apmd package is already present on your system. Execute the following commands:

sudo apt-get update
sudo apt-get install -y apmd

Example output:

Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
  apmd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.

With the apmd package successfully installed, you can now launch the apmd service using this command:

sudo /etc/init.d/apmd start

Example output:

Starting ACPI Power Management Daemon: apmd.

The apmd service is now active, empowering you to utilize the apmd command for comprehensive power status monitoring and management.

Monitoring Battery Status with apmd

In this section, we will focus on leveraging the apmd command to keep tabs on your system's battery status.

To start, let's check the current battery status by issuing the apmd command:

sudo apmd -s

Example output:

ACPI Power Management Daemon version 3.2.2
Battery status:
  Battery 0: charged, 100% remaining

The output reveals the present battery status, including the battery percentage and whether it's charging or discharging.

You can also employ the apmd command to access more in-depth battery information:

sudo apmd -d

Example output:

ACPI Power Management Daemon version 3.2.2
Battery status:
  Battery 0: charged, 100% remaining
  Design capacity: 5000 mAh
  Last full capacity: 5000 mAh
  Battery technology: rechargeable
  Battery voltage: 12.6 V
  Battery current: 0 mA
  Battery temperature: 25.0 C

This command expands upon the basic status and offers data on design capacity, last full capacity, voltage, current, and temperature.

For real-time battery status monitoring, you can utilize the apmd command. Execute the subsequent command:

sudo apmd -m

This command will continuously track the battery status and promptly display any shifts in battery level or charging/discharging state.

Configuring apmd for Automated Power Management

In this section, we'll explore how to configure the apmd command to automate the power settings of your Linux system. The root user needs to execute this step.

The apmd command's behavior can be customized by editing the /etc/apm/event.d/default.script file. Within this file reside a collection of scripts executed upon the occurrence of specific power events, like the battery level falling below a defined threshold or the system transitioning to a low-power mode.

To begin, let's open the default script file for editing:

sudo nano /etc/apm/event.d/default.script

Within the file, you will encounter sections corresponding to diverse power events. For instance, the following segment addresses the low battery event:

## Low battery event
on battery-low
logger "ACPI event: battery low"
## Add your custom actions here
end

This section can be customized to trigger actions when the battery level is critically low, such as suspending the system or initiating a shutdown.

As a practical example, let's configure apmd to automatically suspend the system when the battery level hits 20%:

## Low battery event
on battery-low
logger "ACPI event: battery low"
if [ "$(sudo apmd -s | grep -o -E '[0-9]+%')" = "20%" ]; then
  logger "Suspending system due to low battery"
  sudo systemctl suspend
fi
end

In this configuration, the apmd -s command is used to inspect the current battery level, and if it's at or below 20%, the system is suspended via the systemctl suspend command.

Save the modifications to the file and exit the text editor.

The apmd command is now configured to automate your system's power settings based on battery level, improving energy efficiency.

Summary

In this lab, you gained a comprehensive understanding of the apmd command, an indispensable tool for monitoring and managing the power status of your Linux system. You began by verifying the installation of the apmd package and learned how to initiate the apmd service. Subsequently, you explored the usage of the apmd command to monitor battery status, including assessing the current battery percentage, identifying charging/discharging state, and accessing detailed information on battery design capacity, last full capacity, voltage, current, and temperature.

Moving forward, you will learn how to configure apmd for automated power management. This will empower you to establish power-saving policies and define corresponding actions contingent on battery status.

400+ Linux Commands