Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion NewRelic.Platform.Sdk/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public void SetupAndRun()

var pollInterval = GetPollInterval(); // Fetch poll interval here so we can report any issues early

// Currently the graphs in New Relic will appear to drop to zero if a metric is sent less than once a minute
// and not sent close to the beginning of the minute, so bias towards starting at the beginning of the minute
DateTime previousMetricTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);

while (true)
{
// Invoke each Agent's PollCycle method, logging any exceptions that occur
Expand All @@ -120,7 +124,12 @@ public void SetupAndRun()
return;
}

Thread.Sleep(pollInterval);
DateTime currentMetricSendTime = DateTime.Now;
int millisecondsToNextInterval = pollInterval - (GetTimeSincePreviousMetric(currentMetricSendTime, previousMetricTime) % pollInterval);

Thread.Sleep(millisecondsToNextInterval);

previousMetricTime = currentMetricSendTime;
}
catch (Exception e)
{
Expand Down Expand Up @@ -179,6 +188,11 @@ private int GetPollInterval()
return pollInterval *= 1000; // Convert to milliseconds since that's what system calls expect;
}

private int GetTimeSincePreviousMetric(DateTime currentMetricSendTime, DateTime previousMetricTime)
{
return (int)(currentMetricSendTime - previousMetricTime).TotalMilliseconds;
}

#region Test Helpers

/// <summary>
Expand Down