brendanhay/statgrab — pull request #1 by adarqui (2014-10-31 16:13:36+00:00)
Title: Support for obtaining lists of results via snapshots

Hey Brendan,

I was going to contact you and ask how this could be done in the current library, but instead I figured i'd just try to implement it and then see if it makes sense. I learned alot in the process; this is the first time i have used the Haskell C FFI.

Basically, I have added modifications that will allow you to obtain a list of results by calling the "snapshots" function. For example, you can obtain a full process list via:

runStats $ (snapshots :: Stats [Process]) >>= liftIO . print

"snapshots" will work with any of the statgrab data types. If a function only returns one value, it will be contained within a list. So there's no danger in calling it against Stats [Host] for example.

Also, everything remains backward compatible with the existing library. "snapshot" works just as it did before. I tried to achieve this in what I figured to be the most elegant way possible. IMHO it came out somewhat decent, only minor changes were made across all of the Stat & Copy instances.

One thing you may not like is the fact that I made System.Statgrab.Internal available. This was done so that I (or others) could more easily marshall/unmarshall statgrab structures into json etc. For example, here is a separate library I wrote to do just that:

https://github.com/adarqui/DevUtils-Statgrab/blob/master/examples/ex1.hs
https://github.com/adarqui/DevUtils-Statgrab/blob/master/src/System/DevUtils/Statgrab.hs

If you would like to accept this pull request but need me to make some changes, please let me know. If not, that's cool too.

Thanks for writing this library. It's been extremely helpful.

-- Andrew