sensu-plugins / sensu-plugins-memory-checks

This plugin provides native memory instrumentation for monitoring and metrics collection, including: memory usage via `free` and `vmstat`, including metrics. Note that this plugin may have cross-platform issues.
http://sensu-plugins.io
MIT License
15 stars 50 forks source link

check-swap-percent.rb fails on FreeBSD #43

Open inferiorhumanorgans opened 8 years ago

inferiorhumanorgans commented 8 years ago
/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-memory-checks-1.0.2/bin/check-swap-percent.rb:6:in `exec': No such file or directory - /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-memory-checks-1.0.2/bin/check-swap-percent.sh (Errno::ENOENT)
    from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-memory-checks-1.0.2/bin/check-swap-percent.rb:6:in `<main>'
majormoses commented 7 years ago

@inferiorhumanorgans I see that we rewrote that check anyways, can you test it against master?

majormoses commented 7 years ago

might be fixed with just a release which has been requested in #54

eheydrick commented 7 years ago

2.0.0 has the rewritten swap check. Can you try that and feel free to reopen if still a problem.

inferiorhumanorgans commented 7 years ago

Well free(1) is Linux only, so I can't imagine it works.

majormoses commented 7 years ago

@inferiorhumanorgans correct sorry I didnt look inside to see that it was simply shelling out for free to get that, we should look into a cross platform way to do this.

majormoses commented 7 years ago

@eheydrick please repopen

inferiorhumanorgans commented 7 years ago

This might be a good way to go:

https://github.com/threez/ruby-vmstat

majormoses commented 7 years ago

@inferiorhumanorgans I used that one for cross platform ram checking, looks like there was some stuff just merged using /proc/meminfo assuming you have that on your *nix system if I get some time next week to take a look at it I will.

inferiorhumanorgans commented 7 years ago

procfs is pretty much always guaranteed to be platform dependent.

majormoses commented 7 years ago

@inferiorhumanorgans can you check out #57 and see if that works for you? Its certainly rough around the edges but wanted to see if I could just get something working for you.

inferiorhumanorgans commented 7 years ago
$ uname -sr
FreeBSD 10.3-RELEASE-p11
$ file /proc/swaps
/proc/swaps: cannot open `/proc/swaps' (No such file or directory)
$ uname -sr
Darwin 13.4.0
$ file /proc/swaps
/proc/swaps: cannot open `/proc/swaps' (No such file or directory)

I'd suggest using an existing abstraction layer. Procfs is inherently operating system dependent and rarely (if ever) considered cross-platform. ruby-vmstat that I linked to above is MIT licensed and claims explicit support for:

majormoses commented 7 years ago

@inferiorhumanorgans sorry I misread your initial comment. Agreed, however I checked and the vmstat did not look like it had swap support unless I am missing something.

inferiorhumanorgans commented 7 years ago

Ah, true. However, the same problems apply to the other memory checks in this repo as it looks like they rely on free(1).

majormoses commented 7 years ago

I did find this: https://github.com/djberg96/sys-filesystem that does work except that it does not detect swap so if we can detect all the swap paths/devices then we could use that. I will dig more when I have some more free time.

majormoses commented 7 years ago

@inferiorhumanorgans check-ram uses vmstat gem and does not rely on free but yes I totally agree and would love to invest time when I have it if I can find a reasonable path.

inferiorhumanorgans commented 7 years ago

Yeah, I'd go for some/more coverage especially as the vmstat gem is already being used here and checking swap info is well within scope per their readme.

majormoses commented 7 years ago

yup it looks like its on the todo list