/Sappi

Command Line Tool for Gathering System Information using Swift Argument Parser

Primary LanguageHTMLMIT LicenseMIT

 

Sappi

Sappi

Command Line Tool for Gathering System Information using Swift Argument Parser

SwiftPM Twitter GitHub GitHub issues

macOS ubuntu Travis (.com) Bitrise CircleCI

Codecov CodeFactor Grade codebeat badge Code Climate maintainability Code Climate technical debt Code Climate issues Reviewed by Hound

$ sappi -h
OVERVIEW: Prints and exports system information.

USAGE: sappi <subcommand>

OPTIONS:
  -h, --help              Show help information.

SUBCOMMANDS:
  print (default)         Prints system information out to the console.
  export                  Exports system information in any format.

  See 'sappi help <subcommand>' for detailed help.


$ sappi 
CPU Usage: 6%
Memory Usage: 95%
Usage of VM: 28% of 1000.24GB
Usage of Preboot: 28% of 1000.24GB
Usage of Media: 42% of 8001.35GB
Usage of Google Drive: 41% of 16.1GB
Usage of Update: 28% of 1000.24GB
Usage of Photos: 26% of 2000.18GB
Usage of Macintosh HD: 28% of 1000.24GB
Usage of Time Machine: 77% of 5000.28GB
Processes: 662
IPv6 address for en0: fe80::10cb:4190:8fe4:ed28
IPv4 address for en0: 192.168.1.76
IPv6 address for en0: 2600:1702:4050:7d30:4e9:86:816d:7e4d
IPv6 address for en0: 2600:1702:4050:7d30:88d3:849e:4a65:6aa3
IPv6 address for en0: 2600:1702:4050:7d30::51e
IPv6 address for en1: fe80::10c0:5193:8bf8:b99
IPv6 address for en1: 2600:1702:4050:7d30:cdb:5f0f:d5be:d86a
IPv6 address for en1: 2600:1702:4050:7d30:192e:3dc6:3d66:6acc
IPv4 address for en1: 192.168.1.82
IPv6 address for en1: 2600:1702:4050:7d30::72f
IPv6 address for en1: 2600:1702:4050:7d30:2193:e7f4:7fc4:97ef

Introduction

This is a simple command line Swift Package for displaying system information as well as showing the power of the Swift Argument Parser:

  • An example of optional Arguments
  • Using enums in Options
  • How to use Flags for verbose information

Installation

The simplest way to install this application is via mint. Install mint via homebrew then run:

$ mint install brightdigit/Sappi

Usage

Specifying Information Flags

Using flags you can specify specific system information. There are 5 accepted InfoType values:

  • --cpu CPU and Core Usage. Includes temperature information in verbose mode.
  • --memory Memory Usage.
  • --disks Disk Volume Usage.
  • --processes Number of Active Processes.
  • --network Each connected network and address.
$ sappi --cpu
CPU Usage: 10%

If no arguments are supplied then all InfoType values are assumed:

$ sappi
CPU Usage: 11%
Memory Usage: 37%
Usage of Media: 42% of 8001.35GB
Usage of Google Drive: 41% of 16.1GB
Usage of VM: 29% of 1000.24GB
Usage of Preboot: 29% of 1000.24GB
Usage of Update: 29% of 1000.24GB
Usage of Time Machine: 77% of 5000.28GB
Usage of Macintosh HD: 29% of 1000.24GB
Usage of Photos: 26% of 2000.18GB
Processes: 489
IPv6 address for en0: fe80::1ca8:35c4:4859:684e
IPv6 address for en0: 2600:1702:4050:7d30:4e9:86:816d:7e4d
IPv6 address for en0: 2600:1702:4050:7d30:64a9:183f:3960:86bc
IPv4 address for en0: 192.168.1.76
IPv6 address for en0: 2600:1702:4050:7d30::51e
IPv6 address for en1: fe80::81f:e405:7602:4003
IPv6 address for en1: 2600:1702:4050:7d30:cdb:5f0f:d5be:d86a
IPv6 address for en1: 2600:1702:4050:7d30:30dc:a334:3675:e05a
IPv4 address for en1: 192.168.1.82
IPv6 address for en1: 2600:1702:4050:7d30::72f

Multiple InfoType values are accepted:

$ sappi --cpu --disks
CPU Usage: 10%
Usage of Media: 42% of 8001.35GB
Usage of Time Machine: 77% of 5000.28GB
Usage of Photos: 26% of 2000.18GB
Usage of Update: 29% of 1000.24GB
Usage of Macintosh HD: 29% of 1000.24GB
Usage of Preboot: 29% of 1000.24GB
Usage of Google Drive: 41% of 16.1GB
Usage of VM: 29% of 1000.24GB

For more information, check out the code documentation page on InfoType here.

Formatting Options For Values

Sappi gives you the ability to format cetain numerical values.

Values such CPU, Memory, and Disk allow for different ways to display usage or availability in relationship to the total by using the --value-format= option:

  • percent - percent value
  • ratio - units / total units
  • percentTotal - percent / total units
  • default - percent for CPU and _Memory, percentTotal for Disks
$ sappi --cpu --memory --disks --value-format=percent
CPU Usage: 20%
Memory Usage: 98%
Usage of Google Drive: 41%
Usage of Update: 15%
Usage of System: 15%
Usage of VM: 15%
Usage of Preboot: 15%

or

