Powershell Script to Log Blue Iris Memory (RAM) Usage

jaydeel

BIT Beta Team
Nov 9, 2016
1,557
1,580
SF Bay Area
I've created a PowerShell script to continuously log Blue Iris memory usage parameters for both the server, and the main Blue Iris process.

Because I found that Blue Iris can become erratic during a memory leak, the memory usage parameters are obtained via Powershell commands - instead of via Blue Iris by either of these approaches:
  • querying the Blue Iris webserver via a JSON status command, or
  • using a Blue Iris Action Set write-to-a-file Action with macros %014, %012 and %017.

The design goal of the script is collect as much data as possible during a memory leak event.... Typically, the script would be executed every 3 minutes or so from Windows Task Scheduler. If you use a slower frequency (say every 5+ minutes) and are actively monitoring this file, this can be detrimental because, as just noted, the Blue Iris server can become erratic quite quickly during a memory leak event, and it can be helpful to know about it sooner rather than later.

The script's output is a CSV log file with the following columns:
  • Timestamp
  • SoftwareUsedRamBytes - the memory used by the Blue Iris process
  • Uptime - the uptime for the Blue Iris process
  • RamPct - the memory used by the system
  • Tag - used to identify background, console and simulation-created entries
  • Host - used to identify the Windows process that called the script

V1.csv_file_in_viewer.png


If you are curious, this screenshot shows the CSV file as viewed by the Powershell Out-GridView cmdlet. I've previously posted about this and other lightweight CSV viewers. Of course, you can always simply open & inspect CSV files a text/code editor (like NotePad++). In some cases this can be preferable when you are searching for specific date pattern or events.

HOW TO GUIDE...

STEP #1:


Install the script and its companion 'user settings file'

  1. Extract all the files from the attached zip file to your desktop, or scripts folder.
  2. Please note that the folder used must be in your PC's environment path.
  3. Create a working folder for this script - it will be used to process the output CSV files.
  4. To use the folder, you must edit a user setting $csv_logfile_path in the user-settings script file (see STEP #2)
NOTE: If you've never used PowerShell on your Blue Iris PC, you may first to need to change its default security policy.
Open PowerShell in Administrator mode, and type the following, then hit the Enter key: Set-ExecutionPolicy RemoteSigned
(click <here> for a nice beginner's tutorial to using PowerShell).

STEP #2:

Edit the user settings file

The user settings file is named 'BI_ram_logger_user_settings.ps1'​
  1. Open the file in a text editor (a code text editor is recommended; I use Notepad++.
  2. Edit the REQUIRED SETTINGS section (see screenshot)
  3. Ignore the remaining settings for now. They provide customizations that you may want to explore later.
V1.user_settings.png

STEP #3:

Test the script from the PowerShell console

Open an Admin PowerShell window, or Powershell-ISE window (I use Windows Terminal):​
Type the following command into the console.​
BI_ram_logger.ps1 -Current
Hit the Enter key.​
This will show the current parameters without logging the data.​
Next, remove the argument -Current​
BI_ram_logger.ps1
Hit the Enter key.​
Both responses should look like following screenshot:​
V1.output_1.png
The script populates the working folder with CSV log files that are automatically rolled over every month.
Furthermore, the script automatically creates a 'stack' of the 5 most recent files, which makes it easier to use the most recent files for charting programs, etc.​
V1.csv_files.png


STEP #4

Automate the script from Task Scheduler.
task_scheduler.png.png

USAGE GUIDE Screenshots:
V1.usage_guide.png V1.usage_guide_examples.png

SCRIPT ZIP FILE:
 

Attachments

Last edited:
Advanced features...

The script also has two optional commands that can insert and remove fake data to simulate a memory leak event.

Why? This can be useful when testing scripts that monitor the CSV log file.

For example:
BI_ram_logger.ps1 -SimLeak 5X, 400MB will append 5 new rows simulating a stepwise 400MB increase in the software used RAM column.
BI_ram_logger.ps1 -RemSimEntries will remove all 'simulation'-tagged entries from the CSV log file.

To learn more, try
bi_ram_logger -Examples