whuanle / CZGL.SystemInfo

一个.NET Core监控系统CPU内存等信息的工具
353 stars 68 forks source link

空引用异常 #6

Closed LGinC closed 2 years ago

LGinC commented 3 years ago

rumtime: aspnet:5.0-alpine nuget: CZGL.ProcessMetrics.ASPNETCore 1.0.0

进程监控空引用异常, 这里的Process为空 https://github.com/whuanle/CZGL.SystemInfo/blob/bce18ba6f495e81921d92c8d6e87027e5db9e90c/src/CZGL.ProcessMetrics/ProcessMetricsCore.cs#L178 [11:06:20 EROR] An unhandled exception has occurred while executing the request. System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.) ---> System.NullReferenceException: Object reference not set to an instance of an object. at System.Diagnostics.Process.get_HandleCount() at CZGL.ProcessMetrics.ProcessMetricsCore.b15_0() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at CZGL.ProcessMetrics.ProcessMetricsCore.ProcessThreadsRecord() at CZGL.ProcessMetrics.ProcessMetricsCore.GetPrometheus() --- End of inner exception stack trace --- at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at CZGL.ProcessMetrics.Extensions.<>c.<b__0_0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Routing.EndpointMiddleware.gAwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

这个是偶发现象,不容易复现 网卡监控构造函数懒加载空引用异常 https://github.com/whuanle/CZGL.SystemInfo/blob/edaee60d28e0ac77b0d6f3ddef3770959df5553a/src/CZGL.SystemInfo/NetworkInfo.cs#L24 System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.) ---> System.NullReferenceException: Object reference not set to an instance of an object. at CZGL.SystemInfo.NetworkInfo.<.ctor>b3_3() at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy`1.CreateValue() at CZGL.ProcessMetrics.ProcessMetricsCore.b__12_0() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.<>c.<.cctor>b277_0(Object obj) at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location ---

whuanle commented 3 years ago

aspnet:5.0-alpine还没有测试过。 这样的, netinterface 接口,对 linux 的不好,在 windows 下基本没啥问题,在Linux下会经常获取不到数据或者出现异常。 晚上我回去排查,或者老哥帮忙提交一下修改?