$ sappi --cpu --memory --disks --value-format=ratio  
CPU Usage: 2416633 idle, 3053548 total
Memory Usage: 43 free, 6504 total
Usage of Update: 1619969011712 available, 1920140099584 total
Usage of Preboot: 1619969011712 available, 1920140099584 total
Usage of VM: 1619969011712 available, 1920140099584 total
Usage of Google Drive: 9482440704 available, 16106127360 total
Usage of System: 1619969011712 available, 1920140099584 total

For more information on the different value formats, check out the documentation page on RatioFormat here.

Getting CPU Temperature

Sappi also has the ability to get various temperature available for your hardware. First you'll need to enable the --verbose option to get this information:

$ sappi --cpu --verbose
CPU Usage: 20%
CPU 1 Usage: 31%
CPU 2 Usage: 13%
CPU 3 Usage: 26%
CPU 4 Usage: 11%
CPU Die Temperature: 64.0°C
Core 1 Temperature: 64.0°C

Sappi also gives you the option to format the temperature in various scales:

  • celsuis Celsuis Scale default
  • fahrenheit Fahrenheit Scale
  • kelvin Kelvin Scale
  • rankine Rankine Scale
  • delisle Delisle Scale
  • newton Newton Scale
  • réaumur Réaumur Scale
  • rømer Rømer Scale

So for instance if you want your temperatures in Kelvin, simply use:

$ sappi --cpu --verbose --temperature-unit=kelvin
CPU Usage: 20%
CPU 1 Usage: 31%
CPU 2 Usage: 13%
CPU 3 Usage: 26%
CPU 4 Usage: 11%
CPU Die Temperature: 324.15°K
Core 1 Temperature: 331.15°K

For more information, check out the documentation page for TemperatureUnit here.

Exporting Your Data

Lastly, Sappi supports exporting data in various formats via the exporting subcommand. You've already seen the default subcommand print which only supports the text format.

$ sappi --cpu --disks
CPU Usage: 10%
Usage of Media: 42% of 8001.35GB
Usage of Time Machine: 77% of 5000.28GB
Usage of Photos: 26% of 2000.18GB
Usage of Update: 29% of 1000.24GB
Usage of Macintosh HD: 29% of 1000.24GB
Usage of Preboot: 29% of 1000.24GB
Usage of Google Drive: 41% of 16.1GB
Usage of VM: 29% of 1000.24GB
$ sappi print --cpu --disks
CPU Usage: 10%
Usage of Media: 42% of 8001.35GB
Usage of Time Machine: 77% of 5000.28GB
Usage of Photos: 26% of 2000.18GB
Usage of Update: 29% of 1000.24GB
Usage of Macintosh HD: 29% of 1000.24GB
Usage of Preboot: 29% of 1000.24GB
Usage of Google Drive: 41% of 16.1GB
Usage of VM: 29% of 1000.24GB
$ sappi export --cpu --disks --export-format=text
CPU Usage: 10%
Usage of Media: 42% of 8001.35GB
Usage of Time Machine: 77% of 5000.28GB
Usage of Photos: 26% of 2000.18GB
Usage of Update: 29% of 1000.24GB
Usage of Macintosh HD: 29% of 1000.24GB
Usage of Preboot: 29% of 1000.24GB
Usage of Google Drive: 41% of 16.1GB
Usage of VM: 29% of 1000.24GB

To export in various formats, use the subcommand export. Then use the --format= to specify a different format other than text:

  • text - Standard text format default
  • json - JSON format (ignores --value-format and --verbose)
  • csv - Comma-Separated Values

For instance, to export all the CPU values including temperature (in Fahrenheit) in csv format:

$ sappi export --format=csv --cpu --verbose --temperature-unit=fahrenheit
CPU,Usage,2005257,2138565
CPU,CPU 1,1636746,2138725
CPU,CPU 2,2117266,2138553
CPU,CPU 3,1772240,2138579
CPU,CPU 4,2119185,2138551
CPU,CPU 5,1847133,2138575
CPU,CPU 6,2119695,2138548
CPU,CPU 7,1898309,2138571
CPU,CPU 8,2119747,2138546
CPU,CPU 9,1941927,2138567
CPU,CPU 10,2119781,2138544
CPU,CPU 11,1990327,2138564
CPU,CPU 12,2120116,2138541
CPU,CPU 13,2008236,2138560
CPU,CPU 14,2120426,2138539
CPU,CPU 15,2032377,2138556
CPU,CPU 16,2120604,2138535
CPU,Die Temperature °F,,123.8
CPU,Core 1 Temperature °F,,123.8
CPU,Core 2 Temperature °F,,123.8
CPU,Core 3 Temperature °F,,122.0
CPU,Core 4 Temperature °F,,123.8

To export the data in JSON format use:

sappi export --format=json                     
{
  "cpu" : {
    "cores" : [
      {
        "idle" : 1646402,
        "sum" : 2151846
      },...
    ],
    "cpu" : {
      "idle" : 2017769,
      "sum" : 2151686
    },
    "temperatures" : [
      {
        "key" : "TC0P",
        "value" : 51
      },...
    ]
  },
  "memory" : {
    "free" : 92161,
    "total" : 131066
  },
  "networks" : [
    {
      "address" : "192.168.1.76",
      "family" : 0,
      "name" : "en0"
    },...
  ],
  "processes" : 561,
  "volumes" : [
    {
      "available" : 694472245248,
      "name" : "Macintosh HD",
      "total" : 1000240963584
    },...
  ]

For more information, check out the documentation page for ExportFormat here.

Support

If you have any questions or issues with the application, feel free to post an issue here.

License

This code is distributed under the MIT license. See the LICENSE file for more info.