Skip to content

Instantly share code, notes, and snippets.

@ksingh7
Created August 17, 2016 21:22
Show Gist options
  • Save ksingh7/1919f65687c68c88af1fa9a7923e6ba9 to your computer and use it in GitHub Desktop.
Save ksingh7/1919f65687c68c88af1fa9a7923e6ba9 to your computer and use it in GitHub Desktop.
string-to-int
def get_stats(self):
"""Retrieves stats from ceph mons"""
#ceph_cluster = "%s-%s" % (self.prefix, self.cluster)
ceph_cluster = 'ceph'
data = { ceph_cluster: { 'cluster': { 'slow_rq': 0 } } }
output = None
try:
output = subprocess.check_output('./slow-request.sh', shell=True)
except Exception as exc:
collectd.error("Slow Request Plugin: Error in slow_request.sh :: %s :: %s" % (exc, traceback.format_exc()))
return
t = output[:-1]
result = int(t)
data[ceph_cluster]['cluster']['slow_rq'] = result
return data
==========================
[2016-08-18 00:14:09] [error] ceph: failed to get stats :: invalid literal for int() with base 10: '' :: Traceback (most recent call last):
File "/etc/collectd/collectd-ceph-slow-requests/base.py", line 114, in read_callback
stats = self.get_stats()
File "/etc/collectd/collectd-ceph-slow-requests/ceph-slow-request.py", line 32, in get_stats
result = int(t)
ValueError: invalid literal for int() with base 10: ''
============================
WORKS
-----
#!/usr/bin/python
import subprocess
output = subprocess.check_output('./slow-request.sh', shell=True)
y = output[:-1]
print type(y)
print y
z = int(y)
print type(z)
print z
=======================
[root@ceph-mon1 collectd-ceph-slow-requests]# python string-int.py
<type 'str'>
253
<type 'int'>
253
[root@ceph-mon
========================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment