Exemple #1
0
        // Called on success and failure
        public void End(bool success)
        {
            startedEvent.Success = success;
            string  eventName = success ? MetricEventNames.FunctionInvokeSucceeded : MetricEventNames.FunctionInvokeFailed;
            dynamic data      = new JObject();

            data.Language     = startedEvent.FunctionMetadata.Language;
            data.FunctionName = _metadata != null ? _metadata.Name : string.Empty;
            data.Success      = success;
            string jsonData = data.ToString();

            startedEvent.Data = jsonData;
            _metrics.LogEvent(eventName, startedEvent.FunctionName, jsonData);

            _metrics.EndEvent(startedEvent);

            if (invokeLatencyEvent != null)
            {
                MetricEvent metricEvent = invokeLatencyEvent as MetricEvent;
                if (metricEvent != null)
                {
                    metricEvent.Data = jsonData;
                }
                _metrics.EndEvent(invokeLatencyEvent);
            }
        }
    public static void QuizEnd(string quizid = "", string quizResult = "")
    {
        if (answeredQuestions == null)
        {
            answeredQuestions = new List <AnswerQuizQuestion>();
        }

        MetricEvent newEvent   = new MetricEvent();
        QuizEnd     metricData = new QuizEnd(quizid, quizResult, answeredQuestions, DateTime.Now.Subtract(lastActionTime).TotalSeconds);

        newEvent.SetEventInfo(uuid, user, sessionID, null);

        newEvent.Timestamp(DateTime.UtcNow);
        newEvent.Data(metricData);

        //Keep a tally of the events in a session in the case of time race conditions to still know which event occured first
        newEvent.SessionIndex(sessionMetricList.Count);

        sessionMetricList.Add(newEvent);

        APIManager.SubmitMetrics((new MetricEvent[1] {
            newEvent
        }), (res) => HandleResponse(res));
        sessioncount++;
    }
    public static void AnswerQuizQuestion(string quizid = "", string answerid = "", string answerGiven = "", string answerResult = "")
    {
        if (answeredQuestions == null)
        {
            answeredQuestions = new List <AnswerQuizQuestion>();
        }

        MetricEvent        newEvent   = new MetricEvent();
        AnswerQuizQuestion metricData = new AnswerQuizQuestion(answerid, answerGiven, answerResult);

        newEvent.SetEventInfo(uuid, user, sessionID, null);

        newEvent.Timestamp(DateTime.UtcNow);
        newEvent.Data(metricData);

        //Keep a tally of the events in a session in the case of time race conditions to still know which event occured first
        newEvent.SessionIndex(sessionMetricList.Count);



        answeredQuestions.Add(metricData);

        if (isSending == true)
        {
            APIManager.SubmitMetrics((new MetricEvent[1] {
                newEvent
            }), (res) => HandleResponse(res));
        }
        sessioncount++;
    }
    public static void GenericEvent(string actionid = "", string data = "")
    {
        if (sessionMetricList == null)
        {
            sessionMetricList = new List <MetricEvent>();
        }

        MetricEvent newEvent = new MetricEvent();

        newEvent.SetEventInfo(uuid, user, sessionID, null);
        GenericEvent metricData = new GenericEvent(actionid, data);

        newEvent.Timestamp(DateTime.UtcNow);
        newEvent.Data(metricData);

        //Keep a tally of the events in a session in the case of time race conditions to still know which event occured first
        newEvent.SessionIndex(sessionMetricList.Count);


        //add it to the list of events this session
        sessionMetricList.Add(newEvent);
        //set the last action to have the duration easily accesible for the event end
        lastActionTime = newEvent.Timestamp();

        //TODO: attempt to upload to database
        //if fail then save

        APIManager.SubmitMetrics((new MetricEvent[1] {
            newEvent
        }), (res) => HandleResponse(res));
        sessioncount++;
    }
 public void Send(MetricEvent @event)
 {
     lock (sent)
     {
         sent.Add(@event);
     }
 }
Exemple #6
0
 public void BeginEvent(MetricEvent metricEvent)
 {
     if (metricEvent is FunctionStartedEvent startedEvent)
     {
         startedEvent.Timestamp = DateTime.UtcNow;
         _metricsEventManager.FunctionStarted(startedEvent);
     }
 }
Exemple #7
0
        public void LogEvent(MetricEvent metricEvent)
        {
            HostStarted hostStartedEvent = metricEvent as HostStarted;

            if (hostStartedEvent != null)
            {
                _metricsEventManager.HostStarted(hostStartedEvent.Host);
            }
        }
        public void EndEvent(MetricEvent metricEvent)
        {
            FunctionStartedEvent completedEvent = metricEvent as FunctionStartedEvent;

            if (completedEvent != null)
            {
                completedEvent.EndTime = DateTime.Now;
                _metricsEventManager.FunctionCompleted(completedEvent);
            }
        }
Exemple #9
0
        public void Send(MetricEvent @event)
        {
            if (!string.IsNullOrEmpty(@event.AggregationType) && !AllowedAggregationTypes.Contains(@event.AggregationType))
            {
                return;
            }

            lock (sync)
                events.Add(@event);
        }
        public void SendMetric(MetricEvent metricEvent)
        {
            var routingKey = RoutingKey.TryAddSuffix(routingKeyPrefix, RoutingKey.MetricsSuffix);

            if (airlockClient == null || string.IsNullOrEmpty(routingKey))
            {
                return;
            }
            airlockClient.Push(routingKey, metricEvent, metricEvent.Timestamp);
        }
Exemple #11
0
        public void BeginEvent(MetricEvent metricEvent)
        {
            FunctionStartedEvent startedEvent = metricEvent as FunctionStartedEvent;

            if (startedEvent != null)
            {
                startedEvent.Timestamp = DateTime.UtcNow;
                _metricsEventManager.FunctionStarted(startedEvent);
            }
        }
Exemple #12
0
 static void OutputMessageInfo(string action, EventData data, MetricEvent info)
 {
     if (data == null)
     {
         return;
     }
     if (info != null)
     {
         Trace.TraceInformation("{0}: Device {1}, Temperature {2}.", action, info.DeviceId, info.Temperature);
     }
 }
 public void EndEvent(MetricEvent metricEvent)
 {
     if (metricEvent is FunctionStartedEvent completedEvent)
     {
         _metricsEventManager.FunctionCompleted(completedEvent);
     }
     else
     {
         _metricsEventManager.EndEvent(metricEvent);
     }
 }
Exemple #14
0
 public void EndEvent(MetricEvent metricEvent)
 {
     if (metricEvent is FunctionStartedEvent completedEvent)
     {
         completedEvent.Duration = DateTime.UtcNow - completedEvent.Timestamp;
         _metricsEventManager.FunctionCompleted(completedEvent);
     }
     else
     {
         _metricsEventManager.EndEvent(metricEvent);
     }
 }
Exemple #15
0
        static void OutputMessageInfo(string action, EventData data, MetricEvent info)
        {
            if (data == null)
            {
                return;
            }

            if (info != null)
            {
                Console.WriteLine("{0}{1} - Device {2}.", action, data, info.DeviceId);
            }
        }
Exemple #16
0
        public void ProcessMetricEvent(MetricEvent metricEvent)
        {
            var bucketKeys     = bucketKeyProvider.GetBucketKeys(metricEvent.Tags);
            var currentBorders = Interlocked.CompareExchange(ref borders, null, null);

            foreach (var bucketKey in bucketKeys)
            {
                var bucket = buckets.GetOrAdd(
                    bucketKey,
                    bk => new Bucket(aggregatorMetrics, bk.Tags, 1.Minutes(), cooldownPeriod, currentBorders));
                bucket.Consume(metricEvent.Values, metricEvent.Timestamp);
            }
        }
Exemple #17
0
        private static string FormatMetricsBody(MetricEvent metrics)
        {
            if (metrics.IsError)
            {
                var error = metrics.Error;
                return(error.GetType().Name + ": " + error.Message);
            }

            var jobIdFormatLength = metrics.JobIds.Max(id => id.Length);
            var jobInfos          = metrics.JobIds.Select(id => FormatJobMetrics(id, metrics.GetMetrics(id), jobIdFormatLength));

            return(String.Join(Environment.NewLine, jobInfos));
        }
        /// <inheritdoc />
        public void Write(string name, double metric, [CallerFilePath] string callerPath = null, [CallerMemberName] string callerMemberName = null, [CallerLineNumber] int callerLineNumber = 0)
        {
            var applicationEvent = new MetricEvent(
                name,
                metric,
                null,
                callerPath,
                callerMemberName,
                callerLineNumber);

            this.writer.Write(applicationEvent);
            EventLogged?.Invoke(this, new EventLoggedEventArgs(applicationEvent));
        }
Exemple #19
0
 public override void Flush()
 {
     while (this.Queue.TryDequeue(out var applicationEvent))
     {
         Console.ForegroundColor = applicationEvent switch
         {
             ExceptionEvent _ => ConsoleColor.Red,
             MetricEvent _ => ConsoleColor.Cyan,
                                     _ => ConsoleColor.White,
         };
         Console.Write(applicationEvent);
         Console.ResetColor();
     }
 }
Exemple #20
0
        public void EndEvent(MetricEvent metricEvent)
        {
            FunctionStartedEvent completedEvent = metricEvent as FunctionStartedEvent;

            if (completedEvent != null)
            {
                completedEvent.Duration = DateTime.UtcNow - completedEvent.Timestamp;
                _metricsEventManager.FunctionCompleted(completedEvent);
            }
            else
            {
                _metricsEventManager.EndEvent((object)metricEvent);
            }
        }
Exemple #21
0
        public void Add(MetricEvent @event)
        {
            lastEvent = @event;

            var bucket = @event.AggregationParameters.GetHistogramBucket();

            if (bucket == null)
            {
                return;
            }

            if (!buckets.ContainsKey(bucket.Value))
            {
                buckets[bucket.Value] = 0;
            }
            buckets[bucket.Value] += @event.Value;
        }
        public IEnumerable <MetricEvent> Aggregate(DateTimeOffset timestamp)
        {
            if (lastEvent == null)
            {
                return(Enumerable.Empty <MetricEvent>());
            }

            var result = new MetricEvent(
                count,
                lastEvent.Tags,
                timestamp,
                lastEvent.Unit,
                null,
                null);

            return(new[] { result });
        }
        public static void SendEvent(MetricEvent info)
        {
            try
            {
                var caCerts = new X509Certificate[] { new X509Certificate(Resources.GetBytes(Resources.BinaryResources.Baltimore)) };

                var eventHubAddressHttps = "https://" + VehicleConfig.ServiceNamespace + ".servicebus.windows.net/"
                                           + VehicleConfig.HubName + "/publishers/" + VehicleConfig.DeviceId + "/messages";

                Debug.Print(eventHubAddressHttps);

                var request = (HttpWebRequest)HttpWebRequest.Create(eventHubAddressHttps);
                {
                    string sasToken = CreateSasToken(eventHubAddressHttps, VehicleConfig.KeyName, VehicleConfig.Key);
                    request.Headers.Add("Authorization", sasToken);
                    request.Headers.Add("ContentType", "application/atom+xml;type=entry;charset=utf-8");
                    request.Method = "POST";

                    request.HttpsAuthentCerts = caCerts;
                    request.KeepAlive         = true;

                    string serializedObject = JsonSerializer.SerializeObject(info);
                    Debug.Print(serializedObject);

                    byte[] buffer = Encoding.UTF8.GetBytes(serializedObject);

                    request.ContentLength = buffer.Length;

                    // request body
                    using (Stream stream = request.GetRequestStream())
                    {
                        stream.Write(buffer, 0, buffer.Length);
                    }

                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        Debug.Print("HTTP Status:" + response.StatusCode + " : " + response.StatusDescription);
                    }
                }
            }
            catch (WebException we)
            {
                Debug.Print(we.Message);
            }
        }
    public static void AskInstructorQuestion(string courseid = "", string instructorid = "", string questionid = "")
    {
        MetricEvent           newEvent   = new MetricEvent();
        AskInstructorQuestion metricData = new AskInstructorQuestion(courseid, instructorid, questionid);

        newEvent.SetEventInfo(uuid, user, sessionID, null);

        newEvent.Timestamp(DateTime.UtcNow);
        newEvent.Data(metricData);

        if (isSending == true)
        {
            APIManager.SubmitMetrics((new MetricEvent[1] {
                newEvent
            }), (res) => HandleResponse(res));
        }
        sessioncount++;
    }
    public static void ActivityStart(string activityid = "")
    {
        MetricEvent   newEvent   = new MetricEvent();
        ActivityStart metricData = new ActivityStart(activityid);

        newEvent.SetEventInfo(uuid, user, sessionID, null);

        newEvent.Timestamp(DateTime.UtcNow);
        newEvent.Data(metricData);

        //Keep a tally of the events in a session in the case of time race conditions to still know which event occured first
        newEvent.SessionIndex(sessionMetricList.Count);

        APIManager.SubmitMetrics((new MetricEvent[1] {
            newEvent
        }), (res) => HandleResponse(res));
        sessioncount++;
    }
    public static void GainBadge(string badgeid = "", string newteam = "", string newawardedby = "")
    {
        MetricEvent newEvent   = new MetricEvent();
        GainBadge   metricData = new GainBadge(badgeid, newteam, newawardedby);

        newEvent.SetEventInfo(uuid, user, sessionID, null);

        newEvent.Timestamp(DateTime.UtcNow);
        newEvent.Data(metricData);

        //Keep a tally of the events in a session in the case of time race conditions to still know which event occured first
        newEvent.SessionIndex(sessionMetricList.Count);


        APIManager.SubmitMetrics((new MetricEvent[1] {
            newEvent
        }), (res) => HandleResponse(res));
        sessioncount++;
    }
    public static void LeaveCourse(string courseid = "", string result = "", string awards = "", float progress = 0.0f)
    {
        MetricEvent newEvent   = new MetricEvent();
        LeaveCourse metricData = new LeaveCourse(courseid, result, awards, progress);

        newEvent.SetEventInfo(uuid, user, sessionID, null);

        newEvent.Timestamp(DateTime.UtcNow);
        newEvent.Data(metricData);

        //Keep a tally of the events in a session in the case of time race conditions to still know which event occured first
        newEvent.SessionIndex(sessionMetricList.Count);


        APIManager.SubmitMetrics((new MetricEvent[1] {
            newEvent
        }), (res) => HandleResponse(res));
        sessioncount++;
    }
    //have the id be optional so the event can be logged even in there is unknown information
    public static void QuizStart(string quizid = "")
    {
        if (sessionMetricList == null)
        {
            sessionMetricList = new List <MetricEvent>();
        }
        if (answeredQuestions == null)
        {
            answeredQuestions = new List <AnswerQuizQuestion>();
        }
        else
        {
            //clear any questions from a previous quiz
            answeredQuestions.Clear();
        }


        MetricEvent newEvent = new MetricEvent();

        //newEvent.SetEventInfo("FFFFFFFFF", user, "12ss", null);
        newEvent.SetEventInfo(uuid, user, sessionID, null);
        QuizStart metricData = new QuizStart(quizid);

        newEvent.Timestamp(DateTime.UtcNow);
        newEvent.Data(metricData);

        //Keep a tally of the events in a session in the case of time race conditions to still know which event occured first
        newEvent.SessionIndex(sessionMetricList.Count);


        //add it to the list of events this session
        sessionMetricList.Add(newEvent);
        //set the last action to have the duration easily accesible for the event end
        lastActionTime = newEvent.Timestamp();

        //TODO: attempt to upload to database
        //if fail then save

        APIManager.SubmitMetrics((new MetricEvent[1] {
            newEvent
        }), (res) => HandleResponse(res));
        sessioncount++;
    }
Exemple #29
0
        public void SendEvents()
        {
            // Create EventHubClient
            EventHubClient client = EventHubClient.Create(this.eventHubName);

            try
            {
                List <Task> tasks = new List <Task>();

                // Send messages to Event Hub
                Trace.TraceInformation("Sending messages to Event Hub " + client.Path);

                Random random = new Random();
                for (int i = 0; i < this.numberOfMessages; ++i)
                {
                    // Create the device/temperature metric
                    MetricEvent info = new MetricEvent()
                    {
                        DeviceId = random.Next(numberOfDevices), Temperature = random.Next(100)
                    };
                    var serializedString = JsonConvert.SerializeObject(info);

                    EventData data = new EventData(Encoding.UTF8.GetBytes(serializedString));

                    // Set user properties if needed
                    data.Properties.Add("Type", "Telemetry_" + DateTime.Now.ToLongTimeString());
                    OutputMessageInfo("SENDING: ", data, info);

                    // Send the metric to Event Hub
                    tasks.Add(client.SendAsync(data));
                }
                ;

                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception exp)
            {
                Trace.TraceError("Error on send: " + exp.Message);
            }

            client.CloseAsync().Wait();
        }
    public static void AnswerInstructorQuestion(string courseid = "", string instructorid = "", string questionid = "", string answer = "", string result = "")
    {
        MetricEvent newEvent = new MetricEvent();
        AnswerInstructorQuestion metricData = new AnswerInstructorQuestion(courseid, instructorid, questionid, answer, result);

        newEvent.SetEventInfo(uuid, user, sessionID, null);

        newEvent.Timestamp(DateTime.UtcNow);
        newEvent.Data(metricData);

        //Keep a tally of the events in a session in the case of time race conditions to still know which event occured first
        newEvent.SessionIndex(sessionMetricList.Count);
        if (isSending == true)
        {
            APIManager.SubmitMetrics((new MetricEvent[1] {
                newEvent
            }), (res) => HandleResponse(res));
        }
        sessioncount++;
    }
 public void BeginEvent(MetricEvent metricEvent)
 {
 }
 public void EndEvent(MetricEvent metricEvent)
 {
 }
 public void LogEvent(MetricEvent metricEvent)
 {
 }