-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvme_stat.py
executable file
·51 lines (33 loc) · 979 Bytes
/
nvme_stat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
"""nvme_stat
Usage:
nvme_stat (-h | --help)
nvme_stat get [--dev=<devices>]
Options:
-h --help Show help
--dev=<devices> List of comma separated nvme devices to gather stats from [default: all]
""" # noqa: E501
from docopt import docopt
import os
import logging
import sys
from ns_utils import data
def setup_logging():
level = os.getenv("NVM_STAT_LOG", logging.INFO)
logging.basicConfig(level=level)
def main():
args = docopt(__doc__)
setup_logging()
if args["get"]:
dev_list = [dev.strip() for dev in args["--dev"].split(',')]
collector = data.NVMStats(dev_list)
if not len(collector.get_devices()):
logging.error("No nvme devices detected, exiting")
collector.gather_all_dev_stats()
collector.print_stats()
if __name__ == "__main__":
try:
main()
except RuntimeError as e:
logging.error(e)
sys.exit(1)