[增加]prometheus远程写入的参数配置界面
This commit is contained in:
141
management-panel/app/Filament/Pages/ManageRemoteWrite.php
Normal file
141
management-panel/app/Filament/Pages/ManageRemoteWrite.php
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
|
use App\Settings\RemoteWriteSettings;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Pages\SettingsPage;
|
||||||
|
|
||||||
|
class ManageRemoteWrite extends SettingsPage
|
||||||
|
{
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
|
||||||
|
|
||||||
|
protected static string $settings = RemoteWriteSettings::class;
|
||||||
|
|
||||||
|
public function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->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])),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
management-panel/app/Settings/RemoteWriteSettings.php
Normal file
33
management-panel/app/Settings/RemoteWriteSettings.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Settings;
|
||||||
|
|
||||||
|
use Spatie\LaravelSettings\Settings;
|
||||||
|
|
||||||
|
class RemoteWriteSettings extends Settings
|
||||||
|
{
|
||||||
|
public bool $state;
|
||||||
|
public string $auth_mode;
|
||||||
|
public string $url;
|
||||||
|
public int $queue_config_capacity;
|
||||||
|
public int $queue_config_max_samples_per_send;
|
||||||
|
public string $queue_config_batch_send_deadline;
|
||||||
|
public int $queue_config_max_shards;
|
||||||
|
public int $queue_config_min_shards;
|
||||||
|
public string $queue_config_min_backoff;
|
||||||
|
public string $queue_config_max_backoff;
|
||||||
|
|
||||||
|
public ?string $tls_config_ca_file;
|
||||||
|
public ?string $tls_config_cert_file;
|
||||||
|
public ?string $tls_config_key_file;
|
||||||
|
public bool $tls_config_insecure_skip_verify;
|
||||||
|
|
||||||
|
public ?string $basic_auth_username;
|
||||||
|
public ?string $basic_auth_password;
|
||||||
|
public ?string $bearer_token;
|
||||||
|
|
||||||
|
public static function group(): string
|
||||||
|
{
|
||||||
|
return 'remote_write';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Spatie\LaravelSettings\Migrations\SettingsMigration;
|
||||||
|
|
||||||
|
return new class extends SettingsMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$this->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 令牌
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user