首页 > 其他分享 >【Application Insights】使用CURL命令向Application Insgihts发送测试数据

【Application Insights】使用CURL命令向Application Insgihts发送测试数据

时间:2024-01-08 21:31:42浏览次数:30  
标签:name -- Application https azure CURL Insights

问题描述

在使用App Service或者Kubernetes等服务时,需要收集一些日志数据并且发送到Application Insights中,当使用SDK或者是服务自带的Application Insights配置时遇见问题,有没有快速的调试方式能验证App Service是否与Application Insights之间的连通性呢?

【Application Insights】使用CURL命令向Application Insgihts发送测试数据_结点


问题解答

可以使用CURL发送请求到Application Insigths的Ingress Endpoint来验证当前环境是否可以成功发送请求!

根据参考文档(用于发送可用性测试结果的 Curl 命令)中介绍,使用 curl 发送 REST 请求,引入终结点主机名、 iKey 值和 time 值。 Application Insights 引入终结点不接受任何超过 48 小时的记录。

###适用于 Linux/MacOS 的 Curl 命令:
curl -H "Content-Type: application/json" -X POST -d '{"data":{"baseData":{"ver":2,"id":"SampleRunId","name":"MicrosoftSupportSampleWebtestResultUsingCurl","duration":"00.00:00:10","success":true,"runLocation":"RegionName","message":"SampleWebtestResult","properties":{"SampleProperty":"SampleValue"}},"baseType":"AvailabilityData"},"ver":1,"name":"Microsoft.ApplicationInsights.Metric","time":"2024-01-08T12:57:25.0000000Z","sampleRate":100,"iKey":"########-####-####-####-############","flags":0}'  https://chinanorth3-0.in.applicationinsights.azure.cn/v2/track   -v

 

