in src/Core/Exporters/Concrete/BaseExporter.cs [57:102]
public async Task ExportMetricsAsync(string endpointUrlSuffix = null)
{
// Getting the full endpoint URL
var fullEndpointUrl = GetFullEndpointUrl(endpointUrlSuffix);
// Invoking the request and sending metrics
var content = string.Empty;
var stopWatch = Stopwatch.StartNew();
var successfullRun = 1;
try
{
using (Logger.BeginScope(new Dictionary<string, object>() { { "Exporter", GetType().Name } }))
{
Logger.LogInformation($"{nameof(ExportMetricsAsync)} Started.");
content = await ContentProvider.GetResponseContentAsync(fullEndpointUrl);
var component = JsonConvert.DeserializeObject(content, ComponentType);
await ReportMetrics(component);
}
}
catch (Exception e)
{
successfullRun = 0;
Logger.LogError(e, $"{GetType().Name}.{nameof(ExportMetricsAsync)}: Failed to export metrics. Labels: {BaseConfiguration.DefaultLabels}, Content length: {content.Length}");
throw;
}
finally
{
stopWatch.Stop();
Logger.LogInformation($"{GetType().Name}.{nameof(ExportMetricsAsync)} ran for: {stopWatch.Elapsed}.");
PrometheusUtils.ReportGauge(
Collectors,
"exporter_is_successful_scrape",
successfullRun,
_exporterMetricsLabels,
"Indication to if the last scrape was successful");
}
// Sending scrape time only on successful operations
PrometheusUtils.ReportGauge(
Collectors,
"exporter_scrape_time_seconds",
stopWatch.ElapsedMilliseconds / 1000.0,
_exporterMetricsLabels,
"Total scraping time of a specific exporter component");
}