观测云接入 NewRelic .NET 探针

背景

部分客户系统采用的是.NET 4.5 部署研发的、基于 IIS 进行发布的 Web 项目,需要接入到观测云进行链路信息展示,ddtrace 和 otel 对于低版本.NET 支持力度有限。

环境信息

  • IIS 4.0
  • .NET core 4.0、4.5、4.6
  • Window Server 2012 R2

域名配置

准备一个域名 www.datakit.com,需要申请 https 证书

配置 host

修改 hosts 文件,添加两个域名

127.0.0.1 www.google.com
127.0.0.1 www.datakit.com
  • www.google.com: NewRelic Agent 在生效前需要去访问一下 google,目的是确保网络通畅
  • www.datakit.com: NewRelic Agent 上报链路数据采用的是 tls,需要一个域名和证书信息

域名生效

在 IIS 下新增网站,域名为 www.google.com,端口为 80

根证书配置

如果申请的 https 证书是购买的,一般不需要配置根证书,如果属于自签证书,则需要配置。

Windows服务器如何导入根证书

NewRelic 接入

经调查研究表明,NewRelic .NET Agent 版本 6.27 可用于当前客户环境,采集链路并上报数据到观测云(DataKit采集上报)进行统一的信息展示。

下载安装 .NET Agent

安装前需要准备一个 NewRelic license,安装时需要用到,可以随意填写,也可以填写固定值eu01xx332b83865e13171131e7f9e08dFFFFNRAL

安装完成后有两个目录

  • C:\Program Files\New Relic\.NET Agent

  • C:\ProgramData\New Relic\.NET Agent

其中 C:\Program Files\New Relic\.NET Agent 目录下有个 newrelic.conf 文件,采集.NET 信息需要。

IIS 下 NewRelic 配置

使用管理员权限打开 PowerShell,执行以下命令

$env:COR_ENABLE_PROFILING=1;
$env:COR_PROFILER={71DA0A04-7777-4EC6-9643-7D28B46A8A41};
$env:NEWRELIC_INSTALL_PATH="C:\Program Files\New Relic\.NET Agent";
$env:NEW_RELIC_HOST="www.datakit.com";

在 PowerShell 使用 Get-ChildItem env:查看命令是否生效,该命令会列出当前系统的所有环境变量信息

DataKit 安装&配置

安装

参考安装文档

DataKit 的安装目录为 C:\Program Files\datakit

调整 DataKit 配置

DataKit 全局配置文件为datakit.conf,这里需要调整datakit.conf,让其至此 tls

[http_api]
  rum_origin_ip_header = "X-Forwarded-For"
  listen = "0.0.0.0:9529"
  disable_404page = false
  rum_app_id_white_list = []
  public_apis = []
  timeout = "30s"
  close_idle_connection = false
  [http_api.tls]
    cert="/cert/cmyncp.com_cert.pem"
    privkey="/cert/cmyncp.com_key.pem"

其中 [http_api.tls] 为开启 tls 模块

  • cert:域名公钥证书
  • privkey:域名私钥证书

路径建议填写绝对路径,否则可能会出现意想不到的效果

开启 NewRelic 采集器

进入 DataKit 安装目录下,并进入 conf.d/newrelic,复制 newrelic.config.samplenewrelic.config

重启 DataKit

在 PowerShell 下执行一下命令

datakit service -R

应用接入 NewRelic .NET Agent

配置 newrelic.conf

<?xml version="1.0"?>
<!-- Copyright (c) 2008-2017 New Relic, Inc.  All rights reserved. -->
<!-- For more information see: https://newrelic.com/docs/dotnet/dotnet-agent-configuration -->
<configuration xmlns="urn:newrelic-config" agentEnabled="true">
  <service licenseKey="eu01xx332b83865e13171131e7f9e08dFFFFNRAL" ssl="true" host="www.datakit.com" port="9529"/>
  <application>
    <name>water-web</name>
  </application>
  <log level="debug" auditLog="true"/>
  <transactionTracer enabled="true" transactionThreshold="apdex_f" stackTraceThreshold="500" recordSql="obfuscated" explainEnabled="false" explainThreshold="500" />
  <crossApplicationTracer enabled="true" />
  <errorCollector enabled="true">
    <ignoreErrors>
      <exception>System.IO.FileNotFoundException</exception>
      <exception>System.Threading.ThreadAbortException</exception>
    </ignoreErrors>
    <ignoreStatusCodes>
      <code>401</code>
      <code>404</code>
    </ignoreStatusCodes>
  </errorCollector>
  <browserMonitoring autoInstrument="true" />
  <threadProfiling>
    <ignoreMethod>System.Threading.WaitHandle:InternalWaitOne</ignoreMethod>
    <ignoreMethod>System.Threading.WaitHandle:WaitAny</ignoreMethod>
  </threadProfiling>
</configuration>

配置说明:
licenseKey: license 信息
host: 上报的主机
port: 上报端口
application > name: 应用名称
log: 日志信息

其中 host 和 port可以通过全局变量的方式进行配置

$env:NEW_RELIC_HOST="www.datakit.com";
$env:NEW_RELIC_PORT=9529;

重启 IIS

net stop /y was # stop iis

net start w3svc # start iis

访问应用

只有访问了应用,系统才会生成链路数据,并进行数据上报。

2023-09-11 07:19:05,603 NewRelic INFO: Configuration file found in app/web root directory: C:\Users\Administrator\Desktop\public\newrelic.config
2023-09-11 07:19:05,632 NewRelic INFO: The log level was updated to DEBUG
2023-09-11 07:19:05,766 NewRelic DEBUG: Available storage type : NewRelic.Providers.Storage.CallStack.AsyncLocal.CallContextStorageFactory (True)
2023-09-11 07:19:05,768 NewRelic DEBUG: Available storage type : NewRelic.Providers.Storage.TransactionContext.AspTransactionContextFactory (True)
2023-09-11 07:19:05,772 NewRelic DEBUG: Available storage type : NewRelic.Providers.Storage.TransactionContext.Wcf3TransactionContextFactory (True)
2023-09-11 07:19:05,774 NewRelic DEBUG: Using async storage NewRelic.Providers.Storage.CallStack.AsyncLocal.CallContextStorageFactory for call stack
2023-09-11 07:19:06,030 NewRelic INFO: Reading configuration from "C:\Users\Administrator\Desktop\public\newrelic.config"
2023-09-11 07:19:06,049 NewRelic INFO: The New Relic .NET Agent v6.27.0.0 started (pid 4344) for virtual path '/'
2023-09-11 07:19:06,050 NewRelic WARN: This version of the agent is primarily meant for monitoring .NET Framework 3.5 applications. This application is running on .NET CLR version 4.0.30319.42000. If you do not need to monitor any .NET Framework 3.5 applications on this server, please consider upgrading to the latest version of the New Relic .NET Agent which supports .NET Framework 4.5 and higher.
2023-09-11 07:19:06,076 NewRelic DEBUG: Wrapper "NewRelic.Providers.Wrapper.ServiceStackRedis.SendCommandWrapper" will be used for instrumented method "ServiceStack.Redis.RedisNativeClient.SendCommand"
2023-09-11 07:19:06,391 NewRelic DEBUG: Invoking "preconnect" with : []
2023-09-11 07:19:07,309 NewRelic DEBUG: Wrapper "NewRelic.Providers.Wrapper.Asp35.IntegratedPipeline.ExecuteStepWrapper" will be used for instrumented method "System.Web.HttpApplication.ExecuteStep"
2023-09-11 07:19:07,548 NewRelic DEBUG: Wrapper "NewRelic.Providers.Wrapper.Asp35.Shared.RouteNamingWrapper" will be used for instrumented method "System.Web.Routing.RouteCollection.GetRouteData"
2023-09-11 07:19:07,733 NewRelic DEBUG: Wrapper "NewRelic.Providers.Wrapper.Asp35.Shared.CallHandlerWrapper" will be used for instrumented method "System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute"
2023-09-11 07:19:07,782 NewRelic DEBUG: Wrapper "NewRelic.Providers.Wrapper.Mvc3.AsyncBeginInvokeActionWrapper" will be used for instrumented method "System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction"
2023-09-11 07:19:07,851 NewRelic DEBUG: Wrapper "NewRelic.Providers.Wrapper.Mvc3.AsyncEndInvokeActionWrapper" will be used for instrumented method "System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction"
2023-09-11 07:19:08,026 NewRelic DEBUG: Wrapper "NewRelic.Providers.Wrapper.Asp35.Shared.FilterWrapper" will be used for instrumented method "System.Web.HttpWriter.FilterIntegrated"
2023-09-11 07:19:08,053 NewRelic DEBUG: Wrapper "NewRelic.Providers.Wrapper.Asp35.IntegratedPipeline.FinishPipelineRequestWrapper" will be used for instrumented method "System.Web.HttpRuntime.FinishPipelineRequest"
2023-09-11 07:19:08,424 NewRelic DEBUG: Received : {"redirect_host":"www.cmyncp.com","security_policies":{"record_sql":{"enabled":true,"required":true},"attributes_include":{"enabled":true,"required":true},"allow_raw_exception_messages":{"enabled":true,"required":true},"custom_events":{"enabled":true,"required":true},"custom_parameters":{"enabled":true,"required":true}}}
2023-09-11 07:19:08,527 NewRelic INFO: Your New Relic Application Name(s): water-web
2023-09-11 07:19:09,775 NewRelic DEBUG: Invoking "connect" with : [{"pid":4344,"language":"dotnet","host":"iZw4p6289ecf7qZ","app_name":["water-web"],"agent_version":"6.27.0.0","agent_version_timestamp":1611791638918,"build_timestamp":1611791638918,"security_settings":{"capture_params":false,"transaction_tracer":{"record_sql":"obfuscated"}},"high_security":false,"identifier":"/LM/W3SVC/2/ROOT:publicwater-web","labels":[],"settings":{"browser_monitoring.loader_debug":false,"browser_monitoring.loader":"rum"},"utilization":{"metadata_version":3,"logical_processors":2,"total_ram_mib":2047,"hostname":"iZw4p6289ecf7qZ"},"environment":[["Framework","dotnet"],["Product Name","New Relic .NET Agent"],["OS","Microsoft Windows NT 6.3.9600.0"],[".NET Version","4.0.30319.42000"],["Total Physical System Memory",2146873344],["x64","yes"],["StartTime","2023-09-11T15:19:00.0918856+08:00"],["MainModule.FileVersionInfo","File:             c:\\windows\\system32\\inetsrv\\w3wp.exe\r\nInternalName:     w3wp.exe\r\nOriginalFilename: w3wp.exe.mui\r\nFileVersion:      8.5.9600.16384 (winblue_rtm.130821-1623)\r\nFileDescription:  IIS Worker Process\r\nProduct:          Internet Information Services\r\nProductVersion:   8.5.9600.16384\r\nDebug:            False\r\nPatched:          False\r\nPreRelease:       False\r\nPrivateBuild:     False\r\nSpecialBuild:     False\r\nLanguage:         语言中性\r\n"],["GCSettings.IsServerGC",true],["AppDomain.FriendlyName","/LM/W3SVC/2/ROOT-1-133388903407442996"],["AppDomainAppPath",null],["AppDomainAppId","/LM/W3SVC/2/ROOT"],["AppDomainAppVirtualPath","/"],["UsingIntegratedPipeline","True"],["IIS Version","8.5"],["Plugin List",["mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","Microsoft.JScript, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","WaterCloud.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","WaterCloud.DataBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","Chloe, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null","System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","WaterCloud.Code, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","WaterCloud.SystemTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","ServiceStack.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","ServiceStack.Redis, Version=3.9.71.0, Culture=neutral, PublicKeyToken=null","ServiceStack.Common, Version=3.9.70.0, Culture=neutral, PublicKeyToken=null","ServiceStack.Text, Version=3.9.71.0, Culture=neutral, PublicKeyToken=null","NewRelic.Agent.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=06552fced0b33d87","NewRelic.Agent.Extensions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","Microsoft.GeneratedCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","NewRelic.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Parsing, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.CallStack.AsyncLocal, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.TransactionContext.Asp, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.TransactionContext.Wcf3, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","NewRelic.Providers.Wrapper.Asp35, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.CastleMonoRail2, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.Couchbase, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.CustomInstrumentation, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.CustomInstrumentationAsync, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.HttpClient, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.HttpWebRequest, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.MongoDb, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.Msmq, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.Mvc3, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.NServiceBus, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.OpenRasta, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.Owin, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.Owin3, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.RabbitMq, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.RestSharp, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.ScriptHandlerFactory, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.ServiceStackRedis, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.Sql, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.SqlAsync, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.StackExchangeRedis, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.Wcf3, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.WebApi1, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.WebApi2, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.WebOptimization, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.WebServices, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","NewRelic.Providers.Wrapper.WrapperUtilities, Version=6.0.0.0, Culture=neutral, PublicKeyToken=f7f92cc5c2dc8743","System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"]],["system.web.compilation.defaultLanguage","vb"],["Physical Processors",1],["Logical Processors",2]]}]
2023-09-11 07:19:09,880 NewRelic DEBUG: Received : {"return_value":{"agent_run_id":"","request_headers_map":{},"max_payload_size_in_bytes":1000000,"entity_guid":"","transaction_segment_terms":null,"transaction_name_rules":null,"url_rules":null,"metric_name_rules":null,"encoding_key":"","cross_process_id":"","trusted_account_ids":null,"web_transactions_apdex":null,"apdex_t":0.5,"collect_analytics_events":false,"collect_custom_events":false,"collect_traces":true,"collect_errors":false,"collect_error_events":false,"collect_span_events":true,"js_agent_loader":"","beacon":"","browser_key":"","application_id":"","error_beacon":"","js_agent_file":"","messages":null,"account_id":"","trusted_account_key":"","primary_application_id":"","sampling_target":10,"sampling_target_period_in_seconds":60,"agent_config":{"transaction_tracer.enabled":null,"transaction_tracer.transaction_threshold":null,"transaction_tracer.stack_trace_threshold":null,"error_collector.enabled":null,"error_collector.ignore_status_codes":null,"error_collector.expected_status_codes":null,"cross_application_tracer.enabled":null},"event_harvest_config":{"report_period_ms":60000,"harvest_limits":{"analytic_event_data":10000,"custom_event_data":30000,"log_event_data":10000,"error_event_data":100,"span_event_data":1000}},"span_event_harvest_config":{"report_period_ms":60,"harvest_limit":1000},"data_report_period":60}}
2023-09-11 07:19:09,924 NewRelic INFO: Agent /LM/W3SVC/2/ROOT:publicwater-web connected to www.datakit.com:9529
2023-09-11 07:19:10,009 NewRelic DEBUG: Invoking "agent_settings" with : [{"apdex_t":0.5,"cross_process_id":"","encoding_key":"","trusted_account_ids":[],"max_stack_trace_lines":80,"using_server_side_config":true,"thread_profiler.enabled":true,"cross_application_tracer.enabled":true,"error_collector.enabled":false,"error_collector.ignore_status_codes":["401","404"],"error_collector.ignore_errors":["System.IO.FileNotFoundException","System.Threading.ThreadAbortException"],"transaction_tracer.stack_trace_threshold":0.5,"transaction_tracer.explain_enabled":false,"transaction_tracer.max_sql_statements":500,"transaction_tracer.max_explain_plans":20,"transaction_tracer.explain_threshold":0.5,"transaction_tracer.transaction_threshold":2.0,"transaction_tracer.record_sql":"obfuscated","slow_sql.enabled":true,"browser_monitoring.auto_instrument":true}]
2023-09-11 07:19:10,019 NewRelic DEBUG: Received : {}
2023-09-11 07:19:10,022 NewRelic INFO: Agent fully connected.

登陆观测云帐号查看数据信息

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值