Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow looping execution for monitools within the container #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```

2 changes: 1 addition & 1 deletion images/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM registry.access.redhat.com/ubi8/go-toolset:1.14.12 as builder
FROM registry.access.redhat.com/ubi8/go-toolset:1.15.13 as builder

USER root
WORKDIR /workspace
Expand Down
22 changes: 19 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,23 @@ $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 -lt $TOTAL_TIME ]]; do
MONITOOL_EXEC="${EXECUTION_FOLDER}/monictl -d "${DATA_FOLDER}/${ITERATION}" -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