Skip to content

Commit

Permalink
Merge pull request #9 from genesiscloud/feature/comments
Browse files Browse the repository at this point in the history
Added comments in the code
  • Loading branch information
matusnovak authored Feb 16, 2022
2 parents 85b8e1b + 2f02814 commit d09f40c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion smartprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@


def isDrive(s: str) -> bool:
"""
checks if the device string matches an expected disk device name
"""
return re.match('^/dev/(sd[a-z]+|nvme[0-9]+)$', s)


def run(args: [str]):
# print('Running: {}'.format(' '.join(args)))
"""
runs the smartctl command on the system
"""
out = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout, stderr = out.communicate()
Expand Down Expand Up @@ -49,6 +54,10 @@ def get_types():


def smart_sat(dev: str) -> List[str]:
"""
Runs the smartctl command on a "sat" device
and processes its attributes
"""
results = run(['smartctl', '-A', '-d', 'sat', dev])
attributes = {}
got_header = False
Expand Down Expand Up @@ -76,6 +85,10 @@ def smart_sat(dev: str) -> List[str]:


def smart_nvme(dev: str) -> List[str]:
"""
Runs the smartctl command on a "nvme" device
and processes its attributes
"""
results = run(['smartctl', '-A', '-d', 'nvme', '--json=c', dev])
attributes = {}

Expand Down Expand Up @@ -109,6 +122,9 @@ def smart_scsi(dev: str) -> List[str]:


def collect():
"""
Collect all drive metrics and save them as Gauge type
"""
global METRICS
global TYPES

Expand Down Expand Up @@ -153,6 +169,9 @@ def collect():


def main():
"""
starts a server at port 9902 and exposes the metrics
"""
start_http_server(9902)
collect()

Expand Down

0 comments on commit d09f40c

Please sign in to comment.