public static EventTelemetry CreateBaseEventTelemetry(
            TelemetryIdentifiers telemetryIdentifiers,
            string taskName,
            string eventName,
            int telBatchesDaily,
            int telBatchNumber,
            DateTime timestamp)
        {
            EventTelemetry eventEntity = new EventTelemetry(string.Format("{0}.{1}", taskName, eventName));

            try
            {
                eventEntity.Properties[ClusterIdStr]    = telemetryIdentifiers.ClusterId;
                eventEntity.Properties[TenantIdStr]     = telemetryIdentifiers.TenantId;
                eventEntity.Properties[NodeNameHashStr] = telemetryIdentifiers.NodeNameHash;
                eventEntity.Properties[TaskNameStr]     = taskName;
                eventEntity.Properties[EventNameStr]    = eventName;
                eventEntity.Properties[TimestampStr]    = timestamp.ToString();
                eventEntity.Metrics[TelBatchesStr]      = telBatchesDaily;
                eventEntity.Metrics[TelBatchNumberStr]  = telBatchNumber;
            }
            catch (ArgumentOutOfRangeException)
            {
                // add information about the exception to the event
                eventEntity.Properties["DateTimeToStringException"] = "true";
            }

            return(eventEntity);
        }
Esempio n. 2
0
        public TelemetryEtwSink(
            ITelemetryWriter telemetryWriter,
            string clusterId,
            string tenantId,
            string clusterType,
            string serviceFabricVersion,
            string nodeName,
            bool isScaleMin,
            TelemetryScheduler telemetryScheduler)
        {
            string clusterDevType = isScaleMin.ToString();

            this.telemetryWriter = telemetryWriter;

            // creating filter to only aggregate traces which are white-listed
            this.telemetryFilter = new TelemetryFilter();

            // creating the unique identifier of the cluster/node
            this.telemetryIdentifier = new TelemetryIdentifiers(clusterId, tenantId, nodeName);

            // getting path to where telemetry will be persisted
            Utility.CreateWorkSubDirectory(
                Utility.TraceSource,
                LogSourceId,
                TelemetryWorkSubDirectoryKey,
                AggregationPersistenceFolder,
                Utility.DcaWorkFolder,
                out this.telemetryPersistFilePath);

            this.telemetryPersistFilePath = Path.Combine(this.telemetryPersistFilePath, TelemetryEtwSink.TelemetryPersistFileName);

            // initializing the collection of telemetry (first it tries to load it from file, if fails an empty collection is created)
            bool telCollectionloadedFromDisk;

            this.telemetryCollection = TelemetryCollection.LoadOrCreateTelemetryCollection(this.telemetryPersistFilePath, this.telemetryIdentifier, telemetryScheduler.DailyPushes, out telCollectionloadedFromDisk, Utility.TraceSource.WriteError);

            // updating the scheduling for sending telemetry based on the persisted (or not persisted) telemetryCollection.
            telemetryScheduler.UpdateScheduler(telCollectionloadedFromDisk, this.telemetryCollection.TotalPushes > 0, this.telemetryCollection.PushTime, DateTime.Now.ToLocalTime().TimeOfDay);
            this.telemetryCollection.PushTime = telemetryScheduler.PushTime;

            // creating environment telemetry and including it in the collection
            this.environmentTelemetry = new EnvironmentTelemetry(
                clusterType,
                serviceFabricVersion,
                clusterDevType);

            this.telemetryCollection.Aggregate(this.environmentTelemetry);

            this.telemetryPerformanceInstrumentation = new TelemetryPerformanceInstrumentation();
            this.telemetryCollection.Aggregate(this.telemetryPerformanceInstrumentation);

            this.telemetryLock = new object();

            Utility.TraceSource.WriteInfo(LogSourceId, "{0}, Initial send telemetry delay of {1} at a frequency of every {2} minutes.", this.telemetryIdentifier, telemetryScheduler.SendDelay, telemetryScheduler.SendInterval.TotalMinutes);
            this.telemetrySendTimer = new System.Threading.Timer(this.SendTelemetry, null, telemetryScheduler.SendDelay, telemetryScheduler.SendInterval);
        }
        private static EventTelemetry ConvertAggregationToTelemetry(TraceAggregationConfig traceAggregationConfig, TraceAggregator traceAggregator, TelemetryIdentifiers telemetryIds, int telBatchesDaily, int telBatchNumber)
        {
            EventTelemetry eventEntity = AppInsightsTelemetryWriter.CreateBaseEventTelemetry(telemetryIds, traceAggregationConfig.TaskName, traceAggregationConfig.EventName, telBatchesDaily, telBatchNumber, traceAggregator.TraceTimestamp);

            Dictionary <string, string> properties;
            Dictionary <string, double> metrics;

            traceAggregator.CurrentFormattedFieldAggregationsValues(out properties, out metrics);

            foreach (var property in properties)
            {
                eventEntity.Properties[property.Key] = property.Value;
            }

            foreach (var metric in metrics)
            {
                eventEntity.Metrics[metric.Key] = metric.Value;
            }

            return(eventEntity);
        }