---
# System prepended metadata

title: How to collect performance data for Linux?

---

# How to collect performance data for Linux?
*LAST UPDATED: NOV 15,2022*

Learn how to use Service Tool for resource monitoring to capture data, such as processor or memory usage, for Linux.

## Steps

### 1. Prepare environment
- Python 3.7 or higher
- zip
- collectl (collectl-4.3.1.src.tar.gz)

### 2. Prerequisite
1. Download `service_tool.zip` and put it in `/root` directory.
2. Prepare working directory
``` shell=
export AXE_DATA_PATH=/home/dsqa
mkdir $AXE_DATA_PATH
```
### 3. Prepare Service Tool

```shell=
sudo cp /root/service_tool.zip $AXE_DATA_PATH
cd $AXE_DATA_PATH
unzip service_tool.zip -d service_tool
```

### 4. Set tool directory variable
```shell=
export SERVICE_TOOL_PATH=$AXE_DATA_PATH/service_tool
export PYTHONPATH=$SERVICE_TOOL_PATH/SERVICE:$SERVICE_TOOL_PATH/PYTHONLIB
```
### 5. Install Python libraries
```shell=
sudo python -m pip install -r $SERVICE_TOOL_PATH/PYTHONLIB/environment/localvar/requirements.txt
sudo python -m pip install -r $SERVICE_TOOL_PATH/SERVICE/requirements.txt
```

### 6. Prepare file (Skip this step if you don't need to upload data via Internet)
- secret.json (under $SERVICE_TOOL_PATH)

### 7. Prepare environment variables 
This is to prepare test information which is uesd in report query. There are three environment variables:
- `AXE_DSA_POLICY`: the policy code on DSM. If the test is under no DSA, please fill in `nonePolicy`
- `AXE_DSA_BUILD`: the DSA version. If the test is under no DSA, please fill in `noneDSA`
- `AXE_SLACK_USER`: the name of tester. This is for report creation.

The section below is the examples under two different test scenarios.
#### Option 1: test under no DSA
```shell=
export AXE_DSA_POLICY=nonePolicy
export AXE_DSA_BUILD=noneDSA
export AXE_SLACK_USER=<fill in tester name>
```
#### Option 2: test under DSA
```shell=
export AXE_DSA_POLICY=<fill in policy code on DSM, ex:11A11101101>
export AXE_DSA_BUILD=<fill in DSA version, ex: 20.0.0.2204>
export AXE_SLACK_USER=<fill in tester name>
```

### 8. Create localvar file
File `localvar` is a json file that describe the test environment, such as DSA build version or tester name. A part of values comes from the environment variables set in step 1-7. 
```shell=
cd $SERVICE_TOOL_PATH/PYTHONLIB/environment/localvar
python localvar.py $SERVICE_TOOL_PATH/localvar_prepare.json localvar.json
mv localvar.json $SERVICE_TOOL_PATH
```

### 9. Trigger Service Tool 
Start monitoring and data upload process. 
```shell=
vi run.sh
```
```shell=
#!/bin/bash
export AXE_DATA_PATH=/home/dsqa
export SERVICE_TOOL_PATH=$AXE_DATA_PATH/service_tool
export PYTHONPATH=$SERVICE_TOOL_PATH/SERVICE:$SERVICE_TOOL_PATH/PYTHONLIB

cd $SERVICE_TOOL_PATH/SERVICE/admin
python service_agent.py --localvar_filepath=$SERVICE_TOOL_PATH/localvar.json
```

```shell=
sudo sh run.sh
```
