How to measure the rate of availability

for datasource of elasticsearch, I have two queries, A is the total requests, B is the requests of 4xx.
now I want to measure the rate of availability and setup alert.
There is no any function to get the result.

You can add 3rd Metaqueries and do calculation. for instance below will show 100 % in gauge as well as graph.
Type : Arithmetic
B[‘totalrequests’] / K[‘requests’] * 100