aboutsummaryrefslogtreecommitdiff
path: root/text_collector_examples
diff options
context:
space:
mode:
authorBrian Candler <b.candler@pobox.com>2019-06-03 10:46:02 +0100
committerBen Kochie <superq@gmail.com>2019-06-03 11:46:02 +0200
commitb3429e4a974f362af007e23cb9a539cecc024d45 (patch)
tree9158b7ad51ff0afdc402637576a541d55fb7cf03 /text_collector_examples
parent4a15edf0b6e9f6e4efe7aeea1ae62215cd01fe6f (diff)
downloadprometheus_node_collector-b3429e4a974f362af007e23cb9a539cecc024d45.tar.bz2
prometheus_node_collector-b3429e4a974f362af007e23cb9a539cecc024d45.tar.xz
prometheus_node_collector-b3429e4a974f362af007e23cb9a539cecc024d45.zip
Make storcli.py compatible with python2 (#1365)
This is only a minor change to .format() arguments, and is useful on CentOS6 servers which have only python2. Signed-off-by: Brian Candler <b.candler@pobox.com>
Diffstat (limited to 'text_collector_examples')
-rwxr-xr-xtext_collector_examples/storcli.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/text_collector_examples/storcli.py b/text_collector_examples/storcli.py
index 6d1d033..26f4bbd 100755
--- a/text_collector_examples/storcli.py
+++ b/text_collector_examples/storcli.py
@@ -113,9 +113,9 @@ def handle_megaraid_controller(response):
113 if vd_position: 113 if vd_position:
114 drive_group = vd_position.split('/')[0] 114 drive_group = vd_position.split('/')[0]
115 volume_group = vd_position.split('/')[1] 115 volume_group = vd_position.split('/')[1]
116 vd_baselabel = 'controller="{}",DG="{}",VG="{}"'.format(controller_index, drive_group, 116 vd_baselabel = 'controller="{0}",DG="{1}",VG="{2}"'.format(controller_index, drive_group,
117 volume_group) 117 volume_group)
118 vd_info_label = vd_baselabel + ',name="{}",cache="{}",type="{}",state="{}"'.format( 118 vd_info_label = vd_baselabel + ',name="{0}",cache="{1}",type="{2}",state="{3}"'.format(
119 str(virtual_drive.get('Name')).strip(), 119 str(virtual_drive.get('Name')).strip(),
120 str(virtual_drive.get('Cache')).strip(), 120 str(virtual_drive.get('Cache')).strip(),
121 str(virtual_drive.get('TYPE')).strip(), 121 str(virtual_drive.get('TYPE')).strip(),
@@ -131,9 +131,9 @@ def handle_megaraid_controller(response):
131 131
132def get_basic_controller_info(response): 132def get_basic_controller_info(response):
133 controller_index = response['Basics']['Controller'] 133 controller_index = response['Basics']['Controller']
134 baselabel = 'controller="{}"'.format(controller_index) 134 baselabel = 'controller="{0}"'.format(controller_index)
135 135
136 controller_info_label = baselabel + ',model="{}",serial="{}",fwversion="{}"'.format( 136 controller_info_label = baselabel + ',model="{0}",serial="{1}",fwversion="{2}"'.format(
137 str(response['Basics']['Model']).strip(), 137 str(response['Basics']['Model']).strip(),
138 str(response['Basics']['Serial Number']).strip(), 138 str(response['Basics']['Serial Number']).strip(),
139 str(response['Version']['Firmware Version']).strip(), 139 str(response['Version']['Firmware Version']).strip(),
@@ -147,10 +147,10 @@ def create_metrcis_of_physical_drive(physical_drive, detailed_info_array, contro
147 enclosure = physical_drive.get('EID:Slt').split(':')[0] 147 enclosure = physical_drive.get('EID:Slt').split(':')[0]
148 slot = physical_drive.get('EID:Slt').split(':')[1] 148 slot = physical_drive.get('EID:Slt').split(':')[1]
149 149
150 pd_baselabel = 'controller="{}",enclosure="{}",slot="{}"'.format(controller_index, enclosure, 150 pd_baselabel = 'controller="{0}",enclosure="{1}",slot="{2}"'.format(controller_index, enclosure,
151 slot) 151 slot)
152 pd_info_label = pd_baselabel + \ 152 pd_info_label = pd_baselabel + \
153 ',disk_id="{}",interface="{}",media="{}",model="{}",DG="{}",state="{}"'.format( 153 ',disk_id="{0}",interface="{1}",media="{2}",model="{3}",DG="{4}",state="{5}"'.format(
154 str(physical_drive.get('DID')).strip(), 154 str(physical_drive.get('DID')).strip(),
155 str(physical_drive.get('Intf')).strip(), 155 str(physical_drive.get('Intf')).strip(),
156 str(physical_drive.get('Med')).strip(), 156 str(physical_drive.get('Med')).strip(),
@@ -179,7 +179,7 @@ def create_metrcis_of_physical_drive(physical_drive, detailed_info_array, contro
179 add_metric('pd_commissioned_spare', pd_baselabel, 179 add_metric('pd_commissioned_spare', pd_baselabel,
180 int(settings['Commissioned Spare'] == 'Yes')) 180 int(settings['Commissioned Spare'] == 'Yes'))
181 add_metric('pd_emergency_spare', pd_baselabel, int(settings['Emergency Spare'] == 'Yes')) 181 add_metric('pd_emergency_spare', pd_baselabel, int(settings['Emergency Spare'] == 'Yes'))
182 pd_info_label += ',firmware="{}"'.format(attributes['Firmware Revision'].strip()) 182 pd_info_label += ',firmware="{0}"'.format(attributes['Firmware Revision'].strip())
183 except KeyError: 183 except KeyError:
184 pass 184 pass
185 add_metric('pd_info', pd_info_label, 1) 185 add_metric('pd_info', pd_info_label, 1)
@@ -198,11 +198,11 @@ def add_metric(name, labels, value):
198 198
199def print_all_metrics(metrics): 199def print_all_metrics(metrics):
200 for metric, measurements in metrics.items(): 200 for metric, measurements in metrics.items():
201 print('# HELP {}{} MegaRAID {}'.format(metric_prefix, metric, metric.replace('_', ' '))) 201 print('# HELP {0}{1} MegaRAID {2}'.format(metric_prefix, metric, metric.replace('_', ' ')))
202 print('# TYPE {}{} gauge'.format(metric_prefix, metric)) 202 print('# TYPE {0}{1} gauge'.format(metric_prefix, metric))
203 for measurement in measurements: 203 for measurement in measurements:
204 if measurement['value'] != 'Unknown': 204 if measurement['value'] != 'Unknown':
205 print('{}{}{} {}'.format(metric_prefix, metric, '{' + measurement['labels'] + '}', 205 print('{0}{1}{2} {3}'.format(metric_prefix, metric, '{' + measurement['labels'] + '}',
206 measurement['value'])) 206 measurement['value']))
207 207
208 208
@@ -227,7 +227,7 @@ if __name__ == "__main__":
227 description=DESCRIPTION, formatter_class=argparse.ArgumentDefaultsHelpFormatter) 227 description=DESCRIPTION, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
228 PARSER.add_argument( 228 PARSER.add_argument(
229 '--storcli_path', default='/opt/MegaRAID/storcli/storcli64', help='path to StorCLi binary') 229 '--storcli_path', default='/opt/MegaRAID/storcli/storcli64', help='path to StorCLi binary')
230 PARSER.add_argument('--version', action='version', version='%(prog)s {}'.format(VERSION)) 230 PARSER.add_argument('--version', action='version', version='%(prog)s {0}'.format(VERSION))
231 ARGS = PARSER.parse_args() 231 ARGS = PARSER.parse_args()
232 232
233 main(ARGS) 233 main(ARGS)