Skip to content

Commit

Permalink
added support for looping monitools execution on target for a period …
Browse files Browse the repository at this point in the history
…with an interval
  • Loading branch information
adrianriobo committed Sep 3, 2021
1 parent b1f9c0d commit 2ecc4a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
monitools
==
# monitools

Gather resource consumption data around a CodeReady Containers instance

Expand All @@ -10,23 +9,20 @@ The following diagram represent the interaction of monitools container with a ho
![Overview](docs/overview.jpg?raw=true)

The container will be configured with ENVs:

#### target host configuration

**TARGET_HOST**(*mandatory*): Target host address
**TARGET_HOST**(*mandatory*): Target host address
**TARGET_HOST_USERNAME**(*mandatory*): username

Chose one of following depending on the target auth mechanism:

**TARGET_HOST_KEY_PATH**(*optional*): key path
**TARGET_HOST_PASSWORD**(*optional*): pasword

#### monictl configuration

**MONICTL_REPETITIONS**(*optional, default 5*)
**MONICTL_INTERVAL**(*optional, default 1*)
**MONITOOL_PERIOD**(*optional, in case we want to loop the monitool execution for a period of time. Period is a number (hours) If not set it will run only once*)
**MONITOOL_PERIOD**(*optional, in case we define MONITOOL_PERIOD. We can set the interval, default is 30m, interval is defined according linux sleep command time syntax*)
**RESULTS_PATH**(*optional, define the target path on the container to copy back results, default is /output*)

Sample container execution

```bash
podman run -it --rm \
-e TARGET_HOST_USERNAME=XXXX \
Expand All @@ -50,11 +46,13 @@ make install
1. Create directory where you want `monictl` to deposit the data.
2. Have a running instance of CRC (`crc status` returns `Running` for both VM and the cluster)
3. Run
```bash

```bash
monictl -d=<data dir> -n=<num of reps> -s=<length of pause>
```
4. Look into your data folder to inspect the files.

```

4. Look into your data folder to inspect the files.

### Flags/arguments

- `-d`: data directory (relative to current directory)
Expand Down Expand Up @@ -95,12 +93,12 @@ Then use as any other package, e.g. by importing as:
``` bash
import github.com/code-ready/monitools/tools
```

### Example

In `monitools/examples` you will find a short program that imports this module and the `tools` package and runs one of its functions. It assumes an existing CRC VM and probes for CPU usage of the `qemu` process 5 times with 1s sleep inbetween probes. Resulting %CPU is recorded in `cpu.csv` in the same `monitools/examples` folder. Run the example script `example.go` by

``` bash
$ cd monitools/examples
$ go run example.go
cd monitools/examples
go run example.go
```

23 changes: 20 additions & 3 deletions images/build/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MONICTL_PATH=/usr/local/bin/monictl
RESULTS_PATH="${RESULTS_PATH:-/output}"
MONICTL_REPETITIONS="${MONICTL_REPETITIONS:-5}"
MONICTL_INTERVAL="${MONICTL_INTERVAL:-1}"
MONITOOL_INTERVAL="${MONITOOL_INTERVAL:-30m}"

if [ "${DEBUG:-}" = "true" ]; then
set -xuo
Expand All @@ -23,6 +24,7 @@ validate=true
[[ -z "${TARGET_HOST_KEY_PATH}" && -z "${TARGET_HOST_PASSWORD}" ]] \
&& echo "TARGET_HOST_KEY_PATH or TARGET_HOST_PASSWORD required" \
&& validate=false

[[ $validate == false ]] && exit 1

# Set SCP / SSH command
Expand All @@ -41,9 +43,24 @@ $SSH "${TARGET_HOST_USERNAME}@${TARGET_HOST}" "mkdir -p ${EXECUTION_FOLDER} && m
# Copy monictl to target host
$SCP "${MONICTL_PATH}" "${TARGET_HOST_USERNAME}@${TARGET_HOST}:${EXECUTION_FOLDER}"

# Run (one shot) monictl
MONITOOL_EXEC="${EXECUTION_FOLDER}/monictl -d ${DATA_FOLDER} -n ${MONICTL_REPETITIONS} -s ${MONICTL_INTERVAL}"
$SSH "${TARGET_HOST_USERNAME}@${TARGET_HOST}" "${MONITOOL_EXEC}"
if [[ -z "${MONITOOL_PERIOD}" ]]; then
# Run (one shot) monictl
MONITOOL_EXEC="${EXECUTION_FOLDER}/monictl -d ${DATA_FOLDER} -n ${MONICTL_REPETITIONS} -s ${MONICTL_INTERVAL}"
$SSH "${TARGET_HOST_USERNAME}@${TARGET_HOST}" "${MONITOOL_EXEC}"
else
START=$(date +%s)
TOTAL_TIME=$((60 * 60 * ${MONITOOL_PERIOD}))
UPTIME=$(($(date +%s) - $START))
ITERATION=0
while [[ $UPTIME < $TOTAL_TIME ]]; do
DATA_FOLDER="${EXECUTION_FOLDER}/data-${ITERATION}"
MONITOOL_EXEC="${EXECUTION_FOLDER}/monictl -d ${DATA_FOLDER} -n ${MONICTL_REPETITIONS} -s ${MONICTL_INTERVAL}"
$SSH "${TARGET_HOST_USERNAME}@${TARGET_HOST}" "${MONITOOL_EXEC}"
UPTIME=$(($(date +%s) - $START))
((ITERATION++))
sleep ${MONITOOL_INTERVAL}
done
fi

# Get results
mkdir -p "${RESULTS_PATH}"
Expand Down

0 comments on commit 2ecc4a0

Please sign in to comment.