sensu-plugins / sensu-plugins-process-checks

This plugin provides native process instrumentation for monitoring and metrics collection, including: process status, uptime, thread count, and others.
http://sensu-plugins.io
MIT License
20 stars 55 forks source link

Uncaught exception in metrics-per-process.py #91

Open boutetnico opened 5 years ago

boutetnico commented 5 years ago

This seems related to #25.

I had 3 occurences of the following Exception:

Traceback (mo st recent call last):
  File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-process-checks-3.2.0/bin/metrics-per-process.py", line 330, in <module>
    main()
  File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-process-checks-3.2.0/bin/metrics-per-process.py", line 318, in main
    pids = find_pids_from_name(options.process_name)
  File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-process-checks-3.2.0/bin/metrics-per-process.py", line 119, in find_pids_from_name
    return find_pids(matcher)
  File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-process-checks-3.2.0/bin/metrics-per-process.py", line 104, in find_pids
    if matcher(path):
  File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-process-checks-3.2.0/bin/metrics-per-process.py", line 116, in matcher
    file_handler = open(path + '/comm', 'r')
IOError: [Errno 2] No such file or directory: '/proc/19630/comm'

In #25 we catch OSError to cover the case when directory /proc/<pid>/ does not exist. In this issue however, it seems /proc/<pid>/ exists but /proc/<pid>/comm does not.

I believe we should catch both OSError & IOError to cover both cases.