forked from monasca/monasca-docker
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Added mem-measurements v1.0.0 #124
Open
chaconpiza
wants to merge
4
commits into
master
Choose a base branch
from
mem-measurements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: | ||
|
||
<pre> | ||
<code> | ||
<i>output-dir</i>/data/data_YYYY-MM-DD_hh-mm-ss.dat | ||
</code> | ||
</pre> | ||
|
||
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: | ||
|
||
<pre> | ||
<code> | ||
# crontab -e | ||
20 * * * * <i>install-dir</i>/mem-measurements.sh 2>&1 | logger | ||
</code> | ||
</pre> | ||
|
||
4. The directory _output-dir_/data/ will keep one week of data. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <output directory>" | ||
exit 1; | ||
elif [ $# -eq 1 ]; then | ||
outputDataDir=$1 | ||
fi | ||
|
||
# Creating output data dir | ||
mkdir -p $outputDataDir/data | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "$0: ERROR: output directory $outputDataDir/data could not be created" | ||
exit 1 | ||
fi | ||
|
||
echo "$0: collecting information in directory $outputDataDir" | ||
|
||
# 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 {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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/
.