diff --git a/README.md b/README.md index 2575334d99df748763b009b28767443d2fdd132c..6a37c666f42252aa7b7179351fcffe03d3a74b25 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ to extend to other fan types (I just don't have one to test). If you'd like a Debian package: ``` -% baze build :main-deb +% bazel build :main-deb ``` ### Without Bazel @@ -20,10 +20,12 @@ If you'd like a Debian package: You'll need these dependencies: ``` -pip install libpurecool -pip install prometheus_client +% pip install libpurecool +% pip install prometheus_client ``` +Consider installing in a [Python virtual environment](https://docs.python.org/3/tutorial/venv.html). + ## Metrics ### Environmental @@ -63,9 +65,13 @@ for your DysonLink login credentials. usage: ./prometheus_dyson.py [-h] [--port PORT] [--config CONFIG] optional arguments: - -h, --help show this help message and exit - --port PORT HTTP server port - --config CONFIG Configuration file (INI file) + -h, --help show this help message and exit + --port PORT HTTP server port + --config CONFIG Configuration file (INI file) + --log_level LOG_LEVEL + Logging level (DEBUG, INFO, WARNING, ERROR) + --include_inactive_devices + Only monitor devices marked as "active" in the Dyson API ``` ### Scrape Frequency diff --git a/main.py b/main.py index 1491f9d4e45a1dd2ce73c71b8012b18469c36e3c..2909f49c1d067eded02acb7cf0d8b08cd02eb1ed 100755 --- a/main.py +++ b/main.py @@ -198,15 +198,30 @@ def main(argv): parser = argparse.ArgumentParser(prog=argv[0]) parser.add_argument('--port', help='HTTP server port', type=int, default=8091) parser.add_argument('--config', help='Configuration file (INI file)', default='config.ini') + parser.add_argument('--log_level', help='Logging level (DEBUG, INFO, WARNING, ERROR)', type=str, default='INFO') + parser.add_argument( + '--include_inactive_devices', + help='Only monitor devices marked as "active" in the Dyson API', + action='store_true') + args = parser.parse_args() + + try: + level = getattr(logging, args.log_level) + except AttributeError: + print(f'Invalid --log_level: {args.log_level}') + exit(-1) args = parser.parse_args() logging.basicConfig( format='%(asctime)s %(levelname)10s %(message)s', datefmt='%Y/%m/%d %H:%M:%S', - level=logging.INFO) + level=level) logging.info('Starting up on port=%s', args.port) + if args.include_inactive_devices: + logging.info('Including devices marked "inactive" from the Dyson API') + credentials = _read_config(args.config) if not credentials: exit(-1) @@ -218,7 +233,7 @@ def main(argv): if not client.login(): exit(-1) - client.monitor(metrics.update) + client.monitor(metrics.update, only_active=not args.include_inactive_devices) _sleep_forever() if __name__ == '__main__':