Skip to content

Commit

Permalink
Provide scrapers for App Services (App Plan, Web App, Function) (#820)
Browse files Browse the repository at this point in the history
* Provide docs for new scrapers

* Provide app service scrapers

Signed-off-by: Tom Kerkhove <[email protected]>

* Support slots for Azure Function App

Signed-off-by: Tom Kerkhove <[email protected]>

* Provide better support for slots

Signed-off-by: Tom Kerkhove <[email protected]>
  • Loading branch information
tomkerkhove authored Jan 10, 2020
1 parent 95295b8 commit 1965793
Show file tree
Hide file tree
Showing 34 changed files with 1,146 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog/content/experimental/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ version:
---

- {{% tag added %}} Azure Virtual Machine Scale Set Scraper ([docs](https://promitor.io/configuration/v1.x/metrics/virtual-machine-scale-set) | [#310](https://github.com/tomkerkhove/promitor/issues/310))
- {{% tag added %}} Azure App Plan Scraper ([docs](https://promitor.io/configuration/v1.x/metrics/app-plan) | [#315](https://github.com/tomkerkhove/promitor/issues/315))
- {{% tag added %}} Azure Web App Scraper ([docs](https://promitor.io/configuration/v1.x/metrics/web-app) | [#762](https://github.com/tomkerkhove/promitor/issues/762))
- {{% tag added %}} Azure Function App Scraper ([docs](https://promitor.io/configuration/v1.x/metrics/function-app) | [#366](https://github.com/tomkerkhove/promitor/issues/366))
- {{% tag changed %}} Metric labels for dimensions are now always lower-cased
34 changes: 34 additions & 0 deletions docs/configuration/v1.x/metrics/app-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
layout: default
title: Azure App Plan Declaration
---

## Azure App Plan - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.2-green.svg)

You can declare to scrape an Azure App Plan via the `AppPlan` resource
type.

The following fields need to be provided:

- `appPlanName` - The name of the Azure App Plan

All supported metrics are documented in the official [Azure Monitor documentation](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftwebserverfarms).

Example:

```yaml
name: azure_app_plan_percentage_memory
description: "Average percentage of memory usage on an Azure App Plan"
resourceType: AppPlan
azureMetricConfiguration:
metricName: MemoryPercentage
aggregation:
type: Average
resources:
- appPlanName: promitor-app-plan
```
<!-- markdownlint-disable MD033 -->
[&larr; back to metrics declarations](/configuration/v1.x/metrics)<br />
[&larr; back to introduction](/)
<!-- markdownlint-enable -->
38 changes: 38 additions & 0 deletions docs/configuration/v1.x/metrics/function-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
layout: default
title: Azure Function App Declaration
---

## Azure Function App - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.2-green.svg)

You can declare to scrape an Azure Function App via the `FunctionApp` resource
type.

The following fields need to be provided:

- `functionAppName` - The name of the Azure Function App

All supported metrics are documented in the official [Azure Monitor documentation](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftwebsites-functions).

The following scraper-specific metric label will be added:

- `slot_name` - Name of the deployment slot. If none is specified, `production` will be used.

Example:

```yaml
name: azure_function_requests
description: "Amount of requests for an Azure Function App"
resourceType: FunctionApp
azureMetricConfiguration:
metricName: Requests
aggregation:
type: Total
resources:
- functionAppName: promitor-function-app
```
<!-- markdownlint-disable MD033 -->
[&larr; back to metrics declarations](/configuration/v1.x/metrics)<br />
[&larr; back to introduction](/)
<!-- markdownlint-enable -->
3 changes: 3 additions & 0 deletions docs/configuration/v1.x/metrics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,21 @@ service supported by Azure Monitor.
We also provide a simplified way to scrape the following Azure resources:
- [Azure App Plan](app-plan)
- [Azure Cache for Redis](redis-cache)
- [Azure Container Instances](container-instances)
- [Azure Container Registry](container-registry)
- [Azure Cosmos DB](cosmos-db)
- [Azure Database for PostgreSQL](postgresql)
- [Azure Function App](function-app)
- [Azure Network Interface](network-interface)
- [Azure Service Bus Queue](service-bus-queue)
- [Azure SQL Database](sql-database)
- [Azure SQL Managed Instance](sql-managed-instance)
- [Azure Storage Queue](storage-queue)
- [Azure Virtual Machine](virtual-machine)
- [Azure Virtual Machine Scale Set (VMSS)](virtual-machine-scale-set)
- [Azure Web App](web-app)
Want to help out? Create an issue and [contribute a new scraper](https://github.com/tomkerkhove/promitor/blob/master/adding-a-new-scraper.md).
Expand Down
42 changes: 42 additions & 0 deletions docs/configuration/v1.x/metrics/web-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
layout: default
title: Azure Web App Declaration
---

## Azure Web App - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.2-green.svg)

You can declare to scrape an Azure Web App via the `WebApp` resource
type.

The following fields need to be provided:

- `webAppName` - The name of the Azure Web App
- `slotName` - The name of the deployment slot *(optional)*

All supported metrics are documented in the official [Azure Monitor documentation](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftwebsites-excluding-functions).

The following scraper-specific metric label will be added:

- `slot_name` - Name of the deployment slot. If none is specified, `production` will be used.

Example:

```yaml
name: azure_web_app_requests
description: "Amount of requests for an Azure Web App"
resourceType: WebApp
azureMetricConfiguration:
metricName: Requests
aggregation:
type: Total
resources:
- webAppName: promitor-web-app
slot: staging
- webAppName: promitor-web-app
slot: production
```
<!-- markdownlint-disable MD033 -->
[&larr; back to metrics declarations](/configuration/v1.x/metrics)<br />
[&larr; back to introduction](/)
<!-- markdownlint-enable -->
2 changes: 2 additions & 0 deletions docs/metrics/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ Every scraper can provide additional labels to provide more information.

Currently we support this for:

- Azure Function App
- Azure Service Bus
- Azure SQL Database
- Azure Storage Queue
- Azure Web App

For more information, we recommend reading the [scraper-specific documentation](./../configuration/v1.x/metrics/#supported-azure-services).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class AppPlanResourceDefinition : AzureResourceDefinition
{
public AppPlanResourceDefinition(string resourceGroupName, string appPlanName)
: base(ResourceType.AppPlan, resourceGroupName)
{
AppPlanName = appPlanName;
}

/// <summary>
/// The name of the Azure App Plan to get metrics for.
/// </summary>
public string AppPlanName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class FunctionAppResourceDefinition : AzureResourceDefinition
{
public FunctionAppResourceDefinition(string resourceGroupName, string functionAppName)
: base(ResourceType.FunctionApp, resourceGroupName)
{
FunctionAppName = functionAppName;
}

/// <summary>
/// The name of the Azure Function App to get metrics for.
/// </summary>
public string FunctionAppName { get; set; }

/// <summary>
/// The name of the deployment slot.
/// </summary>
public string SlotName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class WebAppResourceDefinition : AzureResourceDefinition
{
public WebAppResourceDefinition(string resourceGroupName, string webAppName, string slotName)
: base(ResourceType.WebApp, resourceGroupName)
{
WebAppName = webAppName;
SlotName = slotName;
}

/// <summary>
/// The name of the Azure Web App.
/// </summary>
public string WebAppName { get; set; }

/// <summary>
/// The name of the deployment slot.
/// </summary>
public string SlotName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public enum ResourceType
PostgreSql = 10,
SqlDatabase = 11,
SqlManagedInstance = 12,
VirtualMachineScaleSet = 13
VirtualMachineScaleSet = 13,
AppPlan = 14,
WebApp = 15,
FunctionApp = 16
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public IDeserializer<AzureResourceDefinitionV1> GetDeserializerFor(ResourceType
case ResourceType.VirtualMachineScaleSet:
var virtualMachineScaleSetLogger = _loggerFactory.CreateLogger<VirtualMachineScaleSetDeserializer>();
return new VirtualMachineScaleSetDeserializer(virtualMachineScaleSetLogger);
case ResourceType.AppPlan:
var appPlanLogger = _loggerFactory.CreateLogger<AppPlanDeserializer>();
return new AppPlanDeserializer(appPlanLogger);
case ResourceType.WebApp:
var webAppLogger = _loggerFactory.CreateLogger<WebAppDeserializer>();
return new WebAppDeserializer(webAppLogger);
case ResourceType.FunctionApp:
var functionAppLogger = _loggerFactory.CreateLogger<FunctionAppDeserializer>();
return new FunctionAppDeserializer(functionAppLogger);
default:
throw new ArgumentOutOfRangeException($"Resource Type {resourceType} not supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public V1MappingProfile()
CreateMap<SqlDatabaseResourceV1, SqlDatabaseResourceDefinition>();
CreateMap<SqlManagedInstanceResourceV1, SqlManagedInstanceResourceDefinition>();
CreateMap<VirtualMachineScaleSetResourceV1, VirtualMachineScaleSetResourceDefinition>();
CreateMap<AppPlanResourceV1, AppPlanResourceDefinition>();
CreateMap<WebAppResourceV1, WebAppResourceDefinition>();
CreateMap<FunctionAppResourceV1, FunctionAppResourceDefinition>();

CreateMap<MetricDefinitionV1, PrometheusMetricDefinition>();

Expand All @@ -54,7 +57,10 @@ public V1MappingProfile()
.Include<VirtualMachineResourceV1, VirtualMachineResourceDefinition>()
.Include<SqlDatabaseResourceV1, SqlDatabaseResourceDefinition>()
.Include<SqlManagedInstanceResourceV1, SqlManagedInstanceResourceDefinition>()
.Include<VirtualMachineScaleSetResourceV1, VirtualMachineScaleSetResourceDefinition>();
.Include<VirtualMachineScaleSetResourceV1, VirtualMachineScaleSetResourceDefinition>()
.Include<AppPlanResourceV1, AppPlanResourceDefinition>()
.Include<WebAppResourceV1, WebAppResourceDefinition>()
.Include<FunctionAppResourceV1, FunctionAppResourceDefinition>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes
{
/// <summary>
/// Contains the configuration required to scrape a app plan.
/// </summary>
public class AppPlanResourceV1 : AzureResourceDefinitionV1
{
/// <summary>
/// The name of the Azure App Plan to get metrics for.
/// </summary>
public string AppPlanName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes
{
/// <summary>
/// Contains the configuration required to scrape an Azure Function App.
/// </summary>
public class FunctionAppResourceV1 : AzureResourceDefinitionV1
{
/// <summary>
/// The name of the Azure Function App to get metrics for.
/// </summary>
public string FunctionAppName { get; set; }

/// <summary>
/// The name of the deployment slot.
/// </summary>
public string SlotName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes
{
/// <summary>
/// Contains the configuration required to scrape an Azure Web App.
/// </summary>
public class WebAppResourceV1 : AzureResourceDefinitionV1
{
/// <summary>
/// The name of the Azure Web App.
/// </summary>
public string WebAppName { get; set; }

/// <summary>
/// The name of the deployment slot.
/// </summary>
public string SlotName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.Extensions.Logging;
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model;
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes;
using YamlDotNet.RepresentationModel;

namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Providers
{
public class AppPlanDeserializer : ResourceDeserializer
{
private const string AppPlanNameTag = "appPlanName";

public AppPlanDeserializer(ILogger<AppPlanDeserializer> logger) : base(logger)
{
}

protected override AzureResourceDefinitionV1 DeserializeResource(YamlMappingNode node)
{
var appPlanName = node.GetString(AppPlanNameTag);

return new AppPlanResourceV1
{
AppPlanName= appPlanName
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.Extensions.Logging;
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model;
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes;
using YamlDotNet.RepresentationModel;

namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Providers
{
public class FunctionAppDeserializer : ResourceDeserializer
{
private const string FunctionAppNameTag = "functionAppName";
private const string SlotNameTag = "slotName";

public FunctionAppDeserializer(ILogger<FunctionAppDeserializer> logger) : base(logger)
{
}

protected override AzureResourceDefinitionV1 DeserializeResource(YamlMappingNode node)
{
var functionAppName = node.GetString(FunctionAppNameTag);
var slotName = node.GetString(SlotNameTag);

return new FunctionAppResourceV1
{
FunctionAppName = functionAppName,
SlotName = slotName
};
}
}
}
Loading

0 comments on commit 1965793

Please sign in to comment.