How to monitor long running scripts with pv

Goal

Sometimes you want to run a long running process without feedback. PV is a tool that allows you to do just that.

Example

  • Running a mysqldump
    mysqldump <yourparams> | pv --progress --size 100m > /tmp/dump.sql
  • Importing a mysql dump
    pv dump.sql | mysql <yourparams>
  • Copying a large file
    pv /originallocation/largefile.bin > /otherlocation/largefile.bin
  • Create a zip file
    pv largefile.txt | zip > largefile.zip
  • Create a tar archive
    tar -czf - ./foldertotar | (pv -p --timer --rate --bytes > backup.tgz)

Problem

Sounds cool, but pv isn’t available by default.

Solution

Luckily, there is an easy solution.

Simply add the pv package in your .platform.app.yaml file. This will automatically install pv. So you can use it.

dependencies:
  nodejs: # Specify one NPM package per line.
    pv: '~1.0.1'

Note: you can do this in any container type. PHP, nodejs, golang, …

This works because there is a nodejs package that does the heavy lifting for us.

For more information on dependencies, check our documentation