resource_monitor(1)
β¨ resource_monitor(1) β¨
okay so bestie, you know how you wanna know EXACTLY how much cpu, memory, io and disk your little process tree is eating?? this is that tool. it lives in the Cooperative Computing Tools crew, and it is so iconic.
πΈ NAME πΈ
resource_monitor β monitors the cpu, memory, io, and disk usage of a tree of processes.
π SYNOPSIS π
resource_monitor [options] -- command [command-options]
π DESCRIPTION π
So like. resource_monitor is the tool that watches the computational resources used by the process created by the command you hand it as an argument, and all its descendants. The whole fam. π
Important tea though: the monitor works while a process was running, so literally every single piece of info it reports should be considered just an estimate. That's in contrast with direct methods, like ptrace. It works on Linux, and it can be used automatically by makeflow and work queue applications.
and it gets better. You can also specify maximum resource limits, either as a file or as a string right there on the command line. If one of the resources goes over the limit you specified, then the monitor terminates the task, and reports which resource went over the respective limits. vibe check failed, sorry bestie. π
On systems that support it, resource_monitor wraps some libc functions to obtain a better estimate of the resources used. fancy.
Currently, the monitor does not support interactive applications. That is, if a process issues a read call from standard input, and standard input has not been redirected, then the tree process is terminated. This is likely to change in future versions of the tool. (not me being impatient for the update π)
π¦ the log files π¦
resource_monitor generates up to three log files:
- a summary file encoded as
jsonwith the maximum values of resource used - a time-series that shows the resources used at given time intervals
- a list of files that were opened during execution
π the summary file π
The summary file is a JSON document with the following fields. Unless indicated, all fields are an array with two values, a number that describes the measurement, and a string describing the units (e.g., [ measurement).
command: the command line given as an argumentstart: time at start of execution, since the epochend: time at end of execution, since the epochexit_type: one of"normal","signal"or"limit"(a string)signal: number of the signal that terminated the process. Only present ifexit_typeissignalcores: maximum number of cores usedcores_avg: number of cores ascpu_time/wall_timeexit_status: final status of the parent processmax_concurrent_processes: the maximum number of processes running concurrentlytotal_processes: count of all of the processes createdwall_time: duration of execution,end - startcpu_time:user+systemtime of the executionvirtual_memory: maximum virtual memory across all processesmemory: maximum resident size across all processesswap_memory: maximum swap usage across all processesbytes_read: amount of data read from diskbytes_written: amount of data written to diskbytes_received: amount of data read from network interfacesbytes_sent: amount of data written to network interfacesbandwidth: maximum bandwidth usedtotal_files: total maximum number of files and directories of all the working directories in the treedisk: size of all working directories in the treelimits_exceeded: resources over the limit with-l,-Loptions (JSON object)peak_times: seconds from start when a maximum occured (JSON object)snapshots: List of intermediate measurements, identified bysnapshot_name(JSON object)
π the time-series log π
The time-series log has a row per time sample. For each row, the columns have the following meaning (all columns are integers):
wall_clockβ the sample time, since the epoch, in microsecondscpu_timeβ accumulated user + kernel time, in microsecondscoresβ current number of cores usedmax_concurrent_processesβ concurrent processes at the time of the samplevirtual_memoryβ current virtual memory size, in MBmemoryβ current resident memory size, in MBswap_memoryβ current swap usage, in MBbytes_readβ accumulated number of bytes read, in bytesbytes_writtenβ accumulated number of bytes written, in bytesbytes_receivedβ accumulated number of bytes received, in bytesbytes_sentβ accumulated number of bytes sent, in bytesbandwidthβ current bandwidth, in bpstotal_filesβ current number of files and directories, across all working directories in the treediskβ current size of working directories in the tree, in MB
β¨ OPTIONS β¨
the full menu, no skips, we eat every flag:
-d,--debug=<subsystem>β Enable debugging for this subsystem.-o,--debug-file=<file>β Write debugging output to this file. By default, debugging is sent tostderr(":stderr"). You may specify logs to be sent tostdout(":stdout") instead.-v,--versionβ Show version string.-h,--helpβ Show help text.-i,--interval=<n>β Maximum interval between observations, in seconds (default=1).--pid=pidβ Trackpidinstead of executing a command line (warning: less precise measurements).--accurate-short-processesβ Accurately measure short running processes (adds overhead).-c,--sh=<str>β Read command line fromstr, and execute as/bin/sh -c str.-l,--limits-file=<file>β Use maxfile with list ofvar: valuepairs for resource limits.-L,--limits=<string>β String of the form"var: value, var: valueto specify resource limits. (Could be specified multiple times.)-f,--child-in-foregroundβ Keep the monitored process in foreground (for interactive use).-O,--with-output-files=<template>β Specify template for log files (default=resource-pid).--with-time-seriesβ Write resource time series totemplate.series.--with-inotifyβ Write inotify statistics of opened files to default=template.files.-V,--verbatim-to-summary=<str>β Include this string verbatim in a line in the summary. (Could be specified multiple times.)--measure-dir=dirβ Follow the size ofdir. By default the directory at the start of execution is followed. Can be specified multiple times. See--without-disk-footprintbelow.--follow-chdirβ Follow processes' current working directories.--without-disk-footprintβ Do not measure working directory footprint. Overrides--measure-dir.--no-pprintβ Do not pretty-print summaries.--snapshot-events=fileβ Configuration file for snapshots on file patterns. See below.--catalog-task-name=<task-name>β Report measurements to catalog server with"task"=<task-name>.--catalog-project=<project>β Set project name of catalog update to<project>(default=<task-name>).--catalog=<catalog>β Use catalog server<catalog>. (default=catalog.cse.nd.edu:9097).0,"--catalog=<catalog>");--catalog-interval=<interval>β Send update to catalog every<interval>seconds. (default=30).
The limits file should contain lines of the form:
resource: max_value
It may contain any of the following fields, in the same units as defined for the summary file:
max_concurrent_processes, wall_time, cpu_time, virtual_memory, resident_memory, swap_memory, bytes_read, bytes_written, workdir_number_files_dirs, workdir_footprint
π ENVIRONMENT VARIABLES π
CCTOOLS_RESOURCE_MONITOR_HELPERβ Location of the desired helper library to wraplibccalls. If not provided
π EXIT STATUS π
0β The command exit status was0, and the monitor process ran without errors.1β The command exit status was non-zero, and the monitor process ran without errors.2β The command was terminated because it ran out of resources (see options-l,-L).3β The command did not run succesfully because the monitor process had an error.
To obtain the exit status of the original command, see the generated file with extension .summary.
β¨ SNAPSHOTS β¨
okay so bestie, your fave resource_monitor can literally take snapshots of the resources used, based on the files that the monitored processes create. π
The classic move is to set a watch on a log file and generate a snapshot when a line in the log matches a pattern. To turn on this whole snapshot situation, hit it with --snapshot-events=file, where file is a JSON-encoded document that looks exactly like this:
{
"FILENAME": {
"from-start":boolean,
"from-start-if-truncated":boolean,
"delete-if-found":boolean,
"events": [
{
"label":"EVENT_NAME",
"on-create":boolean,
"on-truncate":boolean,
"on-pattern":"REGEXP",
"count":integer
},
{
"label":"EVENT_NAME",
...
}
]
},
"FILENAME": {
...
}
All fields but label are optional. No cap.
FILENAMEβ Name of a file to watch.from-start:boolean β IfFILENAMEexits when the monitor starts running, process from line 1. Default:false, as monitored processes may be appending to already existing files.from-start-if-truncatedβ IfFILENAMEis truncated, process from line 1. Default:true, to account for log rotations.delete-if-foundβ DeleteFILENAMEwhen found. Default:falseevents:labelβ Name that identifies the snapshot. Only alphanumeric,-, and_characters are allowed.on-createβ Take a snapshot every time the file is created. Default:falseon-deleteβ Take a snapshot every time the file is deleted. Default:falseon-truncateβ Take a snapshot when the file is truncated. Default:falseon-patternβ Take a snapshot when a line matches the regexp pattern. Default: nonecountβ Maximum number of snapshots for this label. Default:-1(no limit)
The snapshots get recorded in two places: in the main resource summary file under the key snapshots, and as a JSON-encoded document, with the extension identified by the key "snapshot_name" β that's a comma-separated string of label(count) elements. A label corresponds to a name that identifies the snapshot, and the count is the number of times an event was triggered since the last check (several events may be triggered, for example, when several matching lines are written to the log). Several events may have the same label, and exactly one of on-create, on-truncate, and on-pattern should be specified per event. π
πΈ EXAMPLES πΈ
To monitor sleep 10, at 2 second intervals, with output to sleep-log.summary, and with a monitor alarm at 5 seconds:
% resource_monitor --interval=2 -L"wall_time: 5" -o sleep-log -- sleep 10
Execute date and redirect its output to a file:
% resource_monitor --sh 'date > date.output'
It can also be run automatically from makeflow, by specifying the -M flag:
% makeflow --monitor=some-log-dir Makeflow
In this case, makeflow wraps every command line rule with the monitor, and writes the resulting logs per rule in the some-log-dir directory.
Additionally, it can be run automatically from Work Queue:
q = work_queue_create_monitoring(port);
work_queue_enable_monitoring(q, some-log-dir, /*kill tasks on exhaustion*/ 1);
wraps every task with the monitor and writes the resulting summaries in some-log-file.
π¦ SNAPSHOTS EXAMPLES π¦
Generate a snapshot when "my.log" is created:
{
"my.log":
{
"events":[
{
"label":"MY_LOG_STARTED",
"on-create:true
}
]
}
}
Generate snapshots every time a line is added to "my.log":
{
"my.log":
{
"events":[
{
"label":"MY_LOG_LINE",
"on-pattern":"^.*$"
}
]
}
}
Generate snapshots on particular lines of "my.log":
{
"my.log":
{
"events":[
{
"label":"started",
"on-pattern":"^# START"
},
{
"label":"end-of-start",
"on-pattern":"^# PROCESSING"
}
{
"label":"end-of-processing",
"on-pattern":"^# ANALYSIS"
}
]
}
}
The monitor can also generate a snapshot when a particular file is created. The monitor can detect this file, generate a snapshot, and delete the file to get ready for the next snapshot. In the following example the monitor takes a snapshot every time the file please-take-a-snapshot is created:
{
"please-take-a-snapshot":
{
"delete-if-found":true,
"events":[
{
"label":"manual-snapshot",
"on-create":true
}
]
}
}
π BUGS AND KNOWN ISSUES π
- The monitor cannot track the children of statically linked executables.
- The option
--snapshot-eventsassumes that the watched files are written by appending to them. File truncation may not be detected if between checks the size of the file is larger or equal to the size after truncation. File checks are fixed at intervals of 1 second.
π COPYRIGHT π
The Cooperative Computing Tools are Copyright (C) 2005-2019 The University of Notre Dame. This software is distributed under the GNU General Public License. See the file COPYING for details.
That's the whole vibe, bestie. This page is from CCTools 8.0.0 DEVELOPMENT and it's resource_monitor(1). The date? The footer didn't give us one, but it's giving timeless icon behavior. π Stay slaying. β¨
π¦ where this page comes from
- debian bookworm: coop-computing-tools 9.9-2+b4 Β· GPL-2.0-only
- ubuntu jammy: coop-computing-tools 9.9-2ubuntu3 Β· GPL-2.0-only
- ubuntu noble: coop-computing-tools 9.9-4ubuntu4 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms