-
Notifications
You must be signed in to change notification settings - Fork 0
Monitor
Configure and-, modify monitors, and view monitor activity (telemetry events and alerts).
public class SomeClass
{
private readonly MonitorClient _client;
public SomeClass()
{
_client = new MonitorClient("apiKey");
}
public void SomeMethod()
{
# Find all monitors
_client.Find(int page = 1);
_client.Find(request);
await _client.FindAsync(int page = 1);
await _client.FindAsync(request);
# Get a monitor
_client.Get("key");
await _client.GetAsync("key");
# Create a monitor
_client.Create(request);
await _client.CreateAsync(request);
# Update a monitor
_client.Update(request);
await _client.UpdateAsync(request);
# Delete a monitor
_client.Delete("key");
await _client.DeleteAsync("key");
# Pause a monitor
_client.Pause("key");
await _client.PauseAsync("key");
_client.Pause("key", 24 /*hours*/);
await _client.PauseAsync("key", 24 /*hours*/);
# Unpause a monitor
_client.Unpause("key");
await _client.UnpauseAsync("key");
# Get activities for a monitor
_client.Activities("key");
await _client.ActivitiesAsync("key");
# Get alerts for a monitor
_client.Alerts("key");
await _client.AlertsAsync("key");
# Get pings for a monitor
_client.Pings("key");
await _client.PingsAsync("key");
}
}
Find will return a paged list of monitors
{
"version": "2020-10-01",
"monitors": [
{},
{}
],
"page": 1,
"total_monitor_count": 120,
"page_size": 50
}
When
"key"
is omitted fromnew Monitor()
the monitor will be created with an auto-generated key (6
characters) based on the charactersabcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ123456790
( e.g.VR7t6i
).
We provide three types of monitors:
Check
,Heartbeat
andJob
and this example usesJob
var monitor = new Job(MonitorKey)
{
Assertions = new List<string>
{
"metric.duration < 30s",
"metric.error_count < 5"
},
Notify = new List<string>
{
"developers",
"administrators"
},
Schedule = "every 60 minutes",
Timezone = "Europe/Stockholm"
};
var request = new CreateRequest(monitor);
_client.Create(request);
You can also run this method asynchronously
await _client.CreateAsync(request);
new Check(Request request);
new Check(string key, Request request);
To read more about the limitations and details about the request object please refer to https://cronitor.io/docs/monitor-api#request
var regions = new List<Region>
{
Region.Bahrain,
Region.California,
Region.Dublin,
Region.Frankfurt,
Region.Mumbai,
Region.Ohio,
Region.SaoPaulo,
Region.Singapore,
Region.Stockholm,
Region.Sydney,
Region.Virginia
}
var request = new Request(url, regions)
{
Body = "",
Cookies = "",
Headers = "",
Method = "GET",
TimeoutSeconds = 10
}
new Heartbeat(string schedule);
new Heartbeat(string key, string schedule);
new Job();
new Job(string key);
var monitor = new Monitor("key")
{
Assertions = new List<string>
{
"job.completes every 2 hours",
"metric.duration < 30min"
},
Timezone = "Europe/Stockholm"
};
var request = new UpdateRequest(monitor);
_client.Update(request);
You can also run this method asynchronously
await _client.UpdateAsync(request);
_client.Delete("key");
You can also run this method asynchronously
await _client.DeleteAsync(request);
_client.Pause("key");
_client.Pause("key", 24 /*hours*/);
_client.Unpause("key");
You can also run these methods asynchronously
await _client.PauseAsync("key");
await _client.PauseAsync("key", 24 /*hours*/);
await _client.UnpauseAsync("key");
For detailed documentation please read, https://cronitor.io/docs/activity-api#read-activity
_client.Activities("key");
You can also run this method asynchronously
await _client.ActivitiesAsync(request);
[
{
"created": "Fri, 17 Sep 2021, 00:56:38 CEST",
"from": "127.0.0.1",
"message": "",
"duration": 1236.421,
"monitor_name": "sql-server-backup-database",
"monitor_code": "aBcDef",
"stamp": "1631832998.360000",
"count": null,
"error_count": null,
"description": "ping",
"host": null,
"status": null,
"event": "complete"
}
]
For detailed documentation please read, https://cronitor.io/docs/activity-api#read-alert-history
_client.Alerts("key");
You can also run this method asynchronously
await _client.AlertsAsync(request);
We're removing the wrapper so you'll just get a list of alerts
{
"aBcDef": [
{
"monitor_name": "sql-server-backup-database",
"stamp": "1631487371.961000",
"message": "Received a complete event. The alert from 3 hours 54 minutes ago is resolved.",
"from": "-",
"monitor_code": "aBcDef",
"event": "recovered",
"description": "alert",
"created": "Mon, 13 Sep 2021, 00:56:11 CEST"
}
]
}
For detailed documentation please read, https://cronitor.io/docs/activity-api#read-ping-history
_client.Pings("key");
You can also run this method asynchronously
await _client.PingsAsync(request);
We're removing the wrapper so you'll just get a list of pings
{
"aBcDef": [
{
"monitor_name": "sql-server-backup-database",
"from": "127.0.0.1",
"event": "complete",
"monitor_code": "aBcDef",
"host": null,
"created": "Fri, 17 Sep 2021, 00:56:38 CEST",
"status": null,
"message": "",
"duration": 1236.421,
"description": "ping",
"stamp": "1631832998.360000",
"error_count": null,
"count": null
}
]
}