Skip to content

Instantly share code, notes, and snippets.

@reikoNeko
Created November 25, 2017 19:09
Show Gist options
  • Save reikoNeko/6a0600b3769d21a55cf2321f2a76651a to your computer and use it in GitHub Desktop.
Save reikoNeko/6a0600b3769d21a55cf2321f2a76651a to your computer and use it in GitHub Desktop.
Flexible icinga DB performace data
def build_dict(seq, key):
return dict((d[key], dict(d)) for (_, d) in enumerate(seq))
i2stat = build_dict(raw["results"], 'name')
rate = {'IdoMysqlConnection': "idomysqlconnection_ido-mysql_queries_1min",
'IdoPgsqlConnection': "idomysqlconnection_ido-pgsql_queries_1min"}
print( set(i2stat.keys()) )
activedb = list( set(rate.keys()).intersection(set(i2stat.keys())) )[0]
print(activedb)
db_performance = build_dict(i2stat[activedb]['perfdata'], 'label')
print(db_performance[rate[activedb]]['value'])
'''
This also works but it's less friendly.
[ x['value'] for x in i2stat[activedb]['perfdata'] if x['label'].endswith("1min")][0]
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment