Reputation: 642
Is there a way within a C# app using an Azure Nuget package to search Azure Telemetry data and get some sort of json result set back?
I have an ASP.NET Core 2.x administrative app and I want to view the last X Azure successful Azure webjob functions (see screenshot). I can't seem to find any info on how I might run this query in my application.
Upvotes: 1
Views: 493
Reputation: 698
I'm not aware of a Nuget package that encapsulates this, but App Insights has a REST API that they expose and they have an API Quickstart guide
The C# example is included below:
private const string URL =
"https://api.applicationinsights.io/v1/apps/{0}/{1}/{2}?{3}";
public static string GetTelemetry(string appid, string apikey,
string queryType, string queryPath, string parameterString)
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("x-api-key", apikey);
var req = string.Format(URL, appid, queryType, queryPath, parameterString);
HttpResponseMessage response = client.GetAsync(req).Result;
if (response.IsSuccessStatusCode)
{
return response.Content.ReadAsStringAsync().Result;
}
else
{
return response.ReasonPhrase;
}
}
...
var json = GetTelemetry
("DEMO_APP", "DEMO_KEY",
"metrics", "requests/duration", "interval=PT1H");
The example call at the bottom will return request duration aggregated per hour for the past 24 hours (default timeframe for the example route).
Creating the API keys can be done via the API Access menu, under the Configuration heading for each specific Application Insights instance:
Upvotes: 2