pimoroni / fanshim-python

Python library for the Fan SHIM for Raspberry Pi
https://shop.pimoroni.com/products/fan-shim
MIT License
295 stars 85 forks source link

Added basic fan status logging #65

Open FlorentLM opened 4 years ago

FlorentLM commented 4 years ago

Added basic fan status logging for use with external metrics collectors.

Example for Telegraf:

[[inputs.file]]
  files = ["/var/log/fanshim_status"]
  name_override = "fanshim_status"
  data_format = "value"
  data_type = "integer"
Gadgetoid commented 4 years ago

Thanks for taking the time to PR this.

It seems like a worthwhile addition, but should probably be paired with a new argument that disables logging by default and allows users to enable it. Something like:

parser.add_argument('--logging', action='store_true', help='Enable logging')

Additionally it could be worth using Python's logging module so log entries are implicitly timestamped, see: https://docs.python.org/3/library/logging.html

A complete implementation, I think, would use logging coupled with a configurable logging-level so that perhaps warnings are generated for fan on/off events and info messages are generated containing the info currently output when args.verbose is set.

If you're up for turning this PR into a more concerted learning effort (I'm making assumptions - based on this being your first PR - that Python might be new to you!) then I'm happy to guide you through these changes.

FlorentLM commented 4 years ago

Sure, these are good points! This was initially very basic, as for my own purpose I really only needed to know when the fan was on or off for Telegram, I tried to add as little code as possible. But your ideas are definitely needed for a more public implementation, yes.

I'm totally up for improving this PR, I'll do that as soon as I have some time.

PS - no worries, Python is not new to me, it'll be fine :) But thanks!