Example #1
0
        public IActionResult Index()
        {
            KeyValueList <string, string> o = new KeyValueList <string, string>();

            string msg = "Hello 35!";

            o.Add("メッセージ", msg);

            o.Add("メッセージ 2", Dbg.HelloMsgTest);

            o.Add("起動時刻", Env.BootTime.ToLocalTime()._ToDtStr());

            o.Add("Git Commit Id", Dbg.GetCurrentGitCommitId());

            o.Add("Git Comment", Dbg.GetCurrentGitCommitInfo()?.Description ?? "-");

            o.Add("Startup Arguments", GlobalDaemonStateManager.StartupArguments);

            o.Add("Process Id", Env.ProcessId.ToString());

            o.Add("BuildConfigurationName", Env.BuildConfigurationName);

            o.Add("ExeOrDllName", Env.AppExecutableExeOrDllFileName);

            o.Add("RealExeName", Env.AppRealProcessExeFileName);

            o.Add("IsDotNetCore", Env.IsDotNetCore.ToString());

            o.Add(".NET Version", Env.FrameworkInfoString);

            o.Add("DotNetHostProcessExeName", Env.DotNetHostProcessExeName);

            o.Add("AppRootDir", Env.AppRootDir);

            o.Add("GC Mode", Env.GcMode);

            // 環境変数
            StringWriter w   = new StringWriter();
            var          dic = Environment.GetEnvironmentVariables();
            KeyValueList <string, string> tmp = new KeyValueList <string, string>();

            foreach (System.Collections.DictionaryEntry?kv in dic)
            {
                if (kv?.Key is string key2)
                {
                    if (kv?.Value is string value2)
                    {
                        tmp.Add(key2._NonNullTrim(), value2._NonNullTrim());
                    }
                }
            }

            tmp.OrderBy(x => x.Key)._DoForEach(x => w.WriteLine($"{x.Key} = {x.Value}"));

            o.Add("Environment Values", w.ToString());

            //string a = Str.MakeCharArray('x', 100_000);
            // テスト

/*            for (int i = 0;; i++)
 *          {
 *              i._PostData();
 *          } */

            return(View(o));
        }
Example #2
0
    async Task PostHttpMainAsync(CancellationToken cancel = default)
    {
        if (this.Config.PostUrl._IsEmpty())
        {
            return;
        }

        StatManDatabase copy;

        lock (this.DataLock)
        {
            copy = this.Database._CloneWithJson();
        }

        KeyValueList <string, string> vers = new KeyValueList <string, string>();

        vers.Add("APPNAME", CoresLib.AppNameFnSafe);
        vers.Add("OS", Env.OsInfoString);
        vers.Add("CPU", Env.CpuInfo.ToString());
        vers.Add("NUMCPU", Env.NumCpus.ToString());
        vers.Add("DOTNET", Env.FrameworkInfoString);
        vers.Add("EXE", Env.AppExecutableExeOrDllFileName._GetFileName() ?? "");

        List <string> versStrs = new List <string>();

        vers.ForEach(x => versStrs.Add($"{x.Key}={x.Value}"));

        var data = Json.NewJsonObject();

        foreach (var item in copy.StrValues)
        {
            data.TryAdd(item.Key, new JValue(item.Value));
        }

        foreach (var item in copy.LongValues)
        {
            data.TryAdd(item.Key, new JValue(item.Value));
        }

        DataVaultData postData = new DataVaultData
        {
            TimeStamp       = DtOffsetNow,
            StatUid         = copy.Uid,
            StatAppVer      = versStrs._Combine("|"),
            StatGitCommitId = Dbg.GetCurrentGitCommitId(),
            StatLocalIp     = this.CurrentLocalIp.ToString(),
            StatLocalFqdn   = LocalNet.GetHostInfo(true).HostName,
            SystemName      = Config.SystemName,
            LogName         = Config.LogName,
            Data            = data,
        };

        string postStr = postData._ObjectToJson();

        using var http = new WebApi(new WebApiOptions(new WebApiSettings { SslAcceptAnyCerts = true }));

        var ret = await http.SimplePostJsonAsync(WebMethods.POST, Config.PostUrl, postStr, cancel);

        if (ret.ToString()._InStr("ok") == false)
        {
            throw new CoresException($"Http error: {ret.ToString()._TruncStrEx(1000)}");
        }
    }
Example #3
0
        public string GenerateReportString()
        {
            StringWriter w = new StringWriter();

            lock (LockObj)
            {
                List <HostSummary> summaryList = new List <HostSummary>();

                foreach (var hostname in this.ReportTable.Keys)
                {
                    var list = this.ReportTable[hostname].ToList();

                    HostSummary h = new HostSummary
                    {
                        HostName    = hostname,
                        LastAlive   = list.LastOrDefault()?.Timestamp ?? Util.ZeroDateTimeOffsetValue,
                        LastChanged = Util.ZeroDateTimeOffsetValue,
                        IpAddress   = list.LastOrDefault()?.IpAddress ?? "",
                    };

                    h.LastChanged = list.Max(x => x.Timestamp);

                    summaryList.Add(h);
                }

                w.WriteLine($"Stress Mon: {DateTimeOffset.Now._ToDtStr(true, DtStrOption.All)}");
                w.WriteLine($"Build: {Dbg.GetCurrentGitCommitId()}, Boot at {Env.BootTime._ToDtStr()}");
                w.WriteLine();
                w.WriteLine($"合計サーバー数: {summaryList.Count}");
                w.WriteLine();
                w.WriteLine();

                w.WriteLine($"■ サーバー数: {summaryList.Count} - 最終変更時刻が古い順");
                var servers1 = summaryList.OrderBy(x => x.LastChanged).ThenBy(x => x.HostName, StrComparer.IgnoreCaseTrimComparer).ToList();
                for (int i = 0; i < servers1.Count; i++)
                {
                    var svr = servers1[i];
                    w.WriteLine($"{i + 1}/{servers1.Count}: Hostname = {svr.HostName}, IP = {svr.IpAddress}, Last Changed = {svr.LastChanged._ToDtStr(zeroDateTimeStr: "none")}, Last Alive = {svr.LastAlive._ToDtStr(zeroDateTimeStr: "none")}");
                }
                w.WriteLine();
                w.WriteLine();

                w.WriteLine($"■ サーバー数: {summaryList.Count} - 最終報告時刻が古い順");
                var servers2 = summaryList.OrderBy(x => x.LastAlive).ThenBy(x => x.HostName, StrComparer.IgnoreCaseTrimComparer).ToList();
                for (int i = 0; i < servers2.Count; i++)
                {
                    var svr = servers2[i];
                    w.WriteLine($"{i + 1}/{servers2.Count}: Hostname = {svr.HostName}, IP = {svr.IpAddress}, Last Changed = {svr.LastChanged._ToDtStr(zeroDateTimeStr: "none")}, Last Alive = {svr.LastAlive._ToDtStr(zeroDateTimeStr: "none")}");
                }
                w.WriteLine();
                w.WriteLine();


                w.WriteLine($"■ サーバー数: {summaryList.Count} - 詳細すべて");
                w.WriteLine();

                var servers3 = summaryList.OrderBy(x => x.HostName, StrComparer.IgnoreCaseTrimComparer).ToList();
                for (int i = 0; i < servers3.Count; i++)
                {
                    var svr = servers3[i];

                    w.WriteLine($"===== {i + 1}/{servers2.Count}: Hostname = {svr.HostName}, IP = {svr.IpAddress}, Last Changed = {svr.LastChanged._ToDtStr(zeroDateTimeStr: "none")}, Last Alive = {svr.LastAlive._ToDtStr(zeroDateTimeStr: "none")} =====");

                    int index = 0;
                    int count = this.ReportTable[svr.HostName].Count;
                    foreach (var hist in this.ReportTable[svr.HostName].OrderByDescending(x => x.Timestamp))
                    {
                        w.WriteLine($"--- History {(index++) + 1}/{count} of Hostname = {svr.HostName} ({hist.Timestamp._ToDtStr(zeroDateTimeStr: "none")}) ---");
                        w.WriteLine(hist.Body._NormalizeCrlf(CrlfStyle.CrLf, true));
                    }

                    w.WriteLine();
                    w.WriteLine();
                }
            }

            return(w.ToString());
        }