Skip to content

Instantly share code, notes, and snippets.

@ealsur
Created February 15, 2019 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ealsur/966c3d6fc1d865204332b739f749d885 to your computer and use it in GitHub Desktop.
Save ealsur/966c3d6fc1d865204332b739f749d885 to your computer and use it in GitHub Desktop.
Azure Cosmos DB + Functions Cookbook - monitoring
[FunctionName("Monitor")]
public static async Task Monitor(
[TimerTrigger("*/1 * * * * *", RunOnStartup = true)] TimerInfo timer, // Timer will trigger every 1 second, adjust CRON expression
[CosmosDB("%MonitoredDatabase%", "%MonitoredCollection%", ConnectionStringSetting = "CosmosDB")] DocumentClient monitoredCollectionClient,
[CosmosDB("%MonitoredDatabase%", "leases", ConnectionStringSetting = "CosmosDB")] DocumentClient leaseCollectionClient,
ILogger log)
{
var estimator = GetRemainingWorkEstimator(monitoredCollectionClient, leaseCollectionClient);
var remainingWork = await estimator.GetEstimatedRemainingWork();
// Send custom metric to App Insight
log.LogInformation(remainingWork.ToString());
log.LogMetric("RemainingWork", remainingWork);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment