Skip to content

Commit

Permalink
Append the aggregate mode to aggregate gauge descriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bretcope committed Mar 10, 2015
1 parent 7280b73 commit 8d9f59c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions BosunReporter/Metrics/AggregateGauge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,57 @@ public void Record(double value)
}
}

public override string GetDescription(string suffix)
{
if (!String.IsNullOrEmpty(Description))
{
var aggregator = _aggregatorStrategy.Aggregators.First(a => a.Suffix == suffix);

switch (aggregator.AggregateMode)
{
case AggregateMode.Last:
return Description + " (last)";
case AggregateMode.Average:
return Description + " (average)";
case AggregateMode.Max:
return Description + " (maximum)";
case AggregateMode.Min:
return Description + " (minimum)";
case AggregateMode.Median:
return Description + " (median)";
case AggregateMode.Percentile:
return Description + " (" + DoubleToPercentileString(aggregator.Percentile) + ")";
}
}

return Description;
}

private static string DoubleToPercentileString(double pct)
{
var ip = (int)(pct * 100.0);
var lastDigit = ip % 10;

string ending;
switch (lastDigit)
{
case 1:
ending = "st";
break;
case 2:
ending = "nd";
break;
case 3:
ending = "rd";
break;
default:
ending = "th";
break;
}

return ip + ending + " percentile";
}

protected override IEnumerable<string> Serialize(string unixTimestamp)
{
var snapshot = GetSnapshot();
Expand Down

0 comments on commit 8d9f59c

Please sign in to comment.