Esempio n. 1
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);
        }
Esempio n. 2
0
        public static void Aggregate(this TelemetryCollection telemetryCollection, TelemetryPerformanceInstrumentation telPerfInstrumentation)
        {
            telemetryCollection.Aggregate(
                telPerfInstrumentation.TraceAggregationCfg,
                string.Empty,
                telPerfInstrumentation.Metrics,
                new Dictionary <string, string>(),
                DateTime.UtcNow);

            // the stop watch has to reset everytime the aggregation happens so that the accumulation in sum represents the total time
            // this is necessary so that it supports loading the accumulation from the persisted value.
            telPerfInstrumentation.ProcessingEventsMeasuredTimeReset();
        }