### 适用于 Windows 的 Curl 命令:
curl -H "Content-Type: application/json" -X POST -d {\"data\":{\"baseData\":{\"ver\":2,\"id\":\"SampleRunId\",\"name\":\"MicrosoftSupportSampleWebtestResultUsingCurl\",\"duration\":\"00.00:00:10\",\"success\":true,\"runLocation\":\"RegionName\",\"message\":\"SampleWebtestResult\",\"properties\":{\"SampleProperty\":\"SampleValue\"}},\"baseType\":\"AvailabilityData\"},\"ver\":1,\"name\":\"Microsoft.ApplicationInsights.Metric\",\"time\":\"2024-01-08T12:57:25.0000000Z\",\"sampleRate\":100,\"iKey\":\"########-####-####-####-############\",\"flags\":0} https://chinanorth3-0.in.applicationinsights.azure.cn/v2/track   -v

在以上内容中,需要修改的内容有

  • time: 修改为发送请求的当前时间点,如2024-01-08T12:57:25.0000000Z
  • iKey :  在Application Insights的Overview页面中,复制 Instrumentation Key 的值
  • Application Insights的终结点,https://dc.applicationinsights.azure.com/v2/track 为global azure的终结点,如果使用的是中国区的Application Insights,需要从连接字符串中提取Ingress Endpoint,完成的值为:
  • 中国东部2区:https://chinaeast2-0.in.applicationinsights.azure.cn/v2/track 
  • 中国北部3区:https://chinanorth3-0.in.applicationinsights.azure.cn/v2/track

 

下图为在App Service Kudu中的测试和验证过程:

第一步:准备 curl 命令并进入App Service Kudu站点:

C:\home>curl -H "Content-Type: application/json" -X POST -d {\"data\":{\"baseData\":{\"ver\":2,\"id\":\"SampleRunId\",\"name\":\"MicrosoftSupportSampleWebtestResultUsingCurl\",\"duration\":\"00.00:00:10\",\"success\":true,\"runLocation\":\"RegionName\",\"message\":\"SampleWebtestResult\",\"properties\":{\"SampleProperty\":\"SampleValue\"}},\"baseType\":\"AvailabilityData\"},\"ver\":1,\"name\":\"Microsoft.ApplicationInsights.Metric\",\"time\":\"2024-01-08T13:09:00.0000000Z\",\"sampleRate\":100,\"iKey\":\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\"flags\":0} https://chinanorth3-0.in.applicationinsights.azure.cn/v2/track

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   493  100    49  100   444    436   3956 --:--:-- --:--:-- --:--:--  5358

{"itemsReceived":1,"itemsAccepted":1,"errors":[]}

【Application Insights】使用CURL命令向Application Insgihts发送测试数据_App_02

 

第二步:在Application Insights中验证数据是否发送成功

进入Application Insights的Logs页面,直接查看 availabilityResults 表中最近1小时的数据:

【Application Insights】使用CURL命令向Application Insgihts发送测试数据_结点_03

 

 

参考资料

用于发送可用性测试结果的 Curl 命令 : https://learn.microsoft.com/zh-cn/troubleshoot/azure/azure-monitor/app-insights/investigate-missing-telemetry#curl-command-send-availability-test-result

 

 


当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

标签:name,--,Application,https,azure,CURL,Insights
From: https://blog.51cto.com/u_13773780/9151434

相关文章

  • Spring的ApplicationContext核心分析
    跟着孙哥学Spring,b站:https://www.bilibili.com/video/BV185411477k/?spm_id_from=333.337.search-card.all.click1.AnnotationConfigApplicationContext执行过程publicstaticvoidmain(String[]args){AnnotationConfigApplicationContextctx=newAnnotationConfig......
  • Spring MVC 源码分析 - WebApplicationContext 容器的初始化
    随着 SpringBoot 和 SpringCloud 在许多中大型企业中被普及,可能你已经忘记当年经典的Servlet+SpringMVC的组合,是否还记得那个 web.xml 配置文件。在开始本文之前,请先抛开 SpringBoot 到一旁,回到从前,一起来看看Servlet是怎么和SpringMVC集成,怎么来初始化Sprin......
  • Random Forests in Computer Vision: Applications and Techniques
    1.背景介绍随机森林在计算机视觉领域的应用和技术随机森林(RandomForests)是一种机器学习方法,它通过构建多个决策树来进行预测和分类。这种方法在处理高维数据和非线性问题时具有很好的性能。在计算机视觉领域,随机森林已经被广泛应用于各种任务,例如图像分类、目标检测、对象识别等。......
  • Python Machine Learning Projects: Building RealWorld Applications
    1.背景介绍人工智能和机器学习技术在过去的几年里取得了巨大的进步,这使得许多实际应用成为可能。这本书《16.PythonMachineLearningProjects:BuildingReal-WorldApplications》旨在帮助读者理解这些实际应用,并提供有关如何使用Python编写机器学习代码的实践指南。本书的目......
  • GANs in the Wild: RealWorld Applications of Generative Adversarial Networks
    1.背景介绍生成对抗网络(GenerativeAdversarialNetworks,GANs)是一种深度学习算法,由伊戈尔·Goodfellow等人于2014年提出。这种算法通过两个神经网络来学习数据分布:一个生成器(Generator)和一个判别器(Discriminator)。生成器的目标是生成类似于训练数据的新数据,而判别器的目标是区分这......
  • centos7 升级curl-8.2.1 支持http2 (yum update)
    转载于:https://www.cnblogs.com/huangweimin/articles/15882913.htmlCentOS7默认的curl版本最新就到7.29 ,它是不支持http2的#curl--versioncurl7.29.0(x86_64-redhat-linux-gnu)libcurl/7.29.0NSS/3.53.1zlib/1.2.7libidn/1.28libssh2/1.8.0Protocols:dict......
  • ApplicationHost.config文件被破坏导致IIS崩溃
    https://www.8a.hk/index.php/news/content/4105.html 今天临近下班时,突然出现了一个重大BUG。服务器IIS崩溃了,所有的站点都打不开了。提示错误:“配置文件的XML格式不正确”。一下就惊到了,感觉自已又要加班了。 根据提示,找到了applicationHost.config文件,打开后,发现,里面全部......
  • springboot 中,ApplicationRunner、InitializingBean、@PostConstruct 执行顺序
    划水。。。ApplicationRunner、InitializingBean、@PostConstruct执行顺序InitializingBean是Spring提供的一个接口,它只有一个方法afterPropertiesSet(),该方法会在容器初始化完成后被调用。ApplicationRunner是SpringBoot提供的一个接口,它有一个方法run(),该方法会在......
  • 完美解决SqlServer2012启动报错(cannot find one or more components.Please reinstall
    原因:默认安装在C:\ProgramFiles(x86)\MicrosoftVisualStudio10.0文件夹,以支持sqlserver2012.(我之前不小心把这个文件夹删除了)。解决方案:下载了visualstudio2010Isolatedshell完美解决问题,下载后安装就能正常运行SqlServer2012了,其他SqlServer版本请下载visualstudio......
  • The World of Virtual Reality (VR) and Augmented Reality (AR): Applications and F
    1.背景介绍VirtualReality(VR)andAugmentedReality(AR)aretworapidlyevolvingtechnologiesthathavethepotentialtorevolutionizethewayweinteractwiththedigitalworld.VRcreatesacompletelyimmersiveexperiencebytransportinguserstoavirtua......