-
Notifications
You must be signed in to change notification settings - Fork 3
Added mem-measurements v1.0.0 #124
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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/` | ||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with L42 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @https://github.com/haruki-yamanashi: |
||
| 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" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| # 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 {} | ||
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/.