微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Azure资源模板依赖关系/应用程序洞察

我有一个鸡和蛋问题,将我的Web应用程序部署Application Insights到Azure.在ARM模板中,Application Insights模块依赖于应用程序ID的Web站点(请参阅下面的ARM模板中的依赖项).另一方面,为了完全检测Web应用程序,我需要Application Insights模块中的检测键.怎么绕过这个?

门户网站中的应用程序洞察视图

用于Web App的ARM模板

应用程序洞察的ARM模板

解决方案是将连接字符串和应用程序设置创建为网站的嵌套子资源.通过使用子资源策略,可以使appsettings依赖于网站和应用程序洞察.这允许按以下顺序进行配置:

>网站
>应用见解
>网站配置/ appsettings

以下两个答案很有帮助.第一个说明了如何提取检测密钥.第二个示例说明如何将应用程序设置和连接字符串嵌套为网站的子资源.

How to pull the instrumentation key

How to nest app settings as child resources

这是我的最终模板:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {
    "webSiteName": {
      "type": "string"
    },"aadTenant": {
      "type": "string"
    },"aadAudience": {
      "type": "string"
    },"endpoints": {
      "type": "string","defaultValue": "n/a"
    },"apiEndpoint": {
      "type": "string","sqlConnStrName": {
      "type": "string"
    },"sqlConnStrValue": {
      "type": "string"
    },"skuName": {
      "type": "string","defaultValue": "F1","allowedValues": [
        "F1","D1","B1","B2","B3","S1","S2","S3","P1","P2","P3","P4"
      ],"Metadata": {
        "description": "Describes plan's pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },"skuCapacity": {
      "type": "int","defaultValue": 1,"minValue": 1,"Metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },"variables": {
    "hostingPlanName": "[concat(parameters('webSiteName'),'-hostingplan')]"
  },"resources": [
    {
      "apiVersion": "2015-08-01","name": "[variables('hostingPlanName')]","type": "Microsoft.Web/serverfarms","location": "[resourceGroup().location]","tags": {
        "displayName": "HostingPlan"
      },"sku": {
        "name": "[parameters('skuName')]","capacity": "[parameters('skuCapacity')]"
      },"properties": {
        "name": "[variables('hostingPlanName')]"
      }
    },{
      "apiVersion": "2015-08-01","name": "[parameters('webSiteName')]","type": "Microsoft.Web/sites","dependsOn": [
        "[variables('hostingPlanName')]"
      ],"tags": {
        "[concat('hidden-related:',resourceId('Microsoft.Web/serverfarms',variables('hostingPlanName')))]": "empty","displayName": "Website"
      },"properties": {
        "name": "[parameters('webSiteName')]","serverFarmId": "[resourceId('Microsoft.Web/serverfarms',variables('hostingPlanName'))]"
      },"resources": [
        {
          "apiVersion": "2015-08-01","name": "appsettings","type": "config","dependsOn": [
            "[parameters('webSiteName')]","[concat('AppInsights',parameters('webSiteName'))]"
          ],"properties": {
            "ida:Tenant": "[parameters('aadTenant')]","ida:Audience": "[parameters('aadAudience')]","endpoints": "[parameters('endpoints')]","apiEndpoint": "[parameters('apiEndpoint')]","applicationInsightsInstrumentationKey": "[reference(resourceId('Microsoft.Insights/components',concat('AppInsights',parameters('webSiteName'))),'2014-04-01').InstrumentationKey]"
          }
        },{
          "apiVersion": "2015-08-01","name": "connectionstrings","dependsOn": [
            "[parameters('webSiteName')]"
          ],"properties": {
            "[parameters('sqlConnStrName')]": {
              "value": "[parameters('sqlConnStrValue')]","type": "sqlServer"
            }
          }
        },"name": "logs","properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Off"
              },"azureTableStorage": {
                "level": "Off","sasUrl": null
              },"azureBlobStorage": {
                "level": "information","sasUrl": "TO DO: pass in a SAS Url","retentionInDays": null
              }
            },"httpLogs": {
              "fileSystem": {
                "retentionInMb": 40,"enabled": true
              }
            },"FailedRequestsTracing": {
              "enabled": true
            },"detailedErrorMessages": {
              "enabled": true
            }
          }
        }
      ]
    },{
      "apiVersion": "2014-04-01","name": "[concat(variables('hostingPlanName'),'-',resourceGroup().name)]","type": "Microsoft.Insights/autoscalesettings","tags": {
        "[concat('hidden-link:',variables('hostingPlanName')))]": "Resource","displayName": "AutoScaleSettings"
      },"properties": {
        "profiles": [
          {
            "name": "Default","capacity": {
              "minimum": 1,"maximum": 2,"default": 1
            },"rules": [
              {
                "metricTrigger": {
                  "metricName": "cpuPercentage","metricResourceUri": "[resourceId('Microsoft.Web/serverfarms',variables('hostingPlanName'))]","timeGrain": "PT1M","statistic": "Average","timeWindow": "PT10M","timeAggregation": "Average","operator": "GreaterThan","threshold": 80.0
                },"scaleAction": {
                  "direction": "Increase","type": "ChangeCount","value": 1,"cooldown": "PT10M"
                }
              },{
                "metricTrigger": {
                  "metricName": "cpuPercentage","timeWindow": "PT1H","operator": "Lessthan","threshold": 60.0
                },"scaleAction": {
                  "direction": "Decrease","cooldown": "PT1H"
                }
              }
            ]
          }
        ],"enabled": false,"targetResourceUri": "[resourceId('Microsoft.Web/serverfarms',variables('hostingPlanName'))]"
      }
    },"name": "[concat('ServerErrors ',parameters('webSiteName'))]","type": "Microsoft.Insights/alertrules","dependsOn": [
        "[parameters('webSiteName')]"
      ],resourceId('Microsoft.Web/sites',parameters('webSiteName')))]": "Resource","displayName": "ServerErrorsAlertRule"
      },"properties": {
        "name": "[concat('ServerErrors ',"description": "[concat(parameters('webSiteName'),' has some server errors,status code 5xx.')]","isEnabled": true,"condition": {
          "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition","dataSource": {
            "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource","resourceUri": "[resourceId('Microsoft.Web/sites',"metricName": "Http5xx"
          },"threshold": 5.0,"windowSize": "PT5M"
        },"action": {
          "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction","sendToServiceOwners": true,"customEmails": ["you@example.com"]
        }
      }
    },"name": "[concat('ForbiddenRequests ',"displayName": "ForbiddenRequestsAlertRule"
      },"properties": {
        "name": "[concat('ForbiddenRequests ',' has some requests that are forbidden,status code 403.')]","metricName": "Http403"
          },"threshold": 5,"customEmails": [ ]
        }
      }
    },"name": "[concat('cpuHigh ',"displayName": "cpuHighAlertRule"
      },"properties": {
        "name": "[concat('cpuHigh ',"description": "[concat('The average cpu is high across all the instances of ',"isEnabled": false,"resourceUri": "[resourceId('Microsoft.Web/serverfarms',"metricName": "cpuPercentage"
          },"threshold": 90,"windowSize": "PT15M"
        },"name": "[concat('LongHttpQueue ',"properties": {
        "name": "[concat('LongHttpQueue ',"description": "[concat('The HTTP queue for the instances of ',variables('hostingPlanName'),' has a large number of pending requests.')]","resourceUri": "[concat(resourceGroup().id,'/providers/Microsoft.Web/serverfarms/',"metricName": "HttpQueueLength"
          },"threshold": 100.0,"name": "[concat('AppInsights',"type": "Microsoft.Insights/components","location": "Central US","displayName": "AppInsightsComponent"
      },"properties": {
        "ApplicationId": "[parameters('webSiteName')]"
      }
    }
  ],"outputs": {
    "siteUri": {
      "type": "string","value": "[reference(concat('Microsoft.Web/sites/',parameters('webSiteName')),'2015-08-01').hostnames[0]]"
    }
  }

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图:提供一种方法顺序访问一个聚合对象中的每个元素,而又不想暴露该对象的内部表示。应用:STL标准库迭代器实现、Java集合类型迭代器等模式结构:心得:迭代器模式的目的是在不获知集合对象内部细节的同时能对集合元素进行遍历操作
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,常见的IO模型有四种:(1)同步阻塞IO(BlockingIO):即传统的IO模型。(2)同步非阻塞IO(Non-blockingIO):默认创建的socket都是阻塞的,非阻塞IO要求socket被设置为NONBLOCK。注意这里所说的N
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定义一系列算法,把他们封装起来,并且使他们可以相互替换,使算法可以独立于使用它的客户而变化。应用:排序的比较方法、封装针对类的不同的算法、消除条件判断、寄存器分配算法等。模式结构:心得:对对象(Context)的处理操作可
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个作用于某对象结构中的各元素的操作,它使你在不改变各元素的类的前提下定义作用于这些元素的新操作。应用:作用于编译器语法树的语义分析算法。模式结构:心得:访问者模式是要解决对对象添加新的操作和功能时候,如何尽可能不修改对象的类的一种方
命令模式(Command)命令模式(Command)[Action/Transaction]意图:将一个请求封装为一个对象,从而可用不同的请求对客户参数化。对请求排队或记录请求日志,以及支持可撤消的操作。应用:用户操作日志、撤销恢复操作。模式结构:心得:命令对象的抽象接口(Command)提供的两个
生成器模式(Builder)生成器模式(Builder)意图:将一个对象的构建和它的表示分离,使得同样的构建过程可以创建不同的表示。 应用:编译器词法分析器指导生成抽象语法树、构造迷宫等。模式结构:心得:和工厂模式不同的是,Builder模式需要详细的指导产品的生产。指导者(Director)使用C
设计模式学习心得《设计模式:可复用面向对象软件的基础》一书以更贴近读者思维的角度描述了GOF的23个设计模式。按照书中介绍的每个设计模式的内容,结合网上搜集的资料,我将对设计模式的学习心得总结出来。网络上关于设计模式的资料和文章汗牛充栋,有些文章对设计模式介绍生动形象。但是我相信“一千个读者,一千个
工厂方法模式(Factory Method)工厂方法模式(Factory Method)[Virtual Constructor]意图:定义一个用于创建对象的接口,让子类决定实例化哪一个类,使一个类的实力化延迟到子类。应用:多文档应用管理不同类型的文档。模式结构:心得:面对同一继承体系(Produc
单例模式(Singleton)单例模式(Singleton)意图:保证一个类只有一个实例,并提供一个访问它的全局访问点。应用:Session或者控件的唯一示例等。模式结构:心得:单例模式应该是设计模式中最简单的结构了,它的目的很简单,就是保证自身的实例只有一份。实现这种目的的方式有很多,在Java中
装饰者模式(Decorator)装饰者模式(Decorator)[Wrapper]意图:动态的给一个对象添加一些额外的职责,就增加功能来说,比生成子类更为灵活。应用:给GUI组件添加功能等。模式结构:心得:装饰器(Decorator)和被装饰的对象(ConcreteComponent)拥有统一的接口