Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
glentner committed Dec 17, 2021
2 parents 0866424 + e9e0436 commit 7f827af
Show file tree
Hide file tree
Showing 20 changed files with 663 additions and 651 deletions.
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ twine = ">=3.2.0"
psutil = ">=5.7.2"
cmdkit = "1.5.5"
logalpha = "2.0.2"
e1839a8 = {editable = true,path = "."}
monitor = {editable = true, path = "."}

[requires]
python_version = "3.8.5"
python_version = "3.9"
791 changes: 472 additions & 319 deletions Pipfile.lock

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import os
import sys
import datetime
sys.path.insert(0, os.path.abspath('../..'))

import monitor # noqa

# -- Project information -----------------------------------------------------

year = datetime.datetime.now().year
project = 'Resource Monitor'
copyright = '2019 Geoffrey Lentner'
author = 'Geoffrey Lentner'
copyright = f'2019 Geoffrey Lentner'
author = 'Geoffrey Lentner <glentner@purdue.edu>'

# The full version, including alpha/beta/rc tags
release = '2.1.2'
release = monitor.__version__
version = monitor.__version__


# -- General configuration ---------------------------------------------------
Expand Down
26 changes: 13 additions & 13 deletions man/man1/monitor.1
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
.\" Man page generated from reStructuredText.
.
.TH "MONITOR" "1" "Apr 21, 2020" "" "Resource Monitor"
.SH NAME
monitor \- system resource monitoring and telemetry
.
.nr rst2man-indent-level 0
.
Expand Down Expand Up @@ -30,6 +27,9 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "MONITOR" "1" "Dec 17, 2021" "2.2.0" "Resource Monitor"
.SH NAME
monitor \- system resource monitoring and telemetry
.SH SYNOPSIS
.sp
monitor \fIdevice\fP \fIresource\fP [\-\-sample\-rate \fISECONDS\fP] [\-\-csv [\-\-no\-header]]
Expand All @@ -47,24 +47,24 @@ possible invocations and associated specific options.
Collect telemetry on CPU core utilization.
.INDENT 7.0
.TP
.B \-\-total
.B \-\-total
Report metrics as a total across all cores (default).
.TP
.B \-\-all\-cores
.B \-\-all\-cores
Report metrics on a per\-core basis.
.UNINDENT
.TP
.B monitor cpu memory [\-\-help]
Collect telemetry on CPU memory utilization.
.INDENT 7.0
.TP
.B \-\-percent
.B \-\-percent
Report metrics as a percent of total available memory (default).
.TP
.B \-\-actual
.B \-\-actual
Report metrics as actual memory allocated (in bytes).
.TP
.B \-H\fP,\fB \-\-human\-readable
.B \-H\fP,\fB \-\-human\-readable
Report metrics in a human readable format with units (e.g., "8.2G").
.UNINDENT
.TP
Expand All @@ -90,25 +90,25 @@ The time interval between consecutive samples (default: 1 second).
.UNINDENT
.INDENT 0.0
.TP
.B \-\-plain
.B \-\-plain
Print messages in log format (default).
.TP
.B \-\-csv
.B \-\-csv
Print messages in CSV format. The header is automatically included in the first line
of output. The field names are consistent between resource types with the exception
of the last one or two fields. For the \fB\-\-all\-cores\fP option with "cpu" and any
of the "gpu" resources, a \fBcpu_id\fP or \fBgpu_id\fP is included. The last column is
specific to the resource being monitored. See also: \fB\-\-no\-header\fP\&.
.TP
.B \-\-no\-header
.B \-\-no\-header
Suppress printing the header in CSV mode (see \fB\-\-csv\fP). This is useful when
appending data to a single file from one or more sources. See the distributed
computing examples below.
.TP
.B \-h\fP,\fB \-\-help
.B \-h\fP,\fB \-\-help
Show help message and exit.
.TP
.B \-v\fP,\fB \-\-version
.B \-v\fP,\fB \-\-version
Show the version number and exit.
.UNINDENT
.SH EXAMPLES
Expand Down
15 changes: 11 additions & 4 deletions monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@

"""Initialization for resource-monitor."""

# pylint: disable=W0611
from .__meta__ import (__appname__, __version__, __authors__,
__contact__, __license__,
__copyright__, __description__)

# package metadata
__appname__ = 'monitor'
__version__ = '2.2.0'
__authors__ = 'Geoffrey Lentner'
__contact__ = 'glentner@purdue.edu'
__license__ = 'Apache Software License 2.0'
__website__ = 'https://resource-monitor.readthedocs.io'
__copyright__ = 'Geoffrey Lentner 2019. All rights reserved.'
__description__ = 'A simple cross-platform system resource monitor.'
__keywords__ = 'cross-platform system resource-monitor telemetry utility command-line-tool'
21 changes: 0 additions & 21 deletions monitor/__meta__.py

This file was deleted.

10 changes: 4 additions & 6 deletions monitor/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

"""Entry-point for resource-monitor."""


# standard libs
import sys
import platform
Expand All @@ -25,8 +26,8 @@
# internal libs
from ..core.logging import Logger
from ..core.exceptions import CompletedCommand
from ..__meta__ import (__appname__, __version__, __description__,
__copyright__, __license__, __website__)
from .. import (__appname__, __version__, __description__,
__copyright__, __license__, __website__)

# external libs
from cmdkit.app import Application
Expand All @@ -43,12 +44,9 @@
}

PROGRAM = __appname__
PADDING = ' ' * len(PROGRAM)

USAGE = f"""\
usage: {PROGRAM} <device> <resource> [<args>...]
{PADDING} [--help] [--version]
usage: {PROGRAM} [-h] [-v] <device> <resource> [<args>...]
{__description__}\
"""

Expand Down
20 changes: 4 additions & 16 deletions monitor/cli/cpu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

"""Monitor CPU resources."""


# standard libs
import sys

# internal libs
from ...core.logging import Logger
from ...core.exceptions import CompletedCommand
from ...__meta__ import __appname__, __copyright__, __license__, __website__
from ... import __appname__

# external libs
from cmdkit.app import Application
Expand All @@ -34,23 +35,12 @@


PROGRAM = f'{__appname__} cpu'
PADDING = ' ' * len(PROGRAM)

USAGE = f"""\
usage: {PROGRAM} <resource> [<args>...]
{PADDING} [--help]
usage: {PROGRAM} [-h] <resource> [<args>...]
{__doc__}\
"""

EPILOG = f"""\
Documentation and issue tracking at:
{__website__}
Copyright {__copyright__}
{__license__}.\
"""

HELP = f"""\
{USAGE}
Expand All @@ -62,9 +52,7 @@
-h, --help Show this message and exit.
Use the -h/--help flag with the above resource groups to
learn more about their usage.
{EPILOG}\
learn more about their usage.\
"""


Expand Down
22 changes: 4 additions & 18 deletions monitor/cli/cpu/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

"""Monitor CPU memory utilization."""


# type annotations
from __future__ import annotations

Expand All @@ -20,7 +21,7 @@
# internal libs
from ...core.exceptions import log_and_exit
from ...core.logging import Logger, PLAIN_HANDLER, CSV_HANDLER
from ...__meta__ import __appname__, __copyright__, __website__, __license__
from ... import __appname__

# external libs
import psutil
Expand All @@ -29,24 +30,12 @@


PROGRAM = f'{__appname__} cpu memory'
PADDING = ' ' * len(PROGRAM)

USAGE = f"""\
usage: {PROGRAM} [--percent | --actual] [--sample-rate SECONDS] [--human-readable]
{PADDING} [--plain | --csv [--no-header]]
{PADDING} [--help]
usage: {PROGRAM} [-h] [-s SECONDS] [--actual [--human-readable]] [--csv [--no-header]]
{__doc__}\
"""

EPILOG = f"""\
Documentation and issue tracking at:
{__website__}
Copyright {__copyright__}
{__license__}.\
"""

HELP = f"""\
{USAGE}
Expand All @@ -58,13 +47,10 @@
--plain Print messages in syslog format (default).
--csv Print messages in CSV format.
--no-header Suppress printing header in CSV mode.
-h, --help Show this message and exit.
{EPILOG}\
-h, --help Show this message and exit.\
"""


# initialize module level logger
log = Logger.with_name('cpu.memory')


Expand Down
24 changes: 5 additions & 19 deletions monitor/cli/cpu/percent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

"""Monitor CPU percent utilization."""


# type annotations
from __future__ import annotations

Expand All @@ -20,34 +21,22 @@
# internal libs
from ...core.exceptions import log_and_exit
from ...core.logging import Logger, PLAIN_HANDLER, CSV_HANDLER
from ...__meta__ import __appname__, __copyright__, __website__, __license__
from ... import __appname__

# external libs
import psutil
from cmdkit.app import Application, exit_status
from cmdkit.cli import Interface, ArgumentError


# program name is constructed from module file name
PROGRAM = f'{__appname__} cpu percent'
PADDING = ' ' * len(PROGRAM)

USAGE = f"""\
usage: {PROGRAM} [--total | --all-cores] [--sample-rate SECONDS]
{PADDING} [--plain | --csv [--no-header]]
{PADDING} [--help]
usage: {PROGRAM} [-h] [--all-cores] [-s SECONDS] [--csv [--no-header]]
{__doc__}\
"""

EPILOG = f"""\
Documentation and issue tracking at:
{__website__}
Copyright {__copyright__}
{__license__}.\
"""

HELP = f"""\
{USAGE}
Expand All @@ -58,13 +47,10 @@
--plain Print messages in syslog format (default).
--csv Print messages in CSV format.
--no-header Suppress printing header in CSV mode.
-h, --help Show this message and exit.
{EPILOG}\
-h, --help Show this message and exit.\
"""


# initialize module level logger
log = Logger.with_name('cpu.percent')


Expand All @@ -76,7 +62,7 @@ def cpu_total(callback, template: str = '{value}') -> None:

def cpu_per_core(callback, template: str = '[{i}] {value}') -> None:
"""Log the CPU utilization per core."""
for i, value in enumerate(psutil.cpu_percent(percpu=True)):
for i, value in enumerate(psutil.cpu_percent(percpu=True)): # noqa: type iterable
callback(template.format(i=i, value=value))


Expand Down

0 comments on commit 7f827af

Please sign in to comment.