print raw db data

This commit is contained in:
Cyberes 2023-04-21 23:54:17 -06:00
parent 57dda6121b
commit 7d42eb0e5b
2 changed files with 8 additions and 7 deletions

View File

@ -106,8 +106,8 @@ def main():
elif args.type == 'db-lag':
db_lag_MAX = 0.01 if not args.crit else args.crit # in seconds
try:
db_lag, null_present = get_waiting_for_db(args.grafana_api_key, args.interval, args.range, args.grafana_server)
null_warn = 'Null data was present for this timeseries.' if null_present else ''
db_lag, null_present, raw_data = get_waiting_for_db(args.grafana_api_key, args.interval, args.range, args.grafana_server)
null_warn = f'Null data was present for this timeseries.\n{raw_data}' if null_present else ''
if db_lag > db_lag_MAX:
print(f"CRITICAL: DB lag is {db_lag} sec. {null_warn} |'db-lag'={db_lag}s;;;")
sys.exit(nagios.CRITICAL)

View File

@ -310,13 +310,14 @@ def get_waiting_for_db(api_key, interval, data_range, endpoint):
'to': 'now',
}
response = requests.post(f'{endpoint}/api/ds/query', headers={'Authorization': f'Bearer {api_key}'}, json=json_data, verify=False).json()
data = response['results']['A']['frames'][0]['data']['values'][1]
raw_data = response['results']['A']['frames'][0]['data']['values'][1]
data = []
null_present = False
for i in range(len(data)):
if data[i] is None:
data[i] = -1
for i in range(len(raw_data)):
if raw_data[i] is not None:
data.append(raw_data[i])
null_present = True
return np.round(np.average(data), 5), null_present
return np.round(np.average(data), 5), null_present, raw_data
def get_stateres_worst_case(api_key, interval, data_range, endpoint):