public void Begin(IDbLogger connection)
        {
            var counters = new[]
                {
                    new KeyValuePair<string, PerformanceCounter>("CpuTime", new PerformanceCounter("Processor", "% Processor Time", "_Total")),
                    new KeyValuePair<string, PerformanceCounter>("FreeSpace", new PerformanceCounter("LogicalDisk", "% Free Space", "_Total")),
                    new KeyValuePair<string, PerformanceCounter>("MemoryInUse", new PerformanceCounter("Memory", "% Committed Bytes In Use"))
                };

            counters.Select(counter => counter.Value.NextValue());

            _disposable = Observable.Interval(TimeSpan.FromSeconds(5)).Subscribe(l =>
                {
                    foreach (var counter in counters)
                    {
                        var jsonData = new Counter
                            {
                                MachineName = Environment.MachineName,
                                Name = string.Format("{0}_{1}_{2}", counter.Value.CategoryName, counter.Value.CounterName, counter.Value.InstanceName),
                                StatName = counter.Key,
                                Value = counter.Value.NextValue(),
                                Date = _time.Now
                            };

                        connection.LogCounter(jsonData);
                    }
                });
        }
Example #2
0
        public void Begin(IDbLogger connection)
        {
            var counters = new[]
            {
                new KeyValuePair <string, PerformanceCounter>("CpuTime", new PerformanceCounter("Processor", "% Processor Time", "_Total")),
                new KeyValuePair <string, PerformanceCounter>("FreeSpace", new PerformanceCounter("LogicalDisk", "% Free Space", "_Total")),
                new KeyValuePair <string, PerformanceCounter>("MemoryInUse", new PerformanceCounter("Memory", "% Committed Bytes In Use"))
            };

            counters.Select(counter => counter.Value.NextValue());

            _disposable = Observable.Interval(TimeSpan.FromSeconds(5)).Subscribe(l =>
            {
                foreach (var counter in counters)
                {
                    var jsonData = new Counter
                    {
                        MachineName = Environment.MachineName,
                        Name        = string.Format("{0}_{1}_{2}", counter.Value.CategoryName, counter.Value.CounterName, counter.Value.InstanceName),
                        StatName    = counter.Key,
                        Value       = counter.Value.NextValue(),
                        Date        = _time.Now
                    };

                    connection.LogCounter(jsonData);
                }
            });
        }