コード例 #1
0
        public void can_determine_if_are_same()
        {
            var first  = new CounterValue(10L);
            var second = new CounterValue(10L);

            first.Should().Be(second);
        }
コード例 #2
0
        public void Can_determine_if_diff_using_operator()
        {
            var first  = new CounterValue(10L);
            var second = new CounterValue(1L);

            Assert.True(first != second);
        }
コード例 #3
0
        public void can_determine_if_diff()
        {
            var first  = new CounterValue(10L);
            var second = new CounterValue(1L);

            first.Should().NotBe(second);
        }
コード例 #4
0
        public void can_determine_if_same_using_operator()
        {
            var first  = new CounterValue(10L);
            var second = new CounterValue(10L);

            Assert.True(first == second);
        }
コード例 #5
0
        public void hash_codes_same_for_same_instance()
        {
            var first  = new CounterValue(1);
            var second = first;

            Assert.Equal(first.GetHashCode(), second.GetHashCode());
        }
コード例 #6
0
        public void hash_codes_differ_between_instances()
        {
            var first  = new CounterValue(10L).GetHashCode();
            var second = new CounterValue(1L).GetHashCode();

            Assert.NotEqual(first, second);
        }
コード例 #7
0
        void UpdateListValues()
        {
            TreeIter it;

            if (seriesStore.GetIterFirst(out it))
            {
                do
                {
                    ChartSerieInfo ci = (ChartSerieInfo)seriesStore.GetValue(it, 3);
                    if (ci.Counter == null)
                    {
                        continue;
                    }
                    CounterValue val = ci.Counter.LastValue;
                    seriesStore.SetValue(it, 4, val.Value.ToString());

                    if (countChart.ActiveCursor != null)
                    {
                        val = ci.Counter.GetValueAt(new DateTime((long)countChart.ActiveCursor.Value));
                        seriesStore.SetValue(it, 5, val.Value.ToString());
                    }

                    val = ci.Counter.GetValueAt(new DateTime((long)countChart.SelectionStart.Value));
                    CounterValue val2 = ci.Counter.GetValueAt(new DateTime((long)countChart.SelectionEnd.Value));

                    seriesStore.SetValue(it, 6, (val2.Value - val.Value).ToString());
                }while (seriesStore.IterNext(ref it));
            }
        }
コード例 #8
0
        void FillValuesList()
        {
            listViewStore.Clear();
            List <ListViewValueInfo> values = new List <ListViewValueInfo> ();

            foreach (var serie in view.Series.Where(s => s.Visible))
            {
                foreach (CounterValue val in serie.Counter.GetValues())
                {
                    values.Add(new ListViewValueInfo()
                    {
                        Serie = serie, Value = val
                    });
                }
            }

            values.Sort(delegate(ListViewValueInfo v1, ListViewValueInfo v2) {
                return(v1.Value.TimeStamp.CompareTo(v2.Value.TimeStamp));
            });

            foreach (ListViewValueInfo vinfo in values)
            {
                CounterValue val  = vinfo.Value;
                string       time = val.TimeStamp.ToLongTimeString();
                listViewStore.AppendValues(vinfo, vinfo.Serie.ColorIcon, vinfo.Serie.Counter.Name, time, val.Value.ToString(), val.TotalCount.ToString(), val.HasTimerTraces ? val.Duration.TotalMilliseconds.ToString() : "");
            }
        }
コード例 #9
0
        public void reference_equality_should_be_correct()
        {
            var first  = new CounterValue(10L);
            var second = new CounterValue(1L);

            Assert.False(first.Equals((object)second));
        }
コード例 #10
0
        public static CounterValueSource ToMetricValueSource(this Counter source)
        {
            var items        = source.Items.Select(i => new CounterValue.SetItem(i.Item, i.Count, i.Percent)).ToArray();
            var counterValue = new CounterValue(source.Count, items);

            return(new CounterValueSource(source.Name, ConstantValue.Provider(counterValue), source.Unit, source.Tags));
        }
コード例 #11
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         CounterValue    = StartValue;
         lblCounter.Text = CounterValue.ToString();
     }
 }
コード例 #12
0
 public void SetMainCounter(Counter c, CounterValue value)
 {
     mainCounter = c;
     mainValue   = value;
     data        = null;
     Scale       = scale;
     QueueDraw();
 }
コード例 #13
0
ファイル: Agent.cs プロジェクト: Cylindric/Monitor
 public void ReportValue(CounterValue v)
 {
     using (var db = new Data())
     {
         db.CounterValues.Add(v);
         db.SaveChanges();
     }
 }
コード例 #14
0
        public CounterValueSource ToValueSource()
        {
            var items = this.items.Select(i => new CounterValue.SetItem(i.Item, i.Count, i.Percent))
              .ToArray();

            var counterValue = new CounterValue(this.Count, items);

            return new CounterValueSource(this.Name, ConstantValue.Provider(counterValue), this.Unit, this.Tags);
        }
コード例 #15
0
ファイル: JsonCounter.cs プロジェクト: sunkor/Metrics.NET-1
        public CounterValueSource ToValueSource()
        {
            var items = this.items.Select(i => new CounterValue.SetItem(i.Item, i.Count, i.Percent))
                        .ToArray();

            var counterValue = new CounterValue(this.Count, items);

            return(new CounterValueSource(this.Name, ConstantValue.Provider(counterValue), this.Unit, this.Tags));
        }
コード例 #16
0
        public TimeLineViewWindow(Counter c, CounterValue value) : base(Gtk.WindowType.Toplevel)
        {
            this.Build();
            this.mainCounter = c;
            this.mainValue   = value;
            timeView.Scale   = 300;

            Update();
        }
コード例 #17
0
        public void counter_value_with_null_set_items_throws()
        {
            Action setupAction = () =>
            {
                var unused = new CounterValue(10L, null);
            };

            setupAction.ShouldThrow <ArgumentNullException>();
        }
コード例 #18
0
        public void OnNext(CounterValue value)
        {
            using (var session = _documentStore.OpenSession())
            {
                session.Store(value);

                session.SaveChanges();
            }
        }
コード例 #19
0
ファイル: UtilCounter.cs プロジェクト: whztt07/mobahero_src
    public virtual CounterValue GetValue(int uid)
    {
        CounterValue result = null;

        if (!this._lookingTable.TryGetValue(uid, out result))
        {
            result = null;
        }
        return(result);
    }
コード例 #20
0
 public void OnNext(CounterValue value)
 {
     WriteFields(value.Time,
         (value.Time - _initialDate).TotalMilliseconds,
         value.Counter.Host,
         value.Counter.Type,
         value.Counter.Category,
         value.Counter.Instance,
         value.Counter.Name,
         value.Value);
 }
コード例 #21
0
ファイル: UtilCounter.cs プロジェクト: whztt07/mobahero_src
 public virtual void AddValue(int uid, CounterValue t)
 {
     if (this._lookingTable.ContainsKey(uid))
     {
         this._lookingTable[uid] = t;
     }
     else
     {
         this._lookingTable.Add(uid, t);
     }
 }
コード例 #22
0
 protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
 {
     if (value.Items.Length == 0)
     {
         Send(Name(name, unit), value.Count);
     }
     else
     {
         Send(SubfolderName(name, unit, "Total"), value.Count);
     }
 }
コード例 #23
0
        public void OnNext(CounterValue value)
        {
            string lastUpdate = string.Format("Last Update: {0}", value.Time.ToLongTimeString());

            lock (_lock)
            {
                UpdateConsoleRow(LAST_UPDATE_ROW, lastUpdate);

                var stats = GetStats(value);
                UpdateCounterStats(value.Counter, stats, value.Value);
            }
        }
コード例 #24
0
        protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
        {
            var itemProperties = value.Items.SelectMany(i => new[]
            {
                new JsonProperty(i.Item + " - Count", i.Count),
                new JsonProperty(i.Item + " - Percent", i.Percent),
            });

            Pack("Counter", name, unit, tags, new[] {
                new JsonProperty("Count", value.Count),
            }.Concat(itemProperties));
        }
コード例 #25
0
        protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
        {
            var itemProperties = value.Items.SelectMany(i => new[] 
            {
                new JsonProperty(i.Item + " - Count", i.Count), 
                new JsonProperty(i.Item + " - Percent", i.Percent),
            });

            Pack("Counter", name, unit, tags, new[] { 
                new JsonProperty("Count", value.Count),
            }.Concat(itemProperties));
        }
コード例 #26
0
        public CounterBox()
        {
            InitializeComponent();

            CounterValue = DefaultValue;

            CounterTextBox.SetBinding(TextBox.TextProperty, new Binding("CounterText")
            {
                Source = this,
                Mode   = BindingMode.TwoWay
            });
            CounterTextBox.Text = CounterValue.ToString();
        }
コード例 #27
0
        public void Update()
        {
            float cpu = 23;
            var   v   = new CounterValue {
                HostName   = mHost.HostName,
                TimeLogged = DateTime.Now,
                Category   = "CPU",
                Counter    = "Usage",
                Instance   = "CPU0",
                Value      = cpu
            };

            mHost.ReportValue(v);
        }
コード例 #28
0
        private void ReportCounter(CounterValueSource g)
        {
            string       name  = g.Name;
            CounterValue value = GetMetricValueSourceValue <CounterValue>(g.ValueProvider);
            Unit         unit  = g.Unit;

            var itemColumns = value.Items.SelectMany(i => new[] { i.Item + " - Count", i.Item + " - Percent" });
            var columns     = CounterColumns.Concat(itemColumns);

            var itemValues = value.Items.SelectMany(i => new object[] { i.Count, i.Percent });
            var values = new object[] { value.Count }.Concat(itemValues);

            Pack(name, columns, values, g.Tags);
        }
コード例 #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="value"></param>
 /// <param name="unit"></param>
 /// <param name="tags"></param>
 protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
 {
     // Metrics.NET counters can be decremented, but Prometheus' are expected to be monotonically increasing,
     // so this maps to a Prometheus gauge.
     if (_config.OutputSetItems && value.Items?.Length > 0)
     {
         var setItems = value.Items.Select(item => new SetItem(item.Item, item.Count));
         WriteLongMetricSet("gauge", name, setItems, unit, tags);
     }
     else
     {
         WriteLongMetric("gauge", name, value.Count, unit, tags);
     }
 }
コード例 #30
0
        private IEnumerable <CounterValueSource> SetupCounters()
        {
            var items = new[]
            {
                new CounterValue.SetItem("item1", 20, 10),
                new CounterValue.SetItem("item2", 40, 20),
                new CounterValue.SetItem("item3", 140, 70)
            };

            var counterValue = new CounterValue(200, items);
            var counter      = new CounterValueSource("test_counter", ConstantValue.Provider(counterValue), Unit.Items, Tags);

            return(new[] { counter });
        }
コード例 #31
0
        public void Metrics()
        {
            IMetrics metrics = AppMetrics.CreateDefaultBuilder().Build();

            CounterOptions counterOptions = new CounterOptions()
            {
                Context = "App",
                Name    = "Counter",
            };

            metrics.Measure.Counter.Increment(counterOptions);

            MetricsContextValueSource context = metrics.Snapshot.GetForContext("App");
            CounterValue counterValue1        = context.Counters.First().Value;
        }
コード例 #32
0
 protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
 {
     this.WriteMetricName(name);
     WriteValue("Count", unit.FormatCount(value.Count));
     if (value.Items.Length > 0)
     {
         WriteValue("Total Items", value.Items.Length.ToString());
     }
     for (int i = 0; i < value.Items.Length; i++)
     {
         var key = "Item " + i.ToString();
         var item = value.Items[i];
         var val = string.Format("{0:00.00}% {1,5} {2} [{3}]", item.Percent, item.Count, unit.Name, item.Item);
         WriteValue(key, val);
     }
 }
コード例 #33
0
 protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
 {
     this.WriteMetricName(name);
     WriteValue("Count", unit.FormatCount(value.Count));
     if (value.Items.Length > 0)
     {
         WriteValue("Total Items", value.Items.Length.ToString());
     }
     for (int i = 0; i < value.Items.Length; i++)
     {
         var key  = "Item " + i.ToString();
         var item = value.Items[i];
         var val  = $"{item.Percent:00.00}% {item.Count,5} {unit.Name} [{item.Item}]";
         WriteValue(key, val);
     }
 }
コード例 #34
0
        protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
        {
            if (_isDisposed)
            {
                return;
            }
            var itemProperties = value.Items.SelectMany(i => (new[]
            {
                new JsonProperty(SanitizeJsonPropertyName(i.Item) + "-Count", i.Count),
                new JsonProperty(SanitizeJsonPropertyName(i.Item) + "-Percent", i.Percent),
            }));

            Pack("Counter", name, unit, tags, new[] {
                new JsonProperty("Count", value.Count),
            }.Concat(itemProperties));

            Int64 lastValue;

            if (!CounterLastValue.TryGetValue(name, out lastValue))
            {
                lastValue = 0;
            }

            CounterLastValue[name] = value.Count;

            var itemPropertiesDiff = value.Items.SelectMany(i =>
            {
                var pName        = SanitizeJsonPropertyName(i.Item);
                var itemPropName = name + "-" + pName;
                Int64 pLastValue;
                if (!CounterPropertiesLastValue.TryGetValue(itemPropName, out pLastValue))
                {
                    lastValue = 0;
                }
                CounterPropertiesLastValue[itemPropName] = i.Count;

                var item = (new[]
                {
                    new JsonProperty(pName + "-Count", i.Count - pLastValue)
                });
                return(item);
            });

            Pack("CounterDiff", name, unit, tags, new[] {
                new JsonProperty("Count", value.Count - lastValue),
            }.Concat(itemPropertiesDiff));
        }
コード例 #35
0
        protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
        {
            if (value.Items.Length == 0)
            {
                Send(Name(name, unit), value.Count);
            }
            else
            {
                Send(SubfolderName(name, unit, "Total"), value.Count);
            }

            foreach (var item in value.Items)
            {
                Send(SubfolderName(name, unit, item.Item), item.Count);
                Send(SubfolderName(name, unit, item.Item, "Percent"), item.Percent);
            }
        }
コード例 #36
0
        protected void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
        {
            var payload = new JObject
            {
                { "count", value.Count }
            };

            value.Items.ForEach(i =>
            {
                payload.Add(i.Item + "Count", i.Count);
                payload.Add(i.Item + "Percent", i.Percent);
            });

            var te = Pack("Counter", name, unit, tags, payload);

            _subject.OnNext(te);
        }
コード例 #37
0
 public void OnNext(CounterValue value)
 {
     foreach (var o in _observers)
         o.OnNext(value);
 }
コード例 #38
0
        Stats GetStats(CounterValue counterValue)
        {
            string key = GetCounterShortName(counterValue.Counter);

            Stats row;
            if (_data.TryGetValue(key, out row))
            {
                row.CounterValues.Add(counterValue);
                return row;
            }
            else
                throw new ApplicationException("Counter not initialized on the observer");
        }
コード例 #39
0
 public void OnNext(CounterValue value)
 {
     int eventId = Interlocked.Increment(ref EventId);
     TraceSource.TraceEvent(TraceEventType.Information, eventId, string.Format("{0} {1} {2}", value.Time, value.Counter, value.Value));
 }
コード例 #40
0
ファイル: CSVReport.cs プロジェクト: 284247028/Metrics.NET
 protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
 {
     Write("Counter", name, CounterValues(value.Count, unit));
 }
コード例 #41
0
 public void OnNext(CounterValue value)
 {
     Console.WriteLine(string.Format("{0} {1} {2}", value.Time, value.Counter, value.Value));
 }
コード例 #42
0
 protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
 {
   this.metricName = name;
   base.ReportCounter(name, value, unit, tags);
 }