In our app environment, we don’t allow developers to SSH into servers without leadership approval. Therefore, it is critical that our team provide tools to allow developers to debug problems using our monitoring tools.
For example, when we get an alert that a disk is getting full, you would want to know what files are using up all of the space.
- Python
- Ubuntu (16.x or later) or similar distribution
- SSH enabled servers
Prerequisite | Version |
---|---|
Python | ~ ^2.7 |
Updating to the latest releases is recommended.
If python and ssh is already installed in your machine, run the following commands to validate the versions:
python -v
ssh -h
If your versions are lower than the prerequisite versions, you should update.
- Open a Terminal / Command Line / Bash Shell in your projects directory (i.e.:
/yourprojectdirectory/
) - Clone the linix-disk-usage-util repository
$ git clone https://github.com/nirajKpanda/linux-disk-usage-util.git
This will download the entire linix-disk-usage-util repo to your project directory.
- Change directory to the new linix-disk-usage-util directory (
cd linix-disk-usage-util
)
Congratulations, you now have a local copy of the linix-disk-usage-util project!
Once you have linix-disk-usage-util cloned, before you start the application, you first need to install all of the dependencies:
pip install -r requirements.txt
[niraj@niraj]$python get_diskusage.py --help
usage: get_diskusage.py [-h] [-i HOST] [-u USER] [-p PASSWORD] [-f FILENAME]
-m MOUNTPOINT
optional arguments:
-h, --help show this help message and exit
-i HOST, --host HOST The hostname or IP address of the server to connect
-u USER, --user USER The remote server username preferably a sudo user
-p PASSWORD, --password PASSWORD
The password of the remote server user
-f FILENAME, --filename FILENAME
Load server credentials from configuration file,
provide absolute path of the config file
-m MOUNTPOINT, --mountpoint MOUNTPOINT
Mount point of the server directory structure
[niraj@niraj]$
[niraj@niraj]$python get_diskusage.py -i localhost -m /tmp
INFO:User requested to fetch local server file disk usage.....
Mount point is : /tmp
{
"/tmp/unity_support_test/tmp0": 0,
"/tmp/e3546f11-84f5-4c95-90e9a5af-36eeff8e/tmpdmp": 221248,
"/tmp/config-err-0PdOED": 0,
"/tmp//tmporg/tmpchromium/tmpChromium/tmpMNLHuI/Skype1_5/tmppng": 652,
"/tmp/a": 349,
"/tmp//tmpX0-lock": 11
}
[niraj@niraj]$
[niraj@niraj]python get_diskusage.py -i -u -p -m
[niraj@nira]$python get_diskusage.py -f server.config -m /tmp