Skip to main content

Machine Stats for Unix-like systems

PyPI

A simple and effective way to gather machine statistics (RAM, Storage, CPU) from a server environment as a first layer of a Tidal discovery process.

Machine Stats for Linux/Unix leverages Ansible to gather facts in a cross-platform way.

Interactive tutorial

Get familiar with Machine Stats, Tidal Tools and Tidal Accelerator!

Open in Cloud Shell

Installation

Install locally in a Python 3 environment:

python3 -m pip install machine-stats

Need to install in an environment without internet access? Checkout how to do that below.

Distribution-specific installation instructions

Ubuntu 16.04

  1. Make sure pip is installed and is one of the latest version available:
    sudo apt update && \
      sudo apt install -y python3-pip && \
      python3 -m pip install --user pip==18.1 && \
      python3 -m pip install --upgrade --user pip
    
    Note: Direct upgrade to the latest available pip version results with an unusable pip installation. That's why we perform the upgrade through the intermediate version (18.1).
  2. Install machine-stats:
    python3 -m pip install machine-stats
    

Debian 9/Ubuntu 18.04

  1. Make sure pip is installed and is one of the latest version:
    sudo apt update && \
      sudo apt install -y python3-pip && \
      python3 -m pip install --upgrade pip
    
  2. Install machine-stats:
    python3 -m pip install machine-stats
    

Debian 10/Debian 11/Ubuntu 20.04/Ubuntu 21.04

  1. Make sure pip is installed:
    sudo apt update && \
      sudo apt install -y python3-pip
    
  2. Install machine-stats:
    python3 -m pip install machine-stats
    

CentOS 7/CentOS 8/CentOS Stream/Red Hat Enterprise Linux 7/Red Hat Enterprise Linux 8/Rocky Linux 8

  1. Install Python 3:
    sudo yum install -y python3
    
  2. Upgrade pip to the latest available version:
    python3 -m pip install --upgrade --user pip
    
  3. Install machine-stats:
    python3 -m pip install machine-stats
    

SUSE Linux Enterprise Server 12

  1. Install Python 3.6:
    sudo zypper install -y python36-base
    
  2. Install machine-stats:
    pip install machine-stats
    

SUSE Linux Enterprise Server 15

  1. Install pip:
    sudo zypper install -y python3-pip
    
  2. Install machine-stats:
    pip install machine-stats
    

Data captured

For Linux/Unix based systems, by default, the following metrics are captured from the resources and sent and stored in Tidal Accelerator:

  • Host Name
  • FQDN
  • IP Addresses
  • RAM Allocated (GB)
  • RAM Used (GB)
  • Storage Allocated (GB)
  • Storage Used (GB)
  • CPU Count
  • Operating System
  • Operating System Version
  • CPU name

Here is an example of the output of machine-stats:

{
    "servers": [
        {
            "cpu_count": 2,
            "cpu_name": "Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz",
            "custom_fields": {
                "cpu_average": 0.9314873092946548,
                "cpu_peak": 20.46949490073019,
                "cpu_sampling_timeout": 30,
                "cpu_utilization_timestamp": "2024-05-17 11:54:19"
            },
            "fqdn": "ip-172-31-9-62.ca-central-1.compute.internal",
            "host_name": "ip-172-31-9-62",
            "ip_addresses": [
                "172.31.9.62",
                "172.17.0.1",
                "fe80::4ee:9cff:fe97:418f"
            ],
            "operating_system": "Ubuntu",
            "operating_system_version": "18.04",
            "ram_allocated_gb": 0.9267578125,
            "ram_used_gb": 0.7001953125,
            "storage_allocated_gb": 7.80632209777832,
            "storage_used_gb": 2.61613130569458
        }
    ]
}

It's also possible to capture point-in-time CPU utilization using the flags --cpu-utilization-only-value and --cpu-utilization-timeout.

Here's an example of the output of running machine-stats hosts --cpu-utilization-only-value --cpu-utilization-timeout 1:

{
    "servers": [
        {
            "cpu_count": 2,
            "cpu_name": "Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz",
            "custom_fields": {
                "cpu_sampling_timeout": 1,
                "cpu_utilization": 0.497512437810943,
                "cpu_utilization_timestamp": "2024-05-17 11:59:54"
            },
            "fqdn": "ip-172-31-9-62.ca-central-1.compute.internal",
            "host_name": "ip-172-31-9-62",
            "ip_addresses": [
                "172.31.9.62",
                "172.17.0.1",
                "fe80::4ee:9cff:fe97:418f"
            ],
            "operating_system": "Ubuntu",
            "operating_system_version": "18.04",
            "ram_allocated_gb": 0.9267578125,
            "ram_used_gb": 0.7109375,
            "storage_allocated_gb": 7.80632209777832,
            "storage_used_gb": 2.6161465644836426
        }
    ]
}

You also can optionally capture metrics about processes running on the server:

  • User
  • Process Name
  • Process Path
  • Memory Used (MB)
  • Max Memory Used (MB)
  • Total Alive Time

To enable capturing process metrics add the command-line flag --process-stats:

machine-stats --process-stats

Here is an example of the output of this command:

{
    "servers": [
        {
            "cpu_count": 2,
            "cpu_name": "Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz",
            "custom_fields": {
                "cpu_average": 0.4973174560230535,
                "cpu_peak": 13.43191223297967,
                "cpu_sampling_timeout": 30,
                "cpu_utilization_timestamp": "2024-05-17 11:56:39"
            },
            "fqdn": "ip-172-31-9-62.ca-central-1.compute.internal",
            "host_name": "ip-172-31-9-62",
            "ip_addresses": [
                "172.31.9.62",
                "172.17.0.1",
                "fe80::4ee:9cff:fe97:418f"
            ],
            "operating_system": "Ubuntu",
            "operating_system_version": "18.04",
            "process_stats": [
                {
                    "max_memory_used_mb": 283.7890625,
                    "memory_used_mb": 220.11328125,
                    "name": "systemd",
                    "path": "/",
                    "pid": 1,
                    "ppid": 0,
                    "total_alive_time": 420,
                    "user": "root"
                }
            ]
        }
    ]
}

Minimal example

  1. Create a hosts file in the current directory. See below on a couple ways you can easily create this.

  2. Add connection strings in the form of ssh-user@ip-address or ssh-user@domain to the hosts file one per line If the ssh-user@ part is omitted, then the current user name is used.

  3. If you need to use a custom SSH identity file for some particular host, provide it as the following:

    my-user@example.com ansible_ssh_private_key_file=path/to/key-file.pem
    
  4. Make sure that Python 2.6+ is installed on the machines from hosts file.

  5. If python executable was installed into non-default location (not in /usr/bin/python), add the ansible_python_interpreter parameter to the hosts file after the host IP/domain, for example:

    freebsd.example.com ansible_python_interpreter=/usr/local/bin/python
    
  6. Execute machine-stats and pipe its output to Tidal Tools:

    machine-stats | tidal sync servers
    

Additional notes

By default Machine Stats looks for the hosts file in current working directory. If your inventory file has another name or is located on another path, then you should specify it explicitly:

machine-stats /path/to/myhosts | tidal sync servers

You can specify multiple inventory files as the following:

machine-stats hosts myhosts /path/to/myhosts

Configuration

Machine Stats uses Ansible under the hood. Most of the Ansible configuration options can be used with Machine Stats too. By default, Machine Stats will look for configuration files in the following locations:

  • $PWD/machine_stats.cfg
  • $PWD/machine-stats.cfg
  • $PWD/machinestats.cfg
  • $PWD/ansible.cfg
  • $HOME/.machine_stats.cfg
  • $HOME/.machine-stats.cfg
  • $HOME/.machinestats.cfg
  • $HOME/.ansible.cfg
  • /etc/ansible/ansible.cfg

Also, it is possible to specify the custom configuration file location by setting the ANSIBLE_CONFIG environment variable, for example:

ANSIBLE_CONFIG=/path/to/my/machine_stats.cfg machine_stats /path/to/my/hosts

Note: if ANSIBLE_CONFIG value points to a directory, then Machine Stats will look for ansible.cfg in that directory.

Offline installation

NOTE: Creating the packages archive for offline installation and the actual offline installation process must be performed on machines with the same OS and Python versions.

  1. On the machine with internet connection create the packages archive using the following commands:

    python3 -m pip download -d machine-stats-offline machine-stats
    tar czf machine-stats-offline.tar.gz machine-stats-offline
    
  2. Transfer the archive to the machine where you need to perform the offline installation (replace <remote-host> and <remote-dir> with the appropriate values):

    scp machine-stats-offline.tar.gz <remote-host>:/<remote-dir>/
    
  3. On the remote host, extract the archive and switch to extracted directory:

    tar xf machine-stats-offline.tar.gz
    cd machine-stats-offline
    
  4. Install Machine Stats and its dependencies:

    python3 -m pip install --no-index --find-links . machine_stats-*.whl
    

Generating a hosts file from Tidal Accelerator

You can easily generate a hosts file directly from your server inventory in Tidal Accelerator. For example you can use this command:

tidal export servers | jq '.[].host_name' > hosts

This will create a file (hosts), in your current directory, that you can use above in Step 1.

Alternatively, if you use Tidal Accelerator Ansible Tower integration script you can use its output to generate the hosts file for machine_stats.

Requirements

Usage

cd ansible-tower-integration
./tidal_inventory.py | jq -r '.servers.hosts[]' > path/to/hosts

Troubleshooting

machine-stats: command not found

If running Machine Stats as a CLI failed, try running it as the following:

python3 -m machine_stats

Metadata

Release files for machine_stats 3.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for machine_stats 3.0.2
File Size Uploaded
machine_stats-3.0.2.tar.gz 63.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for machine_stats 3.0.2
File Interpreter ABI Platform
machine_stats-3.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 79.1 kB

Release files / machine_stats-3.0.2.tar.gz

Download URL machine_stats-3.0.2.tar.gz
Size 63.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0b5920dc6657c5ae15244fd137a1ac3b4b669883e7da2269b15db34daf7b93e8
BLAKE2b-256 checksum
How to use checksums
1e49332e2ca46fba2e3ca9b14a4aaa9e5b8724da14cdf4ca15a041ebd1693b60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / machine_stats-3.0.2-py3-none-any.whl

Download URL machine_stats-3.0.2-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b3bd8f44d3bb39db8d027c39c50ad1698298e4f12d7e6f7b180d3281e0c7aff
BLAKE2b-256 checksum
How to use checksums
fdabc7755df5b659584f5e52fb65c0aa6430498368af2f40dd30227627cc1644
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page