internal void FunctionCompleted(FunctionStartedEvent functionStartedEvent) { var functionStage = (functionStartedEvent.Success == false) ? ExecutionStage.Failed : ExecutionStage.Succeeded; long executionTimeInMS = (long)functionStartedEvent.Duration.TotalMilliseconds; var monitoringEvent = new FunctionMetrics(functionStartedEvent.FunctionMetadata.Name, functionStage, executionTimeInMS); _functionMetricsQueue.Enqueue(monitoringEvent); var key = GetDictionaryKey(functionStartedEvent.FunctionMetadata.Name, functionStartedEvent.InvocationId); if (_runningFunctions.ContainsKey(key)) { lock (_functionMetricEventLockObject) { if (_runningFunctions.ContainsKey(key)) { var functionInfo = _runningFunctions[key]; functionInfo.ExecutionStage = ExecutionStage.Finished; functionInfo.Success = functionStartedEvent.Success; var endTime = functionStartedEvent.Timestamp + functionStartedEvent.Duration; functionInfo.EndTime = functionStartedEvent.Timestamp + functionStartedEvent.Duration; RaiseFunctionMetricEvent(functionInfo, _runningFunctions.Keys.Count, endTime); _runningFunctions.Remove(key); } } } }
internal void FunctionStarted(FunctionStartedEvent startedEvent) { _totalExecutionCount++; var metricEventPerFunction = new FunctionMetrics(startedEvent.FunctionMetadata.Name, ExecutionStage.Started, 0); _functionMetricsQueue.Enqueue(metricEventPerFunction); var key = GetDictionaryKey(startedEvent.FunctionMetadata.Name, startedEvent.InvocationId); if (!_runningFunctions.ContainsKey(key)) { lock (_functionMetricEventLockObject) { if (!_runningFunctions.ContainsKey(key)) { _runningFunctions.Add(key, new RunningFunctionInfo(startedEvent.FunctionMetadata.Name, startedEvent.InvocationId, startedEvent.Timestamp, startedEvent.Success)); } } } }