diff --git a/management-panel/app/Filament/Pages/ManageRemoteWrite.php b/management-panel/app/Filament/Pages/ManageRemoteWrite.php new file mode 100644 index 0000000..76dc803 --- /dev/null +++ b/management-panel/app/Filament/Pages/ManageRemoteWrite.php @@ -0,0 +1,141 @@ +schema([ + // 启用切换开关 + Forms\Components\Toggle::make('state') + ->label("启用") + ->required() + ->reactive(), + + Forms\Components\Fieldset::make() + ->schema([ + // 远程存储的URL + Forms\Components\TextInput::make('url') + ->label("远程存储URL") + ->required() + ->url() + ->placeholder("http://remote-storage.example.com/api/v1/write"), + + // 每个分片的最大队列容量 + Forms\Components\TextInput::make('queue_config_capacity') + ->label("队列容量") + ->required() + ->numeric(), + + // 每次发送的最大样本数 + Forms\Components\TextInput::make('queue_config_max_samples_per_send') + ->label("每次发送样本数") + ->required() + ->numeric(), + + // 每次发送批次的最大等待时间 + Forms\Components\TextInput::make('queue_config_batch_send_deadline') + ->label("批次发送截止时间") + ->required() + ->placeholder("5s"), + + // 最大分片数 + Forms\Components\TextInput::make('queue_config_max_shards') + ->label("最大分片数") + ->required() + ->numeric(), + + // 最小分片数 + Forms\Components\TextInput::make('queue_config_min_shards') + ->label("最小分片数") + ->required() + ->numeric(), + + // 最小重试等待时间 + Forms\Components\TextInput::make('queue_config_min_backoff') + ->label("最小重试等待时间") + ->required() + ->placeholder("100ms"), + + // 最大重试等待时间 + Forms\Components\TextInput::make('queue_config_max_backoff') + ->label("最大重试等待时间") + ->required() + ->placeholder("5m"), + ]) + ->visible(fn($get) => in_array($get('state'), [true])), + + Forms\Components\Fieldset::make() + ->schema([ + // 认证模式选择 + Forms\Components\Select::make('auth_mode') + ->label("认证模式") + ->options([ + 'anonymous' => '匿名模式', + 'certificate' => '证书模式', + 'basic_auth' => '用户名密码模式', + ]) + ->required() + ->reactive(), + + // CA证书文件路径 + Forms\Components\TextInput::make('tls_config_ca_file') + ->label("CA证书文件") + ->nullable() + ->placeholder("/path/to/ca.crt") + ->visible(fn($get) => $get('auth_mode') === 'certificate'), + + // 客户端证书文件路径 + Forms\Components\TextInput::make('tls_config_cert_file') + ->label("客户端证书文件") + ->nullable() + ->placeholder("/path/to/client.crt") + ->visible(fn($get) => $get('auth_mode') === 'certificate'), + + // 客户端私钥文件路径 + Forms\Components\TextInput::make('tls_config_key_file') + ->label("客户端私钥文件") + ->nullable() + ->placeholder("/path/to/client.key") + ->visible(fn($get) => $get('auth_mode') === 'certificate'), + + // 是否跳过TLS验证 + Forms\Components\Toggle::make('tls_config_insecure_skip_verify') + ->label("跳过TLS验证") + ->visible(fn($get) => $get('auth_mode') === 'certificate'), + + // 基础认证用户名 + Forms\Components\TextInput::make('basic_auth_username') + ->label("基础认证用户名") + ->nullable() + ->visible(fn($get) => $get('auth_mode') === 'basic_auth'), + + // 基础认证密码 + Forms\Components\TextInput::make('basic_auth_password') + ->label("基础认证密码") + ->nullable() + ->password() + ->visible(fn($get) => $get('auth_mode') === 'basic_auth'), + + // Bearer令牌 + Forms\Components\TextInput::make('bearer_token') + ->label("Bearer令牌") + ->nullable() + ->visible(fn($get) => $get('auth_mode') === 'basic_auth'), + + ]) + ->visible(fn($get) => in_array($get('state'), [true])), + ]); + } +} diff --git a/management-panel/app/Settings/RemoteWriteSettings.php b/management-panel/app/Settings/RemoteWriteSettings.php new file mode 100644 index 0000000..a5e191b --- /dev/null +++ b/management-panel/app/Settings/RemoteWriteSettings.php @@ -0,0 +1,33 @@ +migrator->add('remote_write.state', false); + $this->migrator->add('remote_write.auth_mode', 'anonymous'); + + // 添加 Prometheus remote_write 配置参数 + $this->migrator->add('remote_write.url', 'http://remote-storage.example.com/api/v1/write'); // 远程存储的URL + $this->migrator->add('remote_write.queue_config_capacity', 10000); // 每个分片的最大队列容量 + $this->migrator->add('remote_write.queue_config_max_samples_per_send', 2000); // 每次发送的最大样本数 + $this->migrator->add('remote_write.queue_config_batch_send_deadline', '5s'); // 每次发送批次的最大等待时间 + $this->migrator->add('remote_write.queue_config_max_shards', 10); // 最大分片数 + $this->migrator->add('remote_write.queue_config_min_shards', 1); // 最小分片数 + $this->migrator->add('remote_write.queue_config_min_backoff', '100ms'); // 最小重试等待时间 + $this->migrator->add('remote_write.queue_config_max_backoff', '5m'); // 最大重试等待时间 + + // TLS 配置参数 + $this->migrator->add('remote_write.tls_config_ca_file', null); // CA证书文件 + $this->migrator->add('remote_write.tls_config_cert_file', null); // 客户端证书文件 + $this->migrator->add('remote_write.tls_config_key_file', null); // 客户端私钥文件 + $this->migrator->add('remote_write.tls_config_insecure_skip_verify', false); // 是否跳过TLS验证 + + // 身份认证参数 + $this->migrator->add('remote_write.basic_auth_username', null); // 基础认证的用户名 + $this->migrator->add('remote_write.basic_auth_password', null); // 基础认证的密码 + $this->migrator->add('remote_write.bearer_token', null); // Bearer 令牌 + } +};