Example #1
0
        /// <summary>
        /// Updates the varz structure with uptime, cpu, memory usage ....
        /// </summary>
        private void UpdateVarz()
        {
            TimeSpan span = DateTime.Now - RubyCompatibility.DateTimeFromRubyString((string)this.discover["start"]);

            this.Varz["uptime"] = string.Format(CultureInfo.InvariantCulture, "{0}d:{1}h:{2}m:{3}s", span.Days, span.Hours, span.Minutes, span.Seconds);

            float cpu = ((float)Process.GetCurrentProcess().TotalProcessorTime.Ticks / span.Ticks) * 100;

            // trim it to one decimal precision
            cpu = float.Parse(cpu.ToString("F1", CultureInfo.CurrentCulture), CultureInfo.CurrentCulture);

            this.Varz["cpu"] = cpu;
            this.Varz["mem"] = Process.GetCurrentProcess().WorkingSet64 / 1024;

            // extra uhuru information
            this.Varz["cpu_time"] = Process.GetCurrentProcess().TotalProcessorTime;

            // this is the cpu percentage for the time span between the Nextvalue calls;
            this.Varz["system_cpu"]       = this.CpuPerformance.NextValue();
            this.Varz["system_cpu_ticks"] = this.CpuPerformance.RawValue;

            // todo: add memory usage here
            // consider:
            // PerformanceCounter ramCounter;
            // ramCounter = new PerformanceCounter("Memory", "Available MBytes");
            // ramCounter.NextValue();
            this.Varz["system_mem"] = null;
        }
        /// <summary>
        /// Updates the discovery uptime.
        /// </summary>
        private void UpdateDiscoverUptime()
        {
            TimeSpan span = DateTime.Now - RubyCompatibility.DateTimeFromRubyString((string)this.discover["start"]);

            this.discover["uptime"] = string.Format(CultureInfo.InvariantCulture, "{0}d:{1}h:{2}m:{3}s", span.Days, span.Hours, span.Minutes, span.Seconds);
        }