---
title: "ALperf Common Use"
canonical: "https://help.agiloft.com/space/HELP/43715601/ALperf+Common+Use"
format: markdown
---
<span style="color: #000000">ALperf can be used to retrieve system level information like CPU load and disk usage. </span><span style="color: #000000">To instantiate ALperf, import it and call its constructor without passing any arguments:</span>

```python
from ALperf import ALperf
perf_data = ALperf()
```

Here is a sample code that makes use of the ALperf module.

##### **Example**

```python
#####################################################################
# Synopsis:
# Store the CPU load in a record of the KB and alert the sysadmin
# if the load is higher than a threshold.
######################################################################
import sys
from ALget import ALget
from ALset import ALset
from ALperf import ALperf
import smtplib
from email.mime.text import MIMEText

def action(inputXMLFile, outputXMLFile):
    get_data = ALget(inputXMLFile)
    set_data = ALset(outputXMLFile)
    perf_data = ALperf()
    cpu_load = perf_data.cpuLoad
    set_data.recordField("field_load", str(cpu_load))
    if cpu_load > 2:
        try:
            body = ("The current load on the server is high.\n"
                    "Please take a look.\n\n"
                    "Thank you,\n")
            msg = MIMEText(body)
            msg['Subject'] = "Alert: Server load is high"
            msg['From'] = "frontdesk@company.com"
            msg['To'] = "sysadmin@company.com"
            s = smtplib.SMTP('agiloft.mail')
            s.sendmail("frontdesk@company.com", "sysadmin@company.com", msg.as_string())
            s.quit()
        except:
            set_data.recordField("notes", "There was a problem sending email\n")
    set_data.exitAction(ALset.ACCEPT)
    set_data.save()

action(sys.argv[1], sys.argv[2])


```

The sample code above retrieves the **cpuLoad** attribute from the ALperf module.

Here is a list of the attributes available for retrieval:

- `hostName`
- `ipAddress`
- `systemBoot`
- `osType`
- `osDistro`
- `osBuild`
- `gLibc`
- `cpuCount`
- `ramTotal`
- `ramUsed`
- `memAvailable`
- `swapTotal`
- `swapUsed`
- `databaseType`
- `databaseAddress`
- `jbossType`
- `jbossMem`
- `mysqlMem`
- `cpuLoad`
- `topCpuProcess`
- `topMemProcess`
- `appDiskUsed`
- `appDiskFree`
- `dbDiskUsed`
- `dbDiskFree`
- `baseDir`

  
Here is a list of the methods (functions) available from the module:-

- `getCpuModel()`
- `getJreVersion()`
- `getNginxVersion()`
- `getAppBootTime()`
- `getHeapUsage()`
- `getDbVersion()`
- `getDbOptionValue(dbOption)`
- `getStorageType()`

  




> Macro (hide-if)
> 
> #### Related articles
> 
> > Macro (contentbylabel)