1. Using azure loganalytics with cdn

    TypeScript

    Azure Log Analytics is a powerful monitoring service provided by Microsoft that helps you collect and analyze data generated by resources in your cloud and on-premises environments. Integrating it with Azure CDN (Content Delivery Network) enables you to monitor and analyze the traffic served by your CDN, providing insights for performance improvements, security assessments, and more.

    To integrate Azure Log Analytics with Azure CDN, we first need to set up an Azure Log Analytics Workspace. This workspace is where all your logging data will be collected and analyzed. After setting up the workspace, you'll need to configure your CDN to send logs to this workspace.

    Below is a Pulumi program in TypeScript that demonstrates how to create an Azure Log Analytics Workspace and an Azure CDN Profile with an Endpoint, which is configured to use the created Log Analytics Workspace.

    import * as azure from "@pulumi/azure"; import * as pulumi from "@pulumi/pulumi"; // Create an Azure Resource Group const resourceGroup = new azure.core.ResourceGroup("myResourceGroup", { location: "West Europe", }); // Create an Azure Log Analytics Workspace const logAnalyticsWorkspace = new azure.operationalinsights.AnalyticsWorkspace("myAnalyticsWorkspace", { resourceGroupName: resourceGroup.name, location: resourceGroup.location, sku: "PerGB2018", retentionInDays: 30, }); // Create a CDN Profile const cdnProfile = new azure.cdn.Profile("myCdnProfile", { resourceGroupName: resourceGroup.name, location: resourceGroup.location, sku: "Standard_Microsoft", }); // Create a CDN Endpoint const cdnEndpoint = new azure.cdn.Endpoint("myCdnEndpoint", { name: "myendpoint", resourceGroupName: resourceGroup.name, profileName: cdnProfile.name, isHttpAllowed: false, isHttpsAllowed: true, originHostHeader: "www.example.com", contentTypesToCompress: [ "text/html", "application/javascript", "text/css", ], queryParams: ["uid", "itok"], // Here we attach the Log Analytics workspace to the CDN endpoint to enable diagnostics logs diagnostics: { logAnalyticsLogging: { enabled: true, workspaceId: logAnalyticsWorkspace.workspaceId, workspaceRegion: logAnalyticsWorkspace.location, }, }, }); // Output the primary keys of the Log Analytics Workspace export const primarySharedKey = logAnalyticsWorkspace.primarySharedKey; export const secondarySharedKey = logAnalyticsWorkspace.secondarySharedKey; // Run `pulumi up` to deploy this stack.

    This program sets up the resources in the following order:

    1. Creates an Azure Resource Group which is a logical container into which Azure resources are deployed and managed.
    2. Instantiates a Log Analytics Workspace where all the logs from the CDN will be collected.
    3. Defines a CDN Profile which specifies a collection of CDN endpoints and has settings that affect the CDN endpoints.
    4. Sets up a CDN Endpoint which is the specific location where content is delivered and cached.

    In the cdnEndpoint resource creation, note that we include a diagnostics section. This is where we link the CDN to the Log Analytics Workspace, so it knows where to send the logs.

    By running the Pulumi program above with the Pulumi CLI, it will deploy these resources in your Azure account. To do so, you'll need to have Pulumi installed and configured with your Azure credentials.

    Remember that the names for the resources and properties like location, sku, originHostHeader, and others should be replaced with the actual values that suit your needs. The originHostHeader should specifically match your website's hostname that is served through the Azure CDN.

    Once deployed, your CDN's logs will be sent to the Log Analytics Workspace, where you can use Azure's query language to analyze the data.

    To run this Pulumi program, you would first need to install the Pulumi CLI, setup your Azure account, then create a new directory for your Pulumi project, and initialize it using pulumi new azure-typescript. After that, replace the generated index.ts with the above code, and finally run pulumi up to deploy your infrastructure.