snapshot: 数据源管理+大屏增强前快照
This commit is contained in:
1 parent
2bf3e7c308
commit
1726ad65ac
19 files changed
+2540
-273
No files matched your search
@@ -32,16 +32,36 @@ func (AgentReport) TableName() string {
|
||||
return "agent_reports"
|
||||
}
|
||||
|
||||
// AgentLatestResponse Agent 最新状态(含服务器元信息)// Logan.Li
|
||||
type AgentLatestResponse struct {
|
||||
Hostname string `json:"hostname"`
|
||||
IP string `json:"ip"`
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
CPUCores int `json:"cpu_cores"`
|
||||
MemUsage float64 `json:"mem_usage"`
|
||||
MemTotal float64 `json:"mem_total"`
|
||||
MemUsed float64 `json:"mem_used"`
|
||||
DiskUsage float64 `json:"disk_usage"`
|
||||
DiskInfo string `json:"disk_info"`
|
||||
NetInfo string `json:"net_info"`
|
||||
ReportTime string `json:"report_time"`
|
||||
AgentVersion string `json:"agent_version"`
|
||||
AgentStatus string `json:"agent_status"`
|
||||
OS string `json:"os"`
|
||||
Region string `json:"region"`
|
||||
}
|
||||
|
||||
// AgentReportRequest Agent 上报请求体 // Logan.Li
|
||||
type AgentReportRequest struct {
|
||||
Hostname string `json:"hostname" binding:"required"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
CPU CPUMetric `json:"cpu"`
|
||||
Memory MemMetric `json:"memory"`
|
||||
Disks []DiskMetric `json:"disks"`
|
||||
Ports []PortMetric `json:"ports"`
|
||||
Network NetworkStat `json:"network"` // 网络指标
|
||||
DiskIO DiskIOStat `json:"disk_io"` // 磁盘 IO
|
||||
Hostname string `json:"hostname" binding:"required"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
AgentVersion string `json:"agent_version"` // Agent 版本号
|
||||
CPU CPUMetric `json:"cpu"`
|
||||
Memory MemMetric `json:"memory"`
|
||||
Disks []DiskMetric `json:"disks"`
|
||||
Ports []PortMetric `json:"ports"`
|
||||
Network NetworkStat `json:"network"` // 网络指标
|
||||
DiskIO DiskIOStat `json:"disk_io"` // 磁盘 IO
|
||||
}
|
||||
|
||||
type CPUMetric struct {
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// PrometheusDataSource Prometheus 数据源配置(参考 Grafana 界面设计) // Logan.Li
|
||||
type PrometheusDataSource struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;uniqueIndex;comment:数据源名称" json:"name"`
|
||||
URL string `gorm:"type:varchar(512);not null;comment:Prometheus 服务地址" json:"url"`
|
||||
Access string `gorm:"type:varchar(16);default:'server';comment:访问模式: server/proxy" json:"access"`
|
||||
|
||||
// Basic Auth
|
||||
BasicAuth bool `gorm:"default:false;comment:启用基础认证" json:"basic_auth"`
|
||||
BasicAuthUser string `gorm:"type:varchar(128);comment:认证用户名" json:"basic_auth_user,omitempty"`
|
||||
BasicAuthPass string `gorm:"type:varchar(256);comment:认证密码" json:"basic_auth_pass,omitempty"`
|
||||
WithCredentials bool `gorm:"default:false;comment:携带凭证" json:"with_credentials"`
|
||||
|
||||
// TLS Client Auth
|
||||
TLSClientAuth bool `gorm:"default:false;comment:启用TLS客户端认证" json:"tls_client_auth"`
|
||||
WithCACert bool `gorm:"default:false;comment:携带CA证书" json:"with_ca_cert"`
|
||||
CACert string `gorm:"type:text;comment:CA证书内容(PEM)" json:"ca_cert,omitempty"`
|
||||
SkipTLSVerify bool `gorm:"default:false;comment:跳过TLS验证" json:"skip_tls_verify"`
|
||||
|
||||
// Custom HTTP Headers (JSON array of {header, value})
|
||||
CustomHeaders string `gorm:"type:text;comment:自定义HTTP头(JSON)" json:"custom_headers,omitempty"`
|
||||
|
||||
// Alerting
|
||||
EnableAlerting bool `gorm:"default:true;comment:启用告警管理" json:"enable_alerting"`
|
||||
AlertmanagerDS string `gorm:"type:varchar(128);comment:Alertmanager数据源" json:"alertmanager_ds,omitempty"`
|
||||
|
||||
// 采集与查询
|
||||
ScrapeInterval int `gorm:"default:15;comment:采集间隔(秒)" json:"scrape_interval"`
|
||||
QueryTimeout int `gorm:"default:60;comment:查询超时(秒)" json:"query_timeout"`
|
||||
HTTPMethod string `gorm:"type:varchar(8);default:'POST';comment:HTTP方法" json:"http_method"`
|
||||
|
||||
// 杂项
|
||||
DisableMetricsLookup bool `gorm:"default:false;comment:禁用指标查找" json:"disable_metrics_lookup"`
|
||||
CustomQueryParams string `gorm:"type:text;comment:自定义查询参数(JSON)" json:"custom_query_params,omitempty"`
|
||||
|
||||
// 状态
|
||||
IsDefault bool `gorm:"default:false;index;comment:是否默认数据源" json:"is_default"`
|
||||
Status int `gorm:"default:1;comment:状态: 1启用 0禁用" json:"status"`
|
||||
|
||||
// 时间戳
|
||||
CreatedAt time.Time `gorm:"not null;index;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index;comment:删除时间" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (PrometheusDataSource) TableName() string {
|
||||
return "prometheus_datasources"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 请求/响应 struct
|
||||
// ============================================
|
||||
|
||||
// CreatePromDSReq 创建数据源请求
|
||||
type CreatePromDSReq struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
URL string `json:"url" binding:"required"`
|
||||
Access string `json:"access"`
|
||||
BasicAuth bool `json:"basic_auth"`
|
||||
BasicAuthUser string `json:"basic_auth_user"`
|
||||
BasicAuthPass string `json:"basic_auth_pass"`
|
||||
WithCredentials bool `json:"with_credentials"`
|
||||
TLSClientAuth bool `json:"tls_client_auth"`
|
||||
WithCACert bool `json:"with_ca_cert"`
|
||||
CACert string `json:"ca_cert"`
|
||||
SkipTLSVerify bool `json:"skip_tls_verify"`
|
||||
CustomHeaders string `json:"custom_headers"`
|
||||
EnableAlerting *bool `json:"enable_alerting"`
|
||||
AlertmanagerDS string `json:"alertmanager_ds"`
|
||||
ScrapeInterval int `json:"scrape_interval"`
|
||||
QueryTimeout int `json:"query_timeout"`
|
||||
HTTPMethod string `json:"http_method"`
|
||||
DisableMetricsLookup bool `json:"disable_metrics_lookup"`
|
||||
CustomQueryParams string `json:"custom_query_params"`
|
||||
IsDefault bool `json:"is_default"`
|
||||
}
|
||||
|
||||
// UpdatePromDSReq 更新数据源请求
|
||||
type UpdatePromDSReq struct {
|
||||
Name *string `json:"name"`
|
||||
URL *string `json:"url"`
|
||||
Access *string `json:"access"`
|
||||
BasicAuth *bool `json:"basic_auth"`
|
||||
BasicAuthUser *string `json:"basic_auth_user"`
|
||||
BasicAuthPass *string `json:"basic_auth_pass"`
|
||||
WithCredentials *bool `json:"with_credentials"`
|
||||
TLSClientAuth *bool `json:"tls_client_auth"`
|
||||
WithCACert *bool `json:"with_ca_cert"`
|
||||
CACert *string `json:"ca_cert"`
|
||||
SkipTLSVerify *bool `json:"skip_tls_verify"`
|
||||
CustomHeaders *string `json:"custom_headers"`
|
||||
EnableAlerting *bool `json:"enable_alerting"`
|
||||
AlertmanagerDS *string `json:"alertmanager_ds"`
|
||||
ScrapeInterval *int `json:"scrape_interval"`
|
||||
QueryTimeout *int `json:"query_timeout"`
|
||||
HTTPMethod *string `json:"http_method"`
|
||||
DisableMetricsLookup *bool `json:"disable_metrics_lookup"`
|
||||
CustomQueryParams *string `json:"custom_query_params"`
|
||||
IsDefault *bool `json:"is_default"`
|
||||
Status *int `json:"status"`
|
||||
}
|
||||
|
||||
// TestPromDSReq 测试数据源连接请求
|
||||
type TestPromDSReq struct {
|
||||
URL string `json:"url" binding:"required"`
|
||||
BasicAuth bool `json:"basic_auth"`
|
||||
BasicAuthUser string `json:"basic_auth_user"`
|
||||
BasicAuthPass string `json:"basic_auth_pass"`
|
||||
SkipTLSVerify bool `json:"skip_tls_verify"`
|
||||
}
|
||||
Reference in new issue
Block a user