check_vllm: fix

This commit is contained in:
Cyberes 2023-09-20 15:26:43 -06:00
parent 45087f3299
commit e1fe37a175
1 changed files with 22 additions and 26 deletions

View File

@ -48,37 +48,33 @@ def main(critical, warning, timeout, target_url, does_not_contain, verify):
text_result = f"failed with status code {response.status_code}\n{response.text}"
exit_code = nagios.STATE_CRIT
else:
if not json_data.get('text'):
if not json_data.get('text') or not len(json_data['text']):
text_result = f"did not receive valid JSON\n{response.text}"
exit_code = nagios.STATE_CRIT
else:
if not len(json_data['text']):
text_result = f"did not receive valid JSON\n{response.text}"
tokenizer = tiktoken.get_encoding("cl100k_base")
num_tokens = len(tokenizer.encode(json_data['text'][0]))
perfdata.update({
'tokens': {
'value': num_tokens,
'min': 0,
}
})
if not len(json_data['text'][0]):
text_result = f"response was empty.\n{response.text}"
exit_code = nagios.STATE_CRIT
elif elapsed_time >= warning:
text_result = f"response was {elapsed_time} seconds"
exit_code = nagios.STATE_WARN
elif elapsed_time >= critical:
text_result = f"response was {elapsed_time} seconds"
exit_code = nagios.STATE_CRIT
elif does_not_contain and does_not_contain in json_data['text'][0]:
text_result = f"\"{does_not_contain}\" was in the response:\n{json_data['text'][0]}"
exit_code = nagios.STATE_CRIT
else:
tokenizer = tiktoken.get_encoding("cl100k_base")
num_tokens = len(tokenizer.encode(json_data['text'][0]))
perfdata.update({
'tokens': {
'value': num_tokens,
'min': 0,
}
})
if not len(json_data['text'][0]):
text_result = f"response was empty.\n{response.text}"
exit_code = nagios.STATE_CRIT
elif elapsed_time >= warning:
text_result = f"response was {elapsed_time} seconds"
exit_code = nagios.STATE_WARN
elif elapsed_time >= critical:
text_result = f"response was {elapsed_time} seconds"
exit_code = nagios.STATE_CRIT
elif does_not_contain and does_not_contain in json_data['text'][0]:
text_result = f"\"{does_not_contain}\" was in the response:\n{json_data['text'][0]}"
exit_code = nagios.STATE_CRIT
else:
text_result = f"generation time was {elapsed_time} seconds and generated {num_tokens} tokens"
exit_code = nagios.STATE_OK
text_result = f"generation time was {elapsed_time} seconds and generated {num_tokens} tokens"
exit_code = nagios.STATE_OK
else:
perfdata = {}
text_result = f"CRITICAL - request failed - {error.__class__.__name__}: {error}"