Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 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
55 changes: 55 additions & 0 deletions tools/mem-measurements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Script mem-measurements.sh v1.0.0

## Introduction

This document describes the use of script `mem-measurements.sh v1.0.0`

**Background**:

The goal of this script is tracking the memory consumption through the execution of a set of memory debug commands.

## 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:

```
/opt/mem-measurements/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 the directory `/opt/mem-measurements/`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattibf @adriancz
log-agent is installed in /opt/monasca-log-agent/ in customer environment and we can't create this directory. So please change this variable as /opt/monasca-log-agent/.

2. Change the attributes to `500`
```
# chmod 500 mem-measurements.sh
```

3. Add the record in crontab:

```
# crontab -e
20 * * * * /opt/mem-measurements/mem-measurements.sh 2>&1 | logger

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with L42

```

4. The directory `/opt/mem-measurements/data/` will keep one week of data.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with L42

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@https://github.com/haruki-yamanashi:
I suggest not to write script output to installation directory of monasca-log-agent.
I changed the script so that output directory can be specified as an optional parameter when calling the script.
Readme.md has been adjusted as well.
Pls. check

62 changes: 62 additions & 0 deletions tools/mem-measurements/mem-measurements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/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 the output directory
outputDataDir="/opt/mem-measurements"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattibf @adriancz
log-agent is installed in /opt/monasca-log-agent/ in customer environment and we can't create this directory. So please change this variable as /opt/monasca-log-agent/.


# 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 #
##############################

# Creating output data dir
mkdir -p $outputDataDir/data

# Collecting memory status data
for metricName in "${metricNames[@]}"; do
{
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "+ COMMAND: $metricName"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
eval "$metricName"
echo -e "\n"
} &>> tmpdata.dat
done

mv tmpdata.dat $outputDataDir/data/"data_$(date +%Y-%m-%d_%H-%M-%S).dat"

# Removing old data files
((maxAmountFiles++))
# shellcheck disable=SC2012
ls $outputDataDir/data/data_*.dat -t | tail -n +"$maxAmountFiles" | xargs -I {} rm {}