Skip to content

Commit

Permalink
Multiply Hit Rate by 100 to calculate expected percentage value (#28)
Browse files Browse the repository at this point in the history
* 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 <erikr@tempworks.com>
  • Loading branch information
erikruggles and erikr-tempworks authored Oct 11, 2021
1 parent 37dec51 commit efdb5b2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
},
{
Expand Down

0 comments on commit efdb5b2

Please sign in to comment.