diff --git a/tools/mem-measurements/README.md b/tools/mem-measurements/README.md new file mode 100644 index 000000000..18d6609bc --- /dev/null +++ b/tools/mem-measurements/README.md @@ -0,0 +1,66 @@ +# Script mem-measurements.sh v1.0.0 + +## Introduction + +This document describes the use of script `mem-measurements.sh v1.0.0`. +Please replace variables written in _italic_ with concrete values. + +**Background**: + +The goal of this script is tracking the memory consumption through the execution of a set of memory debug commands. + +## Parameters + +The script can be called with one optional parameter _output-dir_. +If the script willl be called without parameter, the default value "/opt/mem-measurements" will be used. +_output-dir_ will be created, if it doesn't exist. + +## Description + +The script calls the following commands: + +- cat /proc/meminfo +- free -h +- vmstat +- ps axo pmem,vsize,rss,pid,euser,cmd | sort -nr | head -n 1000 + +On each execution the script creates a dat file with the outputs of commands above: + +
+
+output-dir/data/data_YYYY-MM-DD_hh-mm-ss.dat
+
+
+
+By default the script keeps 168 dat files, which means one week of data if the script is executed once every hour.
+
+## Excecution
+
+The script should be executed by the **root** user and the attributes should be changed to `500`
+```
+# chmod 500 mem-measurements.sh
+# ./mem-measurements.sh
+```
+
+## Cron Job
+
+In order to set `mem-measurements.sh` as a cron job follow these instructions as the **root** user:
+
+In this example the script `mem-measurements.sh` will be executed once every hour at minute 20.
+
+1. Save the script `mem-measurements.sh` in a directory _install-dir_, e.g. `/opt/mem-measurements/`
+2. Change the attributes to `500`
+```
+# chmod 500 mem-measurements.sh
+```
+
+3. Add the record in crontab:
+
+
+
+# crontab -e
+20 * * * * install-dir/mem-measurements.sh 2>&1 | logger
+
+
+
+4. The directory _output-dir_/data/ will keep one week of data.
diff --git a/tools/mem-measurements/mem-measurements.sh b/tools/mem-measurements/mem-measurements.sh
new file mode 100755
index 000000000..934512b76
--- /dev/null
+++ b/tools/mem-measurements/mem-measurements.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+# (C) Copyright 2020 Fujitsu Enabling Software Technology GmbH
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+###########################
+# mem-measurements v1.0.0 #
+###########################
+
+# Uncomment for verbose logging in bash
+#set -x
+
+# Set default value for output directory
+outputDataDir="/opt/mem-measurements"
+
+# Default amount of max files to keep.
+# With a cron job running each hour: 24h x 7d = 168
+maxAmountFiles=168
+
+# Commands to be executed
+declare -a metricNames=(
+ "cat /proc/meminfo"
+ "free -h"
+ "vmstat"
+ "ps axo pmem,vsize,rss,pid,euser,cmd | sort -nr | head -n 1000"
+ )
+
+##############################
+# Don't edit below this line #
+##############################
+
+######### handle input params ##############
+if [ $# -gt 1 ]; then
+ echo "ERROR: illegal number of parameters, expected format: $0