An Azure service that stores structured NoSQL data in the cloud.
Azure Table Storage size and retention can be managed by combining Azure Monitor metrics with an automated cleanup process.
To see how much space a storage account or the Table service is using, query the UsedCapacity metric from Azure Monitor. This can be done programmatically from C# via the Azure Monitor client libraries, or via CLI/PowerShell if preferred.
Conceptually in C#:
- Enable metrics for the storage account (Azure Resource Manager account, not classic).
- Use the Azure Monitor .NET SDK to query
UsedCapacityfor the storage account or for thetableServicesresource. - Use the resource ID of the storage account or the Table service (from the Properties blade in the portal) when querying metrics.
The documentation for monitoring Table Storage describes this pattern:
- Metrics for Table Storage are exposed under:
-
Microsoft.Storage/storageAccounts -
Microsoft.Storage/storageAccounts/tableServices
-
-
UsedCapacityis the metric that reports capacity usage. - From .NET, use
Azure.Monitor.QuerywithDefaultAzureCredentialto read metric definitions and values forUsedCapacity.
For example (high level):
- Install the NuGet packages:
-
Azure.Monitor.Query -
Azure.Identity
-
- Use the MetricsQueryClient to query:
- Resource ID: storage account or table service
- Metric name:
UsedCapacity - Time grain: e.g.,
PT1H
- Convert the returned capacity (bytes) to GB in code.
For automation and cleanup of old data (for example, older than 30 or 100 days):
- Implement a retention rule in application code that writes to Table Storage:
- Include a timestamp property on each entity (for example, the built-in
Timestampor a custom date column). - Periodically query entities older than the retention threshold and delete them.
- Include a timestamp property on each entity (for example, the built-in
- Automate the cleanup by running a scheduled process:
- Use an Azure Function or other scheduled job that:
- Enumerates the tables.
- For each table, queries entities older than the threshold (for example,
Timestamp < now - 30 days). - Deletes them in batches.
- Use an Azure Function or other scheduled job that:
- Use Azure Monitor to observe the effect of cleanup:
- Use Metrics Explorer in the Azure portal to visualize
UsedCapacityandTransactionsover time for the storage account or Table service. - Optionally filter
Transactionsby API name (for example, delete operations) using theApiNamedimension.
- Use Metrics Explorer in the Azure portal to visualize
- If diagnostic logs are enabled to Log Analytics, Kusto queries can be used to analyze Table operations and verify cleanup behaviour, for example by querying
StorageTableLogsto see delete operations over time.
This approach provides:
- Capacity visibility per storage account/Table service via
UsedCapacitymetrics. - Automated, time-based cleanup driven by a scheduled process that deletes entities older than the retention window.
- Monitoring and validation via Azure Monitor metrics, Logs, and tools such as Metrics Explorer and Log Analytics.
References: