Skip to content

Commit

Permalink
Add option for enable/disable external counters
Browse files Browse the repository at this point in the history
  • Loading branch information
bretcope committed May 11, 2016
1 parent 7a246d1 commit e51b74d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions BosunReporter/BosunOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ public class BosunOptions
/// Default tags will generally not be included in metadata.
/// </summary>
public Dictionary<string, string> DefaultTags;
/// <summary>
/// Enables sending metrics to the /api/count route on OpenTSDB relays which support external counters. External
/// counters don't reset when applications reload, and are intended for low-volume metrics. For high-volume metrics,
/// use normal counters.
/// </summary>
public bool EnableExternalCounters = true;
}
}
9 changes: 9 additions & 0 deletions BosunReporter/Infrastructure/PayloadQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ internal MetricWriter GetWriter()
return new MetricWriter(this);
}

internal void Clear()
{
Payload p;
while ((p = DequeuePendingPayload()) != null)
{
ReleasePayload(p);
}
}

internal Payload DequeuePendingPayload()
{
lock (_pendingLock)
Expand Down
8 changes: 7 additions & 1 deletion BosunReporter/MetricsCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private class RootMetricInfo
public bool ThrowOnPostFail { get; set; }
public bool ThrowOnQueueFull { get; set; }
public int ReportingInterval { get; }
public bool EnableExternalCounters { get; set; }
public Func<string, string> PropertyToTagName { get; }
public TagValueConverterDelegate TagValueConverter { get; }
public ReadOnlyDictionary<string, string> DefaultTags { get; private set; }
Expand Down Expand Up @@ -141,6 +142,7 @@ public MetricsCollector(BosunOptions options)
ThrowOnPostFail = options.ThrowOnPostFail;
ThrowOnQueueFull = options.ThrowOnQueueFull;
ReportingInterval = options.ReportingInterval;
EnableExternalCounters = options.EnableExternalCounters;
PropertyToTagName = options.PropertyToTagName;
TagValueConverter = options.TagValueConverter;
DefaultTags = ValidateDefaultTags(options.DefaultTags);
Expand Down Expand Up @@ -563,7 +565,11 @@ private void Flush(object isCalledFromTimer)
{
any = false;
any |= FlushPayload("/api/put", _localMetricsQueue);
any |= FlushPayload("/api/count", _externalCounterQueue);

if (EnableExternalCounters)
any |= FlushPayload("/api/count", _externalCounterQueue);
else
_externalCounterQueue.Clear();

} while (any);
}
Expand Down

0 comments on commit e51b74d

Please sign in to comment.