Ejemplo n.º 1
0
        private static void ProcessCounterEmit(CounterEmit emit)
        {
            // This is an expensive call, so make sure that we only make it once
            string counterName = emit.GetCounterName();
            int    hashCode    = CounterInstance.GetCounterHashCode(emit.Name, emit.Dimensions);

            CounterInstance instance;

            if (!instanceByNameCache.TryGetValue(counterName, out instance))
            {
                // The counter is not in the cache, so we need to get/create is in the database
                using (var db = new CounterDatabase())
                {
                    if (!TryGetInstanceFromDatabase(emit, hashCode, db, out instance))
                    {
                        CounterInstanceData counterInstanceData =
                            new CounterInstanceData()
                        {
                            Name             = emit.Name,
                            InstanceHashCode = hashCode
                        };

                        if (counterInstanceData.Dimensions == null)
                        {
                            counterInstanceData.Dimensions = new List <CounterDimensionData>();
                        }

                        foreach (KeyValuePair <string, string> emitDimension in emit.Dimensions)
                        {
                            counterInstanceData.Dimensions.Add(
                                new CounterDimensionData(emitDimension.Key, emitDimension.Value));
                        }

                        db.Instances.Add(counterInstanceData);
                        db.SaveChanges();

                        instance = new CounterInstance(counterInstanceData);
                    }

                    // Add the newly created/retrieved counter instance to the cache
                    // TODO: Where does the TTL go???
                    instanceByNameCache.TryAdd(counterName, instance);
                }
            }

            long ts = Convert.ToInt64(Math.Floor(emit.Timestamp.Subtract(Epoch).TotalSeconds));

            CounterValueSet valueSet;

            // Check if there is a valueSet for this particular timestamp. If not, add one
            if (!instance.Values.TryGetValue(ts, out valueSet))
            {
                valueSet = new CounterValueSet(emit.Value, 1);
                instance.Values.Add(ts, valueSet);
                return;
            }

            valueSet.Sum += emit.Value;
            valueSet.Count++;
        }
Ejemplo n.º 2
0
        internal Dictionary <long, CounterInstanceData> CreateActorMethodCounterInstanceData(
            List <KeyValuePair <long, MethodInfo> > methodInfoList,
            PerformanceCounterInstanceNameBuilder percCounterInstanceNameBuilder)
        {
            var actorMethodCounterInstanceData = new Dictionary <long, CounterInstanceData>();


            // Compute the counter instance names for all the actor methods
            var counterInstanceNames = percCounterInstanceNameBuilder.GetMethodCounterInstanceNames(methodInfoList);
            FabricPerformanceCounterSet actorMethodCounterSet;

            if (!AvaiableFabricCounterSet.TryGetValue(ActorPerformanceCounters.ActorMethodCategoryName,
                                                      out actorMethodCounterSet))
            {
                ActorTrace.Source.WriteWarning(
                    TraceType,
                    "PerformanceCounterSet not generated yet for category {0}",
                    ActorPerformanceCounters.ActorMethodCategoryName);
                return(null);
            }

            foreach (var kvp in counterInstanceNames)
            {
                var data = new CounterInstanceData {
                    InstanceName = kvp.Value
                };
                data.CounterWriters = this.CreateCounterWriters(data, actorMethodCounterSet);
                actorMethodCounterInstanceData[kvp.Key] = data;
            }
            return
                (actorMethodCounterInstanceData);
        }
Ejemplo n.º 3
0
        protected override void ProcessRecord()
        {
            DateTime epoch = new DateTime(1970, 1, 1);

            using (var db = new CounterDatabase())
            {
                List <CounterInstanceData> ins = db.Instances
                                                 .Where(i => i.Id == this.CounterId)
                                                 .Include(i => i.Dimensions)
                                                 .ToList();

                if (!ins.Any())
                {
                    throw new Exception("No counters found with ID " + this.CounterId);
                }

                CounterInstanceData instance = ins.First();

                foreach (var val in db.Values.Where(v => v.CounterInstanceId == instance.Id))
                {
                    SyncProCounterValue temp = new SyncProCounterValue
                    {
                        Count     = val.Count,
                        Timestamp = epoch.AddSeconds(val.Timestamp),
                        Value     = val.Value,
                    };

                    this.WriteObject(temp);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Obtiene la instancia de contador especificada
        /// </summary>
        /// <param name="categoryName">Nombre de la categoría</param>
        /// <param name="counterName">Nombre del contador</param>
        /// <param name="instanceName">Nombre de la instancia</param>
        /// <returns>Instancia de contador especificada o nula de lo contrario</returns>
        public static CounterInstanceData GetPerformanceCounterInstance(string categoryName,
                                                                        string counterName, string instanceName)
        {
            CounterInstanceData instanceData = null;

            if (HasCategory(categoryName))
            {
                instanceData = categoryDataList[categoryName].GetCounterInstance(counterName,
                                                                                 instanceName);
            }

            return(instanceData);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Incrementa en 1 la instancia del contador especificado
        /// </summary>
        /// <param name="categoryName">Nombre de la categoría del contador</param>
        /// <param name="counterName">Nombre del contador</param>
        /// <param name="instanceName">Nombre de la instancia del contador</param>
        public static void IncreaseCounter(string categoryName, string counterName,
                                           string instanceName)
        {
            if (isInitialized)
            {
                CounterInstanceData instanceData =
                    PerformanceCounterContainer.GetPerformanceCounterInstance(categoryName, counterName, instanceName);

                if (instanceData != null)
                {
                    instanceData.IncreaseCounter();
                }
            }
        }
Ejemplo n.º 6
0
        private MethodSpecificCounterWriters CreateCounterWriters(
            CounterInstanceData counterInstanceData,
            FabricPerformanceCounterSet ActorMethodCounterSet)
        {
            var logCounterWriterCreation = false;

            // We have not yet created the objects that write the counter values. So build
            // up the list of counter writers now.
            var instanceName       = counterInstanceData.InstanceName;
            var tempCounterWriters = new MethodSpecificCounterWriters();

            try
            {
                tempCounterWriters.ActorMethodCounterSetInstance =
                    ActorMethodCounterSet.CreateCounterSetInstance(instanceName);
            }
            catch (Exception ex)
            {
                //Instance creation failed, Be done.
                ActorTrace.Source.WriteWarning(
                    TraceType,
                    "Data for performance counter instance {0} of category {1} will not be provided because an exception occurred during its initialization. Exception info: {2}",
                    instanceName, ActorPerformanceCounters.ActorMethodCategoryName, ex);
                return(null);
            }

            tempCounterWriters.ActorMethodFrequencyCounterWriter = this.CreateMethodCounterWriter(
                instanceName,
                typeof(ActorMethodFrequencyCounterWriter),
                tempCounterWriters.ActorMethodCounterSetInstance,
                inst => new ActorMethodFrequencyCounterWriter(inst));
            tempCounterWriters.ActorMethodExceptionFrequencyCounterWriter = this.CreateMethodCounterWriter(
                instanceName,
                typeof(ActorMethodExceptionFrequencyCounterWriter),
                tempCounterWriters.ActorMethodCounterSetInstance,
                inst => new ActorMethodExceptionFrequencyCounterWriter(inst));
            tempCounterWriters.ActorMethodExecTimeCounterWriter = this.CreateMethodCounterWriter(
                instanceName,
                typeof(ActorMethodExecTimeCounterWriter),
                tempCounterWriters.ActorMethodCounterSetInstance,
                inst => new ActorMethodExecTimeCounterWriter(inst));
            logCounterWriterCreation = true;


            if (logCounterWriterCreation)
            {
                object[] newlyCreatedCounterWriters =
                {
                    tempCounterWriters.ActorMethodFrequencyCounterWriter,
                    tempCounterWriters.ActorMethodExceptionFrequencyCounterWriter,
                    tempCounterWriters.ActorMethodExecTimeCounterWriter
                };
                foreach (var newlyCreatedCounterWriter in newlyCreatedCounterWriters)
                {
                    if (null != newlyCreatedCounterWriter)
                    {
                        this.LogCounterInstanceCreationResult(
                            newlyCreatedCounterWriter.GetType(),
                            counterInstanceData.InstanceName,
                            null);
                    }
                }
            }

            return(tempCounterWriters);
        }