Skip to content

Commit

Permalink
获取最新机器名
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jan 24, 2024
1 parent b526d2b commit fd13063
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Stardust/Models/AppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ public void Refresh()
MachineName = Environment.MachineName;
IP = AgentInfo.GetIps();

// 获取最新机器名
if (Runtime.Linux)
{
var file = @"/etc/hostname";
if (File.Exists(file)) MachineName = File.ReadAllText(file).Trim();
}

try
{
// 获取进程的连接数
Expand Down
7 changes: 7 additions & 0 deletions Stardust/StarClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ public NodeInfo GetNodeInfo()
Time = DateTime.UtcNow,
};

// 获取最新机器名
if (Runtime.Linux)
{
var file = @"/etc/hostname";
if (File.Exists(file)) di.MachineName = File.ReadAllText(file).Trim();
}

// 目标框架
di.Framework = _frameworkManager.GetAllVersions().Join(",", e => e.TrimStart('v'));

Expand Down
13 changes: 10 additions & 3 deletions Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,16 @@ static void Test5()

static void Test6()
{
var nr = new NetRuntime();
var rs = nr.IsAlpine();
XTrace.WriteLine("IsAlpine: {0}", rs);
//var nr = new NetRuntime();
//var rs = nr.IsAlpine();
//XTrace.WriteLine("IsAlpine: {0}", rs);

var client = new StarClient();
for (int i = 0; i < 100; i++)
{
XTrace.WriteLine("Name:{0}, MachinecName:{1}", client.GetNodeInfo().MachineName, Environment.MachineName);
Thread.Sleep(1000);
}
}

static void Test8()
Expand Down

0 comments on commit fd13063

Please sign in to comment.