0

I have an nvr system that recording video surveillance into a file server (Debian). I made a Nagios plugin to check if the NVR system is recording correctly and send me a notification when it stops doing that. The issue is I'm using a find command:

find /srv/unifi-video/videos/ -name '*.ts' -mmin -10 | wc -l

and since it's checking through 400 Gb+ of files Nagios keeps timing out and sending "NRPE Socket timed out" messages.

Is it possible to make the find command to search only for the files created in the passed 10 minutes and not only the whole folder ?

  • What do you mean by “not the whole folder”? Do you mean that the files are created in /srv/unifi-video/videos, not a subdirectory, and you don't want find to explore the subdirectories? If it's not that, what do you mean? – Gilles Sep 22 '15 at 22:11
  • I meant to check inside the folder and sub-folders but only for a specific time frame. Like only for the passed 10 minutes and see if there's files or not. The way find is working takes a very long time to go through 400 Gb+ of files and that causes my plugin to timeout. I figured a solution in Nagios by adjusting the interval time and increase the timeout. – Youssef Karami Sep 23 '15 at 14:58
  • I don't think the size of files should matter most, it's probably just the sheer amount of files. – phk Dec 25 '16 at 16:57
0

Your code already seems correct, -mmin -10 narrows results to "modified less than 10 minutes ago". If your videos/ also has other items such as subdirectories, you might be able to shave some time time by ignoring directories and focusing only on files, adding -type f:

find /srv/unifi-video/videos/ -type f -name '*.ts' -mmin -10 | wc -l

If you have any finer control over how your nvr system saves files, maybe try to make it save only *.ts files in a dedicated directory eg videos/ts somehow, so find only has to deal with ts files and nothing else.

Other Ideas

Hopefully you already tried looking into documentation for your nvr system to see if there was some logging feature that just needed to be enabled. Why I mention logging is because it would be faster to get status information if you just had to make a script to read logs, compared to a script using find to examine file system records.

  • I checked and this NVR system is creating random folder after the path like 00-558-5282.... and then sub-directories for dates... I think what makes the command to take forever to execute is because it's accessing all folders that available and it's supposed to do that since I'm not sure which one is NVR using... – Youssef Karami Sep 22 '15 at 18:06
  • In that case yes, try -type f so find will only focus on files. I did a test on a local directory with many, many subdirectories, and I only modified a file deep in the structure less than 10 minutes ago. Using time like this time find -mmin -10, compared to time find -type f -mmin -10, both found my file, and the later one seems to be 3s faster. Only 3s for me but if you have more folders/bigger files, it should be a greater improvement. – estudiante27 Sep 22 '15 at 18:17
  • I did that but it's not really helping. I wish the find command could have more options – Youssef Karami Sep 22 '15 at 20:10
  • would using relatime as a mount option work any better ? just a vague idea. though not sure you can find using access time – infinite-etcetera Jan 30 '17 at 8:07
  • Accessing a folder with few files is often quicker than accessing a folder with millions of files. – Kusalananda Jun 8 '18 at 8:10
0

I would first find the latest directory used and then check only that directory:

find $(ls -rt /srv/unifi-video/videos/* | tail -1) -type f -name '*.ts' -mmin -10 | wc -l

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.