From efdb5b2c9f4a9b3e7f424b154b22444855ac399a Mon Sep 17 00:00:00 2001 From: erikruggles Date: Mon, 11 Oct 2021 13:28:59 -0500 Subject: [PATCH] Multiply Hit Rate by 100 to calculate expected percentage value (#28) * Prevent divide by zero error When there were no hits or misses against a node, the result being returned was NaN as a result of a divide by zero issue. This approach converts the NaN result to a zero. * Multiply Hit Rate ratio by 100 to calculate percentage The Hit Rate metric unit is Percent but we are sending a ratio. We need to multiply the ratio by 100 to get a percentage so monitoring rules and metrics make sense. Resolves #27 Co-authored-by: Erik Ruggles --- Program.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 4cb0895..42405c9 100644 --- a/Program.cs +++ b/Program.cs @@ -335,7 +335,16 @@ private static void Main(string[] args) channel = "Hit Rate", unit = PRTGUnit.Percent, Float=1, - value = SafeGetFloat(() => (Convert.ToDouble(statsInfo.SingleOrDefault(i => i.Key.Equals("keyspace_hits")).Value) / (Convert.ToDouble(statsInfo.SingleOrDefault(i => i.Key.Equals("keyspace_hits")).Value) + Convert.ToDouble(statsInfo.SingleOrDefault(i => i.Key.Equals("keyspace_misses")).Value))).ToString()) + value = SafeGetFloat(() => + ( + 100.0 * + Convert.ToDouble(statsInfo.SingleOrDefault(i => i.Key.Equals("keyspace_hits")).Value) / + ( + Convert.ToDouble(statsInfo.SingleOrDefault(i => i.Key.Equals("keyspace_hits")).Value) + + Convert.ToDouble(statsInfo.SingleOrDefault(i => i.Key.Equals("keyspace_misses")).Value) + ) + ).ToString() + ) } }, {