예제 #1
0
        public Task <ActionResult> GetDump(
            ProcessFilter?processFilter,
            [FromQuery] DumpType type         = DumpType.WithHeap,
            [FromQuery] string egressProvider = null)
        {
            return(InvokeForProcess(async processInfo =>
            {
                string dumpFileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
                                      FormattableString.Invariant($"dump_{GetFileNameTimeStampUtcNow()}.dmp") :
                                      FormattableString.Invariant($"core_{GetFileNameTimeStampUtcNow()}");

                if (string.IsNullOrEmpty(egressProvider))
                {
                    Stream dumpStream = await _diagnosticServices.GetDump(processInfo, type, HttpContext.RequestAborted);

                    //Compression is done automatically by the response
                    //Chunking is done because the result has no content-length
                    return File(dumpStream, ContentTypes.ApplicationOctectStream, dumpFileName);
                }
                else
                {
                    KeyValueLogScope scope = new KeyValueLogScope();
                    scope.AddArtifactType(ArtifactType_Dump);
                    scope.AddEndpointInfo(processInfo.EndpointInfo);

                    return new EgressStreamResult(
                        token => _diagnosticServices.GetDump(processInfo, type, token),
                        egressProvider,
                        dumpFileName,
                        processInfo.EndpointInfo,
                        ContentTypes.ApplicationOctectStream,
                        scope);
                }
            }, processFilter, ArtifactType_Dump));
        }
예제 #2
0
        private ActionResult Result(
            string artifactType,
            string providerName,
            Func <Stream, CancellationToken, Task> action,
            string fileName,
            string contentType,
            IEndpointInfo endpointInfo,
            bool asAttachment = true)
        {
            KeyValueLogScope scope = new KeyValueLogScope();

            scope.AddArtifactType(artifactType);
            scope.AddEndpointInfo(endpointInfo);

            if (string.IsNullOrEmpty(providerName))
            {
                return(new OutputStreamResult(
                           action,
                           contentType,
                           asAttachment ? fileName : null,
                           scope));
            }
            else
            {
                return(new EgressStreamResult(
                           action,
                           providerName,
                           fileName,
                           endpointInfo,
                           contentType,
                           scope));
            }
        }
예제 #3
0
        private async Task <ActionResult <T> > InvokeForProcess <T>(Func <IProcessInfo, Task <ActionResult <T> > > func, ProcessFilter?filter, string artifactType = null)
        {
            IDisposable artifactTypeRegistration = null;

            if (!string.IsNullOrEmpty(artifactType))
            {
                KeyValueLogScope artifactTypeScope = new KeyValueLogScope();
                artifactTypeScope.AddArtifactType(artifactType);
                artifactTypeRegistration = _logger.BeginScope(artifactTypeScope);
            }

            try
            {
                return(await this.InvokeService(async() =>
                {
                    IProcessInfo processInfo = await _diagnosticServices.GetProcessAsync(filter, HttpContext.RequestAborted);

                    KeyValueLogScope processInfoScope = new KeyValueLogScope();
                    processInfoScope.AddEndpointInfo(processInfo.EndpointInfo);
                    using var _ = _logger.BeginScope(processInfoScope);

                    _logger.LogDebug("Resolved target process.");

                    return await func(processInfo);
                }, _logger));
            }
            finally
            {
                artifactTypeRegistration?.Dispose();
            }
        }
        public ActionResult GetMetrics()
        {
            return(this.InvokeService(() =>
            {
                if (!_metricsOptions.Enabled.GetValueOrDefault(MetricsOptionsDefaults.Enabled))
                {
                    throw new InvalidOperationException("Metrics was not enabled");
                }

                KeyValueLogScope scope = new KeyValueLogScope();
                scope.AddArtifactType(ArtifactType_Metrics);

                return new OutputStreamResult(async(outputStream, token) =>
                {
                    await _metricsStore.MetricsStore.SnapshotMetrics(outputStream, token);
                },
                                              ContentTypes.TextPlain_v0_0_4,
                                              null,
                                              scope);
            }, _logger));
        }
예제 #5
0
        public ActionResult Metrics()
        {
            return(this.InvokeService(() =>
            {
                if (!_metricsOptions.Enabled)
                {
                    throw new InvalidOperationException("Metrics was not enabled");
                }

                KeyValueLogScope scope = new KeyValueLogScope();
                scope.AddArtifactType(ArtifactType_Metrics);

                return new OutputStreamResult(async(outputStream, token) =>
                {
                    await _metricsStore.MetricsStore.SnapshotMetrics(outputStream, token);
                },
                                              "text/plain; version=0.0.4",
                                              null,
                                              scope);
            }, _logger));
        }