Ejemplo n.º 1
0
        private void RegisterPrintSpooler()
        {
            string categoryName = "Print Queue";
            PerformanceCounterCategory perfCategory = new PerformanceCounterCategory(categoryName);

            string[] instanceNames = perfCategory.GetInstanceNames().Where(name => name != "_Total").ToArray();
            foreach (string instanceName in instanceNames)
            {
                foreach (string counterName in new string[] { "Total Jobs Printed", "Jobs", "Job Errors" })
                {
                    System.Diagnostics.PerformanceCounter tmpPerfCounter = new System.Diagnostics.PerformanceCounter();
                    tmpPerfCounter.CategoryName = categoryName;
                    tmpPerfCounter.CounterName  = counterName;
                    tmpPerfCounter.InstanceName = instanceName;

                    string           metricName           = string.Format("perfmon_{0}_{1}_total", categoryName.Replace(" ", "_").ToLower().Trim(), counterName.Replace(" ", "_").ToLower().Trim());
                    Prometheus.Gauge tmpPrometheusCounter = Metrics.CreateGauge(metricName, "help text", labelNames: new[] { "name" });

                    CounterEntry entry = new CounterEntry()
                    {
                        PerfCounter = tmpPerfCounter, PrometheusCollector = tmpPrometheusCounter
                    };
                    this.RegisteredCounts.Add(entry);
                }
            }
        }
Ejemplo n.º 2
0
        public void RegisterMetrics()
        {
            // Load search interval from properties.
            TimeSpan rumpTime       = TimeSpan.FromSeconds(NodeCollector.WindowsBasic.Properties.Settings.Default.SearchRumpTime);
            TimeSpan searchInterval = TimeSpan.FromSeconds(NodeCollector.WindowsBasic.Properties.Settings.Default.SearchInvervalSeconds);

            GVars.MyLog.WriteEntry(string.Format("Initializing WindowsBasic collector v{0} (Search interval is {1}s, Rump time is {2}s).",
                                                 this.GetVersion(), searchInterval.TotalSeconds, rumpTime.TotalSeconds), EventLogEntryType.Information, 1000);

            /*
             * CPU
             */
            string categoryName = "Processor";
            PerformanceCounterCategory perfCategory = new PerformanceCounterCategory(categoryName);

            string[] instanceNames = perfCategory.GetInstanceNames().Where(name => name != "_Total").ToArray();
            foreach (string instanceName in instanceNames)
            {
                System.Diagnostics.PerformanceCounter tmpPerfCounter = new System.Diagnostics.PerformanceCounter();
                tmpPerfCounter.CategoryName = categoryName;
                tmpPerfCounter.CounterName  = "% Processor Time";
                tmpPerfCounter.InstanceName = instanceName;
                Prometheus.Gauge tmpPrometheusCounter = Metrics.CreateGauge("perfmon_processor_processortime_percent", "help text", labelNames: new[] { "name" });
                CounterEntry     entry = new CounterEntry()
                {
                    PerfCounter = tmpPerfCounter, PrometheusCollector = tmpPrometheusCounter
                };
                this.RegisteredCounts.Add(entry);
            }

            this.RegisterPrintSpooler();
            this.RegisterPrintSpooler();

            // Initialize a timer to search all XX minutes for new updates.
            // The process is very time intersive, so please do not lower this value below one hour.
            this.MetricUpdateTimer = new System.Threading.Timer(this.UpdateMetrics,
                                                                this,
                                                                Convert.ToInt32(rumpTime.TotalMilliseconds),
                                                                Convert.ToInt32(searchInterval.TotalMilliseconds)
                                                                );
        }