Example #1
0
        public void StartDispatch(ArguReStart arguReStart)
        {
            string fileName = Configuration["RunProcessAdress"];

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                fileName += $"{arguReStart.app}.bat";
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                fileName += $"{arguReStart.app}.sh";
            }
            else
            {
                fileName += $"{arguReStart.app}.sh";
            }
            //创建一个ProcessStartInfo对象 使用系统shell 指定命令和参数 设置标准输出
            var psi = new ProcessStartInfo(fileName);

            using (var proc = Process.Start(psi))
            {
                if (proc == null)
                {
                    proc.Kill();
                    throw new ClientException(EnumClientMonitor.进程启动失败, "Process start failed");
                }
            }
        }
Example #2
0
        public ActionResult <ResultStatus> ReStartProcess([FromBody] ArguReStart arguReStart)
        {
            if (arguReStart == null)
            {
                throw new ClientException(EnumClientMonitor.请求参数不能为空, "Arguments is null");
            }
            if (arguReStart.value != "0")
            {
                throw new ClientException(EnumClientMonitor.序运行状态正常, "Process start success");
            }
            ReStartDispatch reStartDispatch = new ReStartDispatch(Configuration);

            reStartDispatch.StartDispatch(arguReStart);
            return(new ResultStatus((int)ResultStatusCode.Success, "正常启动程序"));
        }
Example #3
0
        public async Task <string> MonitorProcess(ArguProcess arguProcess, string appHost)
        {
            Uri requestUri = new Uri(appHost + UriAddress);
            var queries    = new[]
            {
                $"SELECT last(value) FROM \"application.health__results\" WHERE env = '{arguProcess.env}' and app = '{arguProcess.app}' and health_check_name = '百度 ping' and time > now() - 5s"
            };
            var dbName = "MyMetrics";

            //从指定库中查询数据
            var response = await ClientDb.Client.QueryAsync(queries, dbName);

            //得到Series集合对象
            var series = response.ToList();

            if (series.Count == 0)
            {
                ArguReStart arguReStart = new ArguReStart()
                {
                    app   = arguProcess.app,
                    value = "0"
                };
                var responsePost = await PostStringAsync("ReStartProcess", ToJSON(arguReStart), requestUri, null);

                return(arguReStart.value);
            }
            var healthCheckValue    = (series[0].Values)[0][1];
            var healthCheckToString = Convert.ToString(healthCheckValue);

            if (healthCheckToString == "0")
            {
                //判断条件还不够精确,无法去重启
                //var responsePost = await PostStringAsync("ReStartProcess", null, requestUri, null);
            }
            else if (healthCheckToString == "0.5")
            {
                //程序运行异常
            }
            else
            {
                //程序正常运行
            }
            return(healthCheckToString);
        }