Esempio n. 1
0
        private static void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (!monitor.started)
            {
                monitor.Run();
            }

            var metricTask = Task.Run(() =>
            {
                List <string> monitoredApps = ConfigTools.GetConfiguredApps();
                foreach (string app in monitoredApps)
                {
                    Process[] processList = Process.GetProcessesByName(app);
                    if (!processList.IsNullOrEmpty())
                    {
                        foreach (Process processItem in processList)
                        {
                            Console.WriteLine($"name=Custom Metrics|Nodes|{System.Environment.MachineName}|Memory|{processItem.ProcessName}|Current Usage,aggregator=OBSERVATION,time-rollup=AVERAGE,cluster-rollup=INDIVIDUAL,value={processItem.WorkingSet64 / 1000}");
                            Console.WriteLine($"name=Custom Metrics|Nodes|{System.Environment.MachineName}|Memory|{processItem.ProcessName}|Current Committed,aggregator=OBSERVATION,time-rollup=AVERAGE,cluster-rollup=INDIVIDUAL,value={processItem.PeakWorkingSet64 / 1000}");
                            Console.WriteLine($"name=Custom Metrics|Nodes|{System.Environment.MachineName}|Process|{processItem.ProcessName}|Thread Count,aggregator=OBSERVATION,time-rollup=AVERAGE,cluster-rollup=INDIVIDUAL,value={processItem.Threads.Count}");
                            Console.WriteLine($"name=Custom Metrics|Nodes|{System.Environment.MachineName}|Process|{processItem.ProcessName}|Handles,aggregator=OBSERVATION,time-rollup=AVERAGE,cluster-rollup=INDIVIDUAL,value={processItem.HandleCount}");

                            Log($"name=Custom Metrics|Nodes|{System.Environment.MachineName}|Memory|{processItem.ProcessName}|Current Usage,aggregator=OBSERVATION,time-rollup=AVERAGE,cluster-rollup=INDIVIDUAL,value={processItem.WorkingSet64 / 1000}");
                            Log($"name=Custom Metrics|Nodes|{System.Environment.MachineName}|Memory|{processItem.ProcessName}|Current Committed,aggregator=OBSERVATION,time-rollup=AVERAGE,cluster-rollup=INDIVIDUAL,value={processItem.PeakWorkingSet64 / 1000}");
                            Log($"name=Custom Metrics|Nodes|{System.Environment.MachineName}|Process|{processItem.ProcessName}|Thread Count,aggregator=OBSERVATION,time-rollup=AVERAGE,cluster-rollup=INDIVIDUAL,value={processItem.Threads.Count}");
                            Log($"name=Custom Metrics|Nodes|{System.Environment.MachineName}|Process|{processItem.ProcessName}|Handles,aggregator=OBSERVATION,time-rollup=AVERAGE,cluster-rollup=INDIVIDUAL,value={processItem.HandleCount}");
                        }
                    }
                }
            });

            metricTask.Wait();
        }
 public void Init()
 {
     monitoredAppPools = ConfigTools.GetConfiguredAppPools();
     monitoredApps     = ConfigTools.GetConfiguredApps();
     console           = Boolean.Parse(ConfigurationManager.AppSettings["ConsoleOutput"]);
     api = Boolean.Parse(ConfigurationManager.AppSettings["APIOutput"]);
     Program.Log($"Configuration console:{console}, api:{api}");
 }