Skip to content

Instantly share code, notes, and snippets.

@tomaustin700
Last active May 21, 2018 12:40
Show Gist options
  • Save tomaustin700/9c7e211e9227401b07aefd23380800ba to your computer and use it in GitHub Desktop.
Save tomaustin700/9c7e211e9227401b07aefd23380800ba to your computer and use it in GitHub Desktop.
MetricityOverview.cs
//Returns time taken for execution of synchronous code
var syncTime = Metricity.Timings.Time(() =>
{
SyncMethod();
});
//Returns time taken for execution of asynchronous code
var asyncTime = Metricity.Timings.Time(async () =>
{
await ASyncMethod();
});
//Returns current memory usage of application
var memoryUsage = Metricity.Diagnostics.GetMemoryUsage();
//Returns current cpu usage of application
var cpuUsage = Metricity.Diagnostics.GetCPUUsage();
//Returns difference in memory usage from before synchronous code execution and after
var memoryChangeSync = Metricity.Diagnostics.GetMemoryChange(() =>
{
SyncMethod();
});
//Returns difference in memory usage from before asynchronous code execution and after
var memoryChangeASync = Metricity.Diagnostics.GetMemoryChange(async () =>
{
await ASyncMethod();
});
//Logs time taken for execution of synchronous code to database
Metricity.RemoteLog.Log(() =>
{
SyncMethod();
});
//Logs time taken for execution of asynchronous code to database
await Metricity.RemoteLog.Log(async () =>
{
await ASyncMethod();
});
//Logs time taken for execution of synchronous code to cache, cache is then commited to database when CommitCache is called
Metricity.RemoteLog.CacheLog(() =>
{
SyncMethod();
});
//Logs time taken for execution of synchronous code to cache, cache is then commited to database when CommitCache is called
await Metricity.RemoteLog.CacheLog(async () =>
{
await ASyncMethod();
});
//Clears all metrics from the cache
Metricity.RemoteLog.ClearCache();
//Returns the current cache
var cache = Metricity.RemoteLog.GetCache();
//Commits cache to database
Metricity.RemoteLog.CommitCache();
//Increments the counter by one
Metricity.Counters.Increment("counter");
//Decrements the counter by one
Metricity.Counters.Decrement("counter");
//Returns the count of the specified counter
Metricity.Counters.GetCurrentCount("counter");
//Resets the specified counter
Metricity.Counters.ClearCounter("counter");
//Resets all counters
Metricity.Counters.PurgeCounters();
//Gets the percentage splits of subset counters
var splits = Metricity.Counters.GetSubsetSplit("counter");
//Handles exceptions of the type that are passed in and writes an entry into HandledExceptions Table
Metricity.Handlers.HandleException(() =>
{
ThrowException(new InvalidOperationException());
}, new List<Exception>() { new InvalidOperationException() });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment