87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace Monitor.Agent;
|
|
|
|
/// <summary>
|
|
/// <c>agent.json</c>:节点本地配置,面板无法修改。其中 <c>limits</c> 是本地硬上限:期望任务集超出这些范围时,
|
|
/// 调和器拒绝执行并在 <c>rejected[]</c> 里给出原因。默认不使用 443,目标任务默认不开放。
|
|
/// </summary>
|
|
public sealed class AgentConfig
|
|
{
|
|
[JsonPropertyName("fleet")]
|
|
public FleetSection Fleet { get; set; } = new();
|
|
|
|
[JsonPropertyName("listen")]
|
|
public ListenSection Listen { get; set; } = new();
|
|
|
|
[JsonPropertyName("limits")]
|
|
public LimitsSection Limits { get; set; } = new();
|
|
|
|
[JsonPropertyName("fleet_policy")]
|
|
public PolicySection Policy { get; set; } = new();
|
|
|
|
[JsonPropertyName("reporting")]
|
|
public ReportingSection Reporting { get; set; } = new();
|
|
}
|
|
|
|
public sealed class ReportingSection
|
|
{
|
|
/// <summary>上报主机资源占用(CPU、内存、磁盘、流量、运行时长,只有汇总数字,没有型号和 IP)。设为 false 就一个字也不上报。</summary>
|
|
[JsonPropertyName("host_stats")]
|
|
public bool HostStats { get; set; } = true;
|
|
|
|
[JsonPropertyName("host_interval_s")]
|
|
public int HostIntervalSeconds { get; set; } = 2;
|
|
}
|
|
|
|
public sealed class FleetSection
|
|
{
|
|
[JsonPropertyName("server")]
|
|
public string Server { get; set; } = "";
|
|
|
|
[JsonPropertyName("identity_dir")]
|
|
public string IdentityDir { get; set; } = "/etc/monitor";
|
|
}
|
|
|
|
public sealed class ListenSection
|
|
{
|
|
[JsonPropertyName("bind")]
|
|
public string Bind { get; set; } = "0.0.0.0";
|
|
|
|
/// <summary>Probe 控制通道(TLS,点对点会话)。</summary>
|
|
[JsonPropertyName("control_port")]
|
|
public int ControlPort { get; set; } = 7443;
|
|
|
|
[JsonPropertyName("udp_ports")]
|
|
public List<int> UdpPorts { get; set; } = [7443];
|
|
|
|
[JsonPropertyName("tcp_ports")]
|
|
public List<int> TcpPorts { get; set; } = [7444];
|
|
}
|
|
|
|
public sealed class LimitsSection
|
|
{
|
|
[JsonPropertyName("max_total_mbps")]
|
|
public double MaxTotalMbps { get; set; } = 1200;
|
|
|
|
[JsonPropertyName("max_total_pps")]
|
|
public long MaxTotalPps { get; set; } = 20_000;
|
|
|
|
/// <summary>默认为空:不允许执行任何目标任务。</summary>
|
|
[JsonPropertyName("allowed_target_cidrs")]
|
|
public List<string> AllowedTargetCidrs { get; set; } = [];
|
|
|
|
[JsonPropertyName("max_concurrent_tests")]
|
|
public int MaxConcurrentTests { get; set; } = 1;
|
|
}
|
|
|
|
public sealed class PolicySection
|
|
{
|
|
/// <summary>在默认值的基础上进一步收窄:只响应这些产品方法。为空表示不收窄。</summary>
|
|
[JsonPropertyName("allow_methods")]
|
|
public List<string>? AllowMethods { get; set; }
|
|
}
|
|
|
|
[JsonSerializable(typeof(AgentConfig))]
|
|
public sealed partial class AgentConfigContext : System.Text.Json.Serialization.JsonSerializerContext;
|