Пример #1
0
        internal void UpdateDiagInfo(TheServiceHealthData pMyHealthData)
        {
            if (pMyHealthData == null || TheCommonUtils.cdeIsLocked(UpdateDiagInfoLock))
            {
                return;
            }
            lock (UpdateDiagInfoLock)
            {
                //uint s;
                //GetCurrentCoreInfo(out t, out s);
                //pMyHealthData.cdeTemp = t;
                //pMyHealthData.cdeSpeed = s;

                double tTemp  = 0;
                long   tSpeed = 0;
                pMyHealthData.CoreTemps  = "";
                pMyHealthData.CoreSpeeds = "";
                if (MyCPUInfoData.NumberOfCores == 0)
                {
                    MyCPUInfoData.NumberOfCores = 1;
                }
                for (int i = 0; i < MyCPUInfoData.NumberOfCores; i++)
                {
                    Thread thread = new Thread(new ParameterizedThreadStart(GetCoreInfo))
                    {
                        Name         = "GetCoreInfo" + (i + 1).ToString(),
                        IsBackground = true
                    };
                    thread.Start(i);
                    thread.Join();
                    thread  = null;
                    tTemp  += MyCoreTemps[i];
                    tSpeed += MyCoreSpeeds[i];
                    if (i > 0)
                    {
                        pMyHealthData.CoreSpeeds += ",";
                    }
                    pMyHealthData.CoreSpeeds += MyCoreSpeeds[i].ToString();
                    if (i > 0)
                    {
                        pMyHealthData.CoreTemps += ",";
                    }
                    pMyHealthData.CoreTemps += MyCoreTemps[i].ToString();
                }
                if (MyCPUInfoData.NumberOfCores > 0)
                {
                    pMyHealthData.CPUTemp  = tTemp / MyCPUInfoData.NumberOfCores;
                    pMyHealthData.CPUSpeed = tSpeed / MyCPUInfoData.NumberOfCores;
                }
                else
                {
                    pMyHealthData.CPUTemp  = tTemp;
                    pMyHealthData.CPUSpeed = tSpeed;
                }
            }
        }
Пример #2
0
        private void sinkNewData(TheServiceHealthData pHealth)
        {
            List <TheChartPoint> tb = new List <TheChartPoint> {
                new TheChartPoint {
                    value = pHealth.CPULoad.cdeTruncate(2), name = "CPU Load"
                },
                new TheChartPoint {
                    value = pHealth.cdeLoad.cdeTruncate(2), name = "CDE Load"
                }
            };

            //TheThing.SetSafePropertyNumber(MyBaseThing, "LoadBucket", pHealth.CPULoad.cdeTruncate(2));
            TheThing.SetSafePropertyString(MyBaseThing, "LoadBucket", TheCommonUtils.SerializeObjectToJSONString(tb));// pHealth.cdeLoad.cdeTruncate(2) +";1");
            MyServiceHealth.HealthUpdateCycle = HealthCollectionCycle;
        }
Пример #3
0
        private void InitHealthCollection()
        {
            if (MyHealthData != null)
            {
                return;
            }

            MyHealthData  = new TheServiceHealthData(MyEngineName, System.Environment.MachineName);
            MyCPUInfoData = new TheCPUInfo(MyEngineName, System.Environment.MachineName);

            // PerformanceCounterCategory[] perfCats = PerformanceCounterCategory.GetCategories();

            if (mDisableCollection)
            {
                return;
            }
            SendCPUInfo(Guid.Empty);
            SendHealthInfo(Guid.Empty);

            try
            {
                MyCPULoadCounter = new PerformanceCounter
                {
                    CategoryName = "Processor Information",
                    CounterName  = "% Processor Time",
                    InstanceName = "_Total"
                };
            }
            catch (Exception e)
            {
                TheBaseAssets.MySYSLOG.WriteToLog(8006, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("jcHealth", "Cannot create CPU Counter", eMsgLevel.l1_Error, e.ToString()));
            }
            try
            {
                MyCDELoadCounter = new PerformanceCounter
                {
                    CategoryName = "Process",
                    CounterName  = "% Processor Time",
                    InstanceName = Process.GetCurrentProcess().ProcessName
                };
            }
            catch (Exception e)
            {
                TheBaseAssets.MySYSLOG.WriteToLog(8006, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("jcHealth", "Cannot Create Load Counter", eMsgLevel.l1_Error, e.ToString()));
            }
            MyCounter   = new List <ThePerfCounter>();
            UseNicState = true;

            //try
            //{
            //    var readBytesSec = new PerformanceCounter("Process", "IO Read Bytes/sec", Process.GetCurrentProcess().ProcessName);
            //    if (readBytesSec != null)
            //        MyCounter.Add(new ThePerfCounter { PerfCounter = readBytesSec, PropertyName = "NetRead" });
            //    var writeByteSec = new PerformanceCounter("Process", "IO Write Bytes/sec", Process.GetCurrentProcess().ProcessName);
            //    if (writeByteSec != null)
            //        MyCounter.Add(new ThePerfCounter { PerfCounter = readBytesSec, PropertyName = "NetWrite" });
            //}
            //catch (Exception e)
            //{
            //    UseNicState = true;
            //    TheBaseAssets.MySYSLOG.WriteToLog(8006, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("jcHealth", "Cannot Create Net Counter - fallback to NIC state", eMsgLevel.l1_Error, e.ToString()));
            //}

            try
            {
                wmiObjectWin32 = new ManagementObjectSearcher("select * from Win32_OperatingSystem");
            }
            catch (Exception)
            {
            }
            StartProcessCPUMeasure();

            AreCounterInit = true;
        }