-
Notifications
You must be signed in to change notification settings - Fork 0
Telemetry
Send telemetry events to Cronitor.
internal class Program
{
private static async Task Main(string[] args)
{
await Host.CreateDefaultBuilder()
.UseCronitor((context) => context.Configuration.GetValue<string>("Cronitor:ApiKey"))
.Build()
.RunAsync();
}
}
public class SomeClass
{
private readonly TelemetryClient _client;
public SomeClass()
{
_client = new TelemetryClient("apiKey");
}
public void SomeMethod()
{
# Begin / ping a monitor
_client.Run("monitorKey");
# Begin / ping a monitor asynchronous
await _client.RunAsync("monitorKey");
# Complete a monitor
_client.Complete("monitorKey");
# Complete a monitor asynchronous
await _client.CompleteAsync("monitorKey");
# Complete a monitor
_client.Fail("monitorKey");
# Complete a monitor asynchronous
await _client.FailAsync("monitorKey");
# Tick a monitor
_client.Tick("monitorKey");
# Tick a monitor asynchronous
await _client.TickAsync("monitorKey");
}
}
Each
Command
-method inTelemetryClient
can be sent with a message.
public class SomeClass
{
private readonly TelemetryClient _client;
public SomeClass()
{
_client = new TelemetryClient("apiKey");
}
public void SomeMethod()
{
# Begin / ping a monitor
_client.Run("monitorKey", "message");
# Begin / ping a monitor asynchronous
await _client.RunAsync("monitorKey", "message");
# Complete a monitor
_client.Complete("monitorKey", "message");
# Complete a monitor asynchronous
await _client.CompleteAsync("monitorKey", "message");
# Complete a monitor
_client.Fail("monitorKey", "message");
# Complete a monitor asynchronous
await _client.FailAsync("monitorKey", "message");
# Tick a monitor
_client.Tick("monitorKey", "message");
# Tick a monitor asynchronous
await _client.TickAsync("monitorKey", "message");
}
}
You can choose to use
Ping
and/orPingAsync
to send aCommand
(CompleteCommand
,FailCommand
,RunCommand
andTickCommand
) with extended properties! To find more about telemetry event enrichers please read the documentation!
The Cronitor API uses API keys to authenticate requests. Your API keys can be found on your account settings page.
A monitor’s unique identifier. The key is used in making API requests to an individual monitor resource.
The environment the telemetry event is being sent from. Use this for monitors that are running in multiple environments (e.g. staging and production). Alerting can be configured per environment.
The hostname of the server sending the telemetry event.
A url-encoded message of up to 2000 characters.
Performance related metrics. Must be one of:
Metric.Count
(count:*
) - record counts of important events.Metric.Duration
(duration:*
) - the duration of the job/task being monitored.Metric.Errors
(error_count:*
) - the number of errors that occurred.
A unique user-supplied ID to collate related pings, i.e. matching state=run and state=complete|fail to one another. If a job is pinging very frequently (every 2-3s or faster), it will greatly improve matching accurracy.
Exit code returned from a background job.
var command = new CompleteCommand()
.WithApiKey("apiKey")
.WithMonitorKey("monitorKey")
.WithEnvironment("Production")
.WithHost("127.0.0.1")
.WithMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
.WithMetric(Metric.Count, new decimal(99.99))
.WithSeries("3de5db91-9c02-4e95-b8a9-9a2442702336")
.WithStatus(0);
# Ping a monitor
_client.Ping(command);
# Ping a monitor asynchronous
await _client.PingAsync(command);