archive_command failed causing master to run out of disk space. Is there a command that prioritizes master's health
I'd recommend a slightly different approach.  Instead of testing for number of failures because a large number might lead to low disk space, test for low disk space directly.

archive_command = 'rsync -a %p _postgresql@serverip:/var/postgresql/wal_archive/%f || (df -P /var/data/pg_wal|awk "NR==2 &amp;&amp; \$4&lt; 400000 {exit 0}; NR==2 {exit 1}")'


But be advised that rsync is a dangerous approach in the first place, because it doesn't guarantee a successful fsync of the file written to the remote side (and the directory that that file is in) before it returns success locally. 

Or an entirely different approach: set your replica up as a streaming replica, rather than log shipping replica.  Then set "wal_keep_segments" to a value a little bit less than the amount of space reserved for pg_wal.  Note that this only works if the space is hard reserved for pg_wal, that is, no one can "borrow" some free space for other purposes, like temp files.

And of course, if your replica was down for a while and you didn't notice, then you probably need a monitoring solution as well.