예제 #1
0
        public HttpResponseMessage GetEnvironments(int id, string filter)
        {
            using (_tracer.Step("ProcessController.GetEnvironments"))
            {
                var envs = GetProcessById(id).GetEnvironmentVariables()
                           .Where(p => string.Equals("all", filter, StringComparison.OrdinalIgnoreCase) || p.Key.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)
                           .ToDictionary(p => p.Key, p => p.Value);

                if (ArmUtils.IsArmRequest(Request))
                {
                    // No need to hide the secrets if the request is from contributor or admin.
                    if (!(ArmUtils.IsRbacContributorRequest(Request) || ArmUtils.IsLegacyAuthorizationSource(Request)))
                    {
                        envs = envs.Where(kv => _armWhitelistedVariables.Contains(kv.Key, StringComparer.OrdinalIgnoreCase))
                               .ToDictionary(k => k.Key, v => v.Value);
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.OK, ArmUtils.AddEnvelopeOnArmRequest(new ProcessEnvironmentInfo(filter, envs), Request)));
            }
        }
예제 #2
0
        private ProcessInfo GetProcessInfo(Process process, string href, bool details = false)
        {
            href = href.TrimEnd('/');
            if (href.EndsWith("/0", StringComparison.OrdinalIgnoreCase))
            {
                href = href.Substring(0, href.Length - 1) + process.Id;
            }

            var selfLink = new Uri(href);
            var info     = new ProcessInfo
            {
                Id       = process.Id,
                Name     = process.ProcessName,
                Href     = selfLink,
                UserName = SafeGetValue(process.GetUserName, null)
            };

            if (details)
            {
                // this could fail access denied
                info.HandleCount = SafeGetValue(() => process.HandleCount, -1);
                info.ThreadCount = SafeGetValue(() => process.Threads.Count, -1);
                info.ModuleCount = SafeGetValue(() => process.Modules.Count, -1);
                info.FileName    = SafeGetValue(() => process.MainModule.FileName, "N/A");

                // always return empty
                //info.Arguments = SafeGetValue(() => process.StartInfo.Arguments, "N/A");

                info.StartTime               = SafeGetValue(() => process.StartTime.ToUniversalTime(), DateTime.MinValue);
                info.TotalProcessorTime      = SafeGetValue(() => process.TotalProcessorTime, TimeSpan.FromSeconds(-1));
                info.UserProcessorTime       = SafeGetValue(() => process.UserProcessorTime, TimeSpan.FromSeconds(-1));
                info.PrivilegedProcessorTime = SafeGetValue(() => process.PrivilegedProcessorTime, TimeSpan.FromSeconds(-1));

                info.PagedSystemMemorySize64    = SafeGetValue(() => process.PagedSystemMemorySize64, -1);
                info.NonpagedSystemMemorySize64 = SafeGetValue(() => process.NonpagedSystemMemorySize64, -1);
                info.PagedMemorySize64          = SafeGetValue(() => process.PagedMemorySize64, -1);
                info.PeakPagedMemorySize64      = SafeGetValue(() => process.PeakPagedMemorySize64, -1);
                info.WorkingSet64            = SafeGetValue(() => process.WorkingSet64, -1);
                info.PeakWorkingSet64        = SafeGetValue(() => process.PeakWorkingSet64, -1);
                info.VirtualMemorySize64     = SafeGetValue(() => process.VirtualMemorySize64, -1);
                info.PeakVirtualMemorySize64 = SafeGetValue(() => process.PeakVirtualMemorySize64, -1);
                info.PrivateMemorySize64     = SafeGetValue(() => process.PrivateMemorySize64, -1);

                info.MiniDump                   = new Uri(selfLink + "/dump");
                info.OpenFileHandles            = SafeGetValue(() => GetOpenFileHandles(process.Id), Enumerable.Empty <string>());
                info.Parent                     = new Uri(selfLink, SafeGetValue(() => process.GetParentId(_tracer), 0).ToString());
                info.Children                   = SafeGetValue(() => process.GetChildren(_tracer, recursive: false), Enumerable.Empty <Process>()).Select(c => new Uri(selfLink, c.Id.ToString()));
                info.Threads                    = SafeGetValue(() => GetThreads(process, selfLink.ToString()), Enumerable.Empty <ProcessThreadInfo>());
                info.Modules                    = SafeGetValue(() => GetModules(process, selfLink.ToString().TrimEnd('/') + "/modules"), Enumerable.Empty <ProcessModuleInfo>());
                info.TimeStamp                  = DateTime.UtcNow;
                info.EnvironmentVariables       = SafeGetValue(process.GetEnvironmentVariables, new Dictionary <string, string>());
                info.CommandLine                = SafeGetValue(process.GetCommandLine, null);
                info.IsProfileRunning           = ProfileManager.IsProfileRunning(process.Id);
                info.IsIisProfileRunning        = ProfileManager.IsIisProfileRunning(process.Id);
                info.IisProfileTimeoutInSeconds = ProfileManager.IisProfileTimeoutInSeconds;
                SetEnvironmentInfo(info);

                if (ArmUtils.IsArmRequest(Request))
                {
                    // No need to hide the secrets if the request is from contributor or admin.
                    if (!(ArmUtils.IsRbacContributorRequest(Request) || ArmUtils.IsLegacyAuthorizationSource(Request)))
                    {
                        info.EnvironmentVariables = info.EnvironmentVariables
                                                    .Where(kv => _armWhitelistedVariables.Contains(kv.Key, StringComparer.OrdinalIgnoreCase))
                                                    .ToDictionary(k => k.Key, v => v.Value);
                        info.CommandLine = null;
                    }
                }
            }

            return(info);
        }