Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails with exception if disk temperature is N/A #2

Open
gerdriesselmann opened this issue Nov 19, 2020 · 2 comments
Open

Fails with exception if disk temperature is N/A #2

gerdriesselmann opened this issue Nov 19, 2020 · 2 comments

Comments

@gerdriesselmann
Copy link

For really really broken disks, the temperature may not be read, and therefore is set to N/A.

In this case, trying to read the Fahrenheit values fails with exception

Traceback (most recent call last):
  File "megacli.py", line 309, in <module>
    main()
  File "megacli.py", line 298, in main
    exec(a)
  File "<string>", line 1, in <module>
IndexError: list index out of range

The input data that leads to this exception is:

line: Drive Temperature : N/A
a: out["megacli_pd_temperature"]["metrics"].append({ "labels": { "adapter": adapter, "enclosure": enclosure, "slot": slot, "type": "barbarians" }, "val": line.split("(")[1].split(" ")[0].strip() })

Since the input does not contain an opening bracket, the splitting does not create an array with at least two elements, so accessing index 1 fails.

@gerdriesselmann
Copy link
Author

Additionally, passing N/A to Prometheus leads to a syntax error on Prometheus side, since it expects only numbers.

I changed the output logic to:

  for k,v in out.iteritems():
    print("# HELP " + k + " " + v['help'])
    print("# TYPE " + k + " " + v['type'])
    for m in v['metrics']:
      clean = str(m['val'])
      if clean.replace('.','',1).isdigit() == False:
        clean = '0'
      print ( str(k) + '{' + ', '.join([ "{}=\"{}\"".format(str(l),str(m['labels'][l])) for l in sorted(m['labels']) ]) + '} ' + clean )

This converts non-numeric values to 0.

@hacklschorsch
Copy link

The OpenMetrics spec sounds like in that case [...] simply do not include this Metric.

hacklschorsch added a commit to PrivateStorageio/megacli2prom that referenced this issue Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants