public virtual void TestInfoOverflow() { MetricsInfo i0 = Interns.Info("m0", "m desc"); for (int i = 0; i < MaxInfoNames + 1; ++i) { Interns.Info("m" + i, "m desc"); if (i < MaxInfoNames) { NUnit.Framework.Assert.AreSame("m0 is still there", i0, Interns.Info("m0", "m desc" )); } } NUnit.Framework.Assert.AreNotSame("m0 is gone", i0, Interns.Info("m0", "m desc")); MetricsInfo i1 = Interns.Info("m1", "m desc"); for (int i_1 = 0; i_1 < MaxInfoDescs; ++i_1) { Interns.Info("m1", "m desc" + i_1); if (i_1 < MaxInfoDescs - 1) { NUnit.Framework.Assert.AreSame("i1 is still there", i1, Interns.Info("m1", "m desc" )); } } NUnit.Framework.Assert.AreNotSame("i1 is gone", i1, Interns.Info("m1", "m desc")); }
public override T Register <T>(string name, string desc, T source) { lock (this) { MetricsSourceBuilder sb = MetricsAnnotations.NewSourceBuilder(source); MetricsSource s = sb.Build(); MetricsInfo si = sb.Info(); string name2 = name == null?si.Name() : name; string finalDesc = desc == null?si.Description() : desc; string finalName = DefaultMetricsSystem.SourceName(name2, !monitoring); // be friendly to non-metrics tests allSources[finalName] = s; Log.Debug(finalName + ", " + finalDesc); if (monitoring) { RegisterSource(finalName, finalDesc, s); } // We want to re-register the source to pick up new config when the // metrics system restarts. Register(finalName, new _AbstractCallback_238(this, finalName, finalDesc, s)); return(source); } }
// set to null as cannot figure out from Metric public virtual void Counter(MetricsInfo info, int value) { // MetricCounterInt.class ==> "int32" type = Int32; // counters have positive slope slope = AbstractGangliaSink.GangliaSlope.positive; }
public virtual void Counter(MetricsInfo info, long value) { // MetricCounterLong.class ==> "float" type = Float; // counters have positive slope slope = AbstractGangliaSink.GangliaSlope.positive; }
public static bool GetLastCalendarYearMetrics(MetricsInfo metricsInfo, int currentDate) { var year = GetYear(currentDate); var date = metricsInfo.Date; return(date > year * 360 && date <= currentDate); }
/// <summary> /// Instantiates a new /// <see cref="MutableQuantiles"/> /// for a metric that rolls itself /// over on the specified time interval. /// </summary> /// <param name="name">of the metric</param> /// <param name="description">long-form textual description of the metric</param> /// <param name="sampleName">type of items in the stream (e.g., "Ops")</param> /// <param name="valueName">type of the values</param> /// <param name="interval">rollover interval (in seconds) of the estimator</param> public MutableQuantiles(string name, string description, string sampleName, string valueName, int interval) { string ucName = StringUtils.Capitalize(name); string usName = StringUtils.Capitalize(sampleName); string uvName = StringUtils.Capitalize(valueName); string desc = StringUtils.Uncapitalize(description); string lsName = StringUtils.Uncapitalize(sampleName); string lvName = StringUtils.Uncapitalize(valueName); numInfo = Interns.Info(ucName + "Num" + usName, string.Format("Number of %s for %s with %ds interval" , lsName, desc, interval)); // Construct the MetricsInfos for the quantiles, converting to percentiles quantileInfos = new MetricsInfo[quantiles.Length]; string nameTemplate = ucName + "%dthPercentile" + uvName; string descTemplate = "%d percentile " + lvName + " with " + interval + " second interval for " + desc; for (int i = 0; i < quantiles.Length; i++) { int percentile = (int)(100 * quantiles[i].quantile); quantileInfos[i] = Interns.Info(string.Format(nameTemplate, percentile), string.Format (descTemplate, percentile)); } estimator = new SampleQuantiles(quantiles); this.interval = interval; scheduler.ScheduleAtFixedRate(new MutableQuantiles.RolloverSample(this), interval , interval, TimeUnit.Seconds); }
public override MetricsRecordBuilder Tag(MetricsInfo info, string value) { if (acceptable) { tags.AddItem(Interns.Tag(info, value)); } return(this); }
public override MetricsRecordBuilder AddCounter(MetricsInfo info, int value) { if (acceptable && (metricFilter == null || metricFilter.Accepts(info.Name()))) { metrics.AddItem(new MetricCounterInt(info, value)); } return(this); }
public static void AddMetrics(GameContext context, GameEntity c, MetricsInfo metricsInfo) { var metrics = c.metricsHistory; metrics.Metrics.Add(metricsInfo); c.ReplaceMetricsHistory(metrics.Metrics); }
/// <summary> /// Adds a gauge with a name built by using the specified phase's name as prefix /// and then appending the specified suffix. /// </summary> /// <param name="builder">MetricsRecordBuilder to receive counter</param> /// <param name="phase">Phase to add</param> /// <param name="nameSuffix">String suffix of metric name</param> /// <param name="descSuffix">String suffix of metric description</param> /// <param name="value">float gauge value</param> private static void AddGauge(MetricsRecordBuilder builder, Phase phase, string nameSuffix , string descSuffix, float value) { MetricsInfo metricsInfo = Interns.Info(phase.GetName() + nameSuffix, phase.GetDescription () + descSuffix); builder.AddGauge(metricsInfo, value); }
public override MetricsRecordBuilder AddGauge(MetricsInfo info, long value) { if (acceptable && (metricFilter == null || metricFilter.Accepts(info.Name()))) { metrics.AddItem(new MetricGaugeLong(info, value)); } return(this); }
/// <summary>Construct a metrics record</summary> /// <param name="info"> /// /// <see cref="MetricInfo"/> /// of the record /// </param> /// <param name="timestamp">of the record</param> /// <param name="tags">of the record</param> /// <param name="metrics">of the record</param> public MetricsRecordImpl(MetricsInfo info, long timestamp, IList <MetricsTag> tags , IEnumerable <AbstractMetric> metrics) { this.timestamp = Contracts.CheckArg(timestamp, timestamp > 0, "timestamp"); this.info = Preconditions.CheckNotNull(info, "info"); this.tags = Preconditions.CheckNotNull(tags, "tags"); this.metrics = Preconditions.CheckNotNull(metrics, "metrics"); }
public static bool GetLastCalendarQuarterMetrics(MetricsInfo metricsInfo, int currentDate) { var year = GetYear(currentDate); var quarter = (currentDate - year * 360) / 90; var date = metricsInfo.Date; return(date > year * 360 + quarter * 90 && date <= currentDate); }
internal MethodMetric(object obj, MethodInfo method, MetricsInfo info, Metric.Type type) { this.obj = Preconditions.CheckNotNull(obj, "object"); this.method = Contracts.CheckArg(method, Runtime.GetParameterTypes(method ).Length == 0, "Metric method should have no arguments"); this.info = Preconditions.CheckNotNull(info, "info"); impl = NewImpl(Preconditions.CheckNotNull(type, "metric type")); }
/// <summary>Create a mutable integer counter</summary> /// <param name="info">metadata of the metric</param> /// <param name="iVal">initial value</param> /// <returns>a new counter object</returns> public virtual MutableCounterInt NewCounter(MetricsInfo info, int iVal) { lock (this) { CheckMetricName(info.Name()); MutableCounterInt ret = new MutableCounterInt(info, iVal); metricsMap[info.Name()] = ret; return(ret); } }
/// <summary>Create a mutable long integer gauge</summary> /// <param name="info">metadata of the metric</param> /// <param name="iVal">initial value</param> /// <returns>a new gauge object</returns> public virtual MutableGaugeLong NewGauge(MetricsInfo info, long iVal) { lock (this) { CheckMetricName(info.Name()); MutableGaugeLong ret = new MutableGaugeLong(info, iVal); metricsMap[info.Name()] = ret; return(ret); } }
public override bool Equals(object obj) { if (obj is MetricsInfo) { MetricsInfo other = (MetricsInfo)obj; return(Objects.Equal(name, other.Name()) && Objects.Equal(description, other.Description ())); } return(false); }
internal MetricsRecordBuilderImpl(MetricsCollector parent, MetricsInfo info, MetricsFilter rf, MetricsFilter mf, bool acceptable) { this.parent = parent; timestamp = Time.Now(); recInfo = info; metrics = Lists.NewArrayList(); tags = Lists.NewArrayList(); recordFilter = rf; metricFilter = mf; this.acceptable = acceptable; }
public virtual MetricsRecordBuilderImpl AddRecord(MetricsInfo info) { bool acceptable = recordFilter == null || recordFilter.Accepts(info.Name()); MetricsRecordBuilderImpl rb = new MetricsRecordBuilderImpl(this, info, recordFilter , metricFilter, acceptable); if (acceptable) { rbs.AddItem(rb); } return(rb); }
/// <summary>Add a tag to the metrics</summary> /// <param name="info">metadata of the tag</param> /// <param name="value">of the tag</param> /// <param name="override">existing tag if true</param> /// <returns>the registry (for keep adding tags etc.)</returns> public virtual Org.Apache.Hadoop.Metrics2.Lib.MetricsRegistry Tag(MetricsInfo info , string value, bool @override) { lock (this) { if (!@override) { CheckTagName(info.Name()); } tagsMap[info.Name()] = Interns.Tag(info, value); return(this); } }
internal virtual MutableMetric NewForField(FieldInfo field, Metric annotation, MetricsRegistry registry) { if (Log.IsDebugEnabled()) { Log.Debug("field " + field + " with annotation " + annotation); } MetricsInfo info = GetInfo(annotation, field); MutableMetric metric = NewForField(field, annotation); if (metric != null) { registry.Add(info.Name(), metric); return(metric); } Type cls = field.FieldType; if (cls == typeof(MutableCounterInt)) { return(registry.NewCounter(info, 0)); } if (cls == typeof(MutableCounterLong)) { return(registry.NewCounter(info, 0L)); } if (cls == typeof(MutableGaugeInt)) { return(registry.NewGauge(info, 0)); } if (cls == typeof(MutableGaugeLong)) { return(registry.NewGauge(info, 0L)); } if (cls == typeof(MutableRate)) { return(registry.NewRate(info.Name(), info.Description(), annotation.Always())); } if (cls == typeof(MutableRates)) { return(new MutableRates(registry)); } if (cls == typeof(MutableStat)) { return(registry.NewStat(info.Name(), info.Description(), annotation.SampleName(), annotation.ValueName(), annotation.Always())); } throw new MetricsException("Unsupported metric field " + field.Name + " of type " + field.FieldType.FullName); }
internal virtual MutableMetric NewForMethod(object source, MethodInfo method, Metric annotation, MetricsRegistry registry) { if (Log.IsDebugEnabled()) { Log.Debug("method " + method + " with annotation " + annotation); } MetricsInfo info = GetInfo(annotation, method); MutableMetric metric = NewForMethod(source, method, annotation); metric = metric != null ? metric : new MethodMetric(source, method, info, annotation .Type()); registry.Add(info.Name(), metric); return(metric); }
private MetricsInfo[] GetGcInfo(string gcName) { MetricsInfo[] gcInfo = gcInfoCache[gcName]; if (gcInfo == null) { gcInfo = new MetricsInfo[2]; gcInfo[0] = Interns.Info("GcCount" + gcName, "GC Count for " + gcName); gcInfo[1] = Interns.Info("GcTimeMillis" + gcName, "GC Time for " + gcName); MetricsInfo[] previousGcInfo = gcInfoCache.PutIfAbsent(gcName, gcInfo); if (previousGcInfo != null) { return(previousGcInfo); } } return(gcInfo); }
private MetricsRegistry InitRegistry(object source) { Type cls = source.GetType(); MetricsRegistry r = null; // Get the registry if it already exists. foreach (FieldInfo field in ReflectionUtils.GetDeclaredFieldsIncludingInherited(cls )) { if (field.FieldType != typeof(MetricsRegistry)) { continue; } try { r = (MetricsRegistry)field.GetValue(source); hasRegistry = r != null; break; } catch (Exception e) { Log.Warn("Error accessing field " + field, e); continue; } } // Create a new registry according to annotation foreach (Annotation.Annotation annotation in cls.GetAnnotations()) { if (annotation is Metrics) { Metrics ma = (Metrics)annotation; info = factory.GetInfo(cls, ma); if (r == null) { r = new MetricsRegistry(info); } r.SetContext(ma.Context()); } } if (r == null) { return(new MetricsRegistry(cls.Name)); } return(r); }
internal ContainerMetrics(MetricsSystem ms, ContainerId containerId, long flushPeriodMs , long delayMs) { // Use a multiplier of 1000 to avoid losing too much precision when // converting to integers // This tracks overall CPU percentage of the machine in terms of percentage // of 1 core similar to top // Thus if you use 2 cores completely out of 4 available cores this value // will be 200 // Metrics publishing status // true if period elapsed // true if container finished // unregister // lazily initialized // Create a timer to unregister container metrics, // whose associated thread run as a daemon. this.recordInfo = Interns.Info(SourceName(containerId), RecordInfo.Description()); this.registry = new MetricsRegistry(recordInfo); this.metricsSystem = ms; this.containerId = containerId; this.flushPeriodMs = flushPeriodMs; this.unregisterDelayMs = delayMs < 0 ? 0 : delayMs; ScheduleTimerTaskIfRequired(); this.pMemMBsStat = registry.NewStat(PmemUsageMetricName, "Physical memory stats", "Usage", "MBs", true); this.cpuCoreUsagePercent = registry.NewStat(PhyCpuUsageMetricName, "Physical Cpu core percent usage stats" , "Usage", "Percents", true); this.milliVcoresUsed = registry.NewStat(VcoreUsageMetricName, "1000 times Vcore usage" , "Usage", "MilliVcores", true); this.pMemLimitMbs = registry.NewGauge(PmemLimitMetricName, "Physical memory limit in MBs" , 0); this.vMemLimitMbs = registry.NewGauge(VmemLimitMetricName, "Virtual memory limit in MBs" , 0); this.cpuVcoreLimit = registry.NewGauge(VcoreLimitMetricName, "CPU limit in number of vcores" , 0); }
/// <summary>Construct a sample statistics metric</summary> /// <param name="name">of the metric</param> /// <param name="description">of the metric</param> /// <param name="sampleName">of the metric (e.g. "Ops")</param> /// <param name="valueName">of the metric (e.g. "Time", "Latency")</param> /// <param name="extended">create extended stats (stdev, min/max etc.) by default.</param> public MutableStat(string name, string description, string sampleName, string valueName , bool extended) { string ucName = StringUtils.Capitalize(name); string usName = StringUtils.Capitalize(sampleName); string uvName = StringUtils.Capitalize(valueName); string desc = StringUtils.Uncapitalize(description); string lsName = StringUtils.Uncapitalize(sampleName); string lvName = StringUtils.Uncapitalize(valueName); numInfo = Interns.Info(ucName + "Num" + usName, "Number of " + lsName + " for " + desc); avgInfo = Interns.Info(ucName + "Avg" + uvName, "Average " + lvName + " for " + desc ); stdevInfo = Interns.Info(ucName + "Stdev" + uvName, "Standard deviation of " + lvName + " for " + desc); iMinInfo = Interns.Info(ucName + "IMin" + uvName, "Interval min " + lvName + " for " + desc); iMaxInfo = Interns.Info(ucName + "IMax" + uvName, "Interval max " + lvName + " for " + desc); minInfo = Interns.Info(ucName + "Min" + uvName, "Min " + lvName + " for " + desc); maxInfo = Interns.Info(ucName + "Max" + uvName, "Max " + lvName + " for " + desc); this.extended = extended; }
/// <summary>Construct the tag with name, description and value</summary> /// <param name="info">of the tag</param> /// <param name="value">of the tag</param> public MetricsTag(MetricsInfo info, string value) { this.info = Preconditions.CheckNotNull(info, "tag info"); this.value = value; }
Tag(MetricsInfo info, ContainerId containerId) { registry.Tag(info, containerId.ToString()); return(this); }
internal MutableCounterLong(MetricsInfo info, long initValue) : base(info) { this.value.Set(initValue); }
public virtual void TestInfo() { MetricsInfo info = Interns.Info("m", "m desc"); NUnit.Framework.Assert.AreSame("same info", info, Interns.Info("m", "m desc")); }