Skip to content

Instantly share code, notes, and snippets.

View shawnweisfeld's full-sized avatar

Shawn Weisfeld shawnweisfeld

View GitHub Profile
** Code Sample
** NOTE: you need AD IAM permissions for this to work
namespace DemoSCID
{
internal class Program
{
static async Task Main(string[] args)
{
var sasUri = await GetSAS();
var blockBlobClient = new BlockBlobClient(sasUri, null);

Pseudocode for Blob Listing/Counting Algorithm

Blob Storage Provides 2 APIs that are needed for this effort.

  • For the Azure Storage account, you can list all the storage containers that it includes more info
  • For any Azure Storage container, you can list all the blobs in the container more info
    • The key for this api is the “prefix” and “delimiter” parameters, these allow you to break up a single list of all the objects in the container into logical folders and process each folder independently.

Other requirements

# ----------------------------------------------------------------------------------
# MIT License
# from https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python-legacy
# Copyright(c) Microsoft Corporation. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
using Azure.Storage.Blobs;
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace ListSpeedTest
{
# Variables
SUB="your azure subscription guid"
RG="the resource group your storage account is in"
STORAGEACCT="the short name of your storage account"
# Resource strings to the account and to the blob service
RESOURCE="/subscriptions/$SUB/resourceGroups/$RG/providers/Microsoft.Storage/storageAccounts/$STORAGEACCT"
BLOBRESOURCE="/subscriptions/$SUB/resourceGroups/$RG/providers/Microsoft.Storage/storageAccounts/$STORAGEACCT/blobServices/default"
# Object Replication Demo
# 0. Setup some variables and create the resource group
# - in this sample we are using the same container name for source and destination this is not required
# - in this sample we are using the same region for source and destination this is not required
# - in this sample we are using the same durability (i.e. LRS) for source and destination this is not required
RG="sweisfelortest"
LOCATION="westus"
SRCACCT="sweisfelsrc$RANDOM"
#1) Create VM
#2) Create Storage account
#3) Register an application with Azure AD and create a service principal
# https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#register-an-application-with-azure-ad-and-create-a-service-principal
#4) create a client secret or upload certificate for your service principal to use
# https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#authentication-two-options
# Get metrics for all storage accounts in an azure sub
## Fill in the shared variables
$sub = "" # Azure Subscription GUID
## The script
$metrics = @()
az login
## List all Application Insights Web Tests in a given resource group
## including test name and URL
# Variables
$TenantId = "" # Enter Tenant Id.
$ClientId = "" # Enter Client Id.
$ClientSecret = "" # Enter Client Secret.
$Resource = "https://management.core.windows.net/"
$SubscriptionId = "" # Enter Subscription Id.
$RG = "" # Enter Resource Group to look in.
## Monitor Azure Storage
### https://aka.ms/azuremonitor/storage-metrics
## Azure Monitor Metrics Overview
### https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-platform-metrics
## Azure Storage monitoring data reference
### https://docs.microsoft.com/en-us/azure/storage/common/monitor-storage-reference
## Azure Monitoring REST API walkthrough