mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
添加mongodb最大链接数、所用磁盘占比等、、、
This commit is contained in:
@@ -950,6 +950,7 @@ type ICloudDBInstance interface {
|
||||
GetVcpuCount() int
|
||||
GetVmemSizeMB() int //MB
|
||||
GetDiskSizeGB() int
|
||||
GetDiskSizeUsedMB() int
|
||||
//基础版、高可用?
|
||||
GetCategory() string
|
||||
GetStorageType() string
|
||||
@@ -1435,6 +1436,9 @@ type ICloudMongoDB interface {
|
||||
GetMaintainTime() string
|
||||
GetPort() int
|
||||
GetIops() int
|
||||
|
||||
GetMaxConnections() int
|
||||
|
||||
GetNetworkAddress() string
|
||||
|
||||
GetIBackups() ([]SMongoDBBackup, error)
|
||||
|
||||
@@ -1700,9 +1700,11 @@ func (manager *SBucketManager) usageQ(q *sqlchemy.SQuery, rangeObjs []db.IStanda
|
||||
}
|
||||
|
||||
type SBucketUsages struct {
|
||||
Buckets int
|
||||
Objects int
|
||||
Bytes int64
|
||||
Buckets int
|
||||
Objects int
|
||||
Bytes int64
|
||||
BytesLimit int64
|
||||
DiskUsedRate float64
|
||||
}
|
||||
|
||||
func (manager *SBucketManager) TotalCount(scope rbacutils.TRbacScope, ownerId mcclient.IIdentityProvider, rangeObjs []db.IStandaloneModel, providers []string, brands []string, cloudEnv string, policyResult rbacutils.SPolicyResult) SBucketUsages {
|
||||
@@ -1726,6 +1728,14 @@ func (manager *SBucketManager) TotalCount(scope rbacutils.TRbacScope, ownerId mc
|
||||
).Else(sqlchemy.NewConstField(0)),
|
||||
"size_bytes1",
|
||||
),
|
||||
sqlchemy.NewFunction(
|
||||
sqlchemy.NewCase().When(
|
||||
sqlchemy.GT(buckets.Field("size_bytes_limit"), 0),
|
||||
buckets.Field("size_bytes_limit"),
|
||||
).Else(
|
||||
buckets.Field("size_bytes")),
|
||||
"size_bytes_limit",
|
||||
),
|
||||
)
|
||||
bucketsQ = manager.usageQ(bucketsQ, rangeObjs, providers, brands, cloudEnv)
|
||||
buckets = bucketsQ.SubQuery()
|
||||
@@ -1733,11 +1743,15 @@ func (manager *SBucketManager) TotalCount(scope rbacutils.TRbacScope, ownerId mc
|
||||
sqlchemy.COUNT("buckets"),
|
||||
sqlchemy.SUM("objects", buckets.Field("object_cnt1")),
|
||||
sqlchemy.SUM("bytes", buckets.Field("size_bytes1")),
|
||||
sqlchemy.SUM("bytes_limit", buckets.Field("size_bytes_limit")),
|
||||
)
|
||||
err := q.First(&usage)
|
||||
if err != nil {
|
||||
log.Errorf("Query bucket usage error %s", err)
|
||||
}
|
||||
if usage.BytesLimit > 0 {
|
||||
usage.DiskUsedRate = float64(usage.Bytes) / float64(usage.BytesLimit)
|
||||
}
|
||||
return usage
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,8 @@ type SDBInstance struct {
|
||||
// 存储大小
|
||||
// example: 10240
|
||||
DiskSizeGB int `nullable:"false" list:"user" create:"required"`
|
||||
// 已使用的存储大小
|
||||
DiskSizeUsedMB int `nullable:"false" list:"user"`
|
||||
// 端口
|
||||
// example: 3306
|
||||
Port int `nullable:"false" list:"user" create:"optional"`
|
||||
@@ -1599,6 +1601,7 @@ func (self *SDBInstance) SyncWithCloudDBInstance(ctx context.Context, userCred m
|
||||
self.VcpuCount = ext.GetVcpuCount()
|
||||
self.VmemSizeMb = ext.GetVmemSizeMB()
|
||||
self.DiskSizeGB = ext.GetDiskSizeGB()
|
||||
self.DiskSizeUsedMB = ext.GetDiskSizeUsedMB()
|
||||
self.StorageType = ext.GetStorageType()
|
||||
self.Category = ext.GetCategory()
|
||||
self.Status = ext.GetStatus()
|
||||
@@ -1702,6 +1705,7 @@ func (manager *SDBInstanceManager) newFromCloudDBInstance(ctx context.Context, u
|
||||
instance.VcpuCount = extInstance.GetVcpuCount()
|
||||
instance.VmemSizeMb = extInstance.GetVmemSizeMB()
|
||||
instance.DiskSizeGB = extInstance.GetDiskSizeGB()
|
||||
instance.DiskSizeUsedMB = extInstance.GetDiskSizeUsedMB()
|
||||
instance.ConnectionStr = extInstance.GetConnectionStr()
|
||||
instance.StorageType = extInstance.GetStorageType()
|
||||
instance.InternalConnectionStr = extInstance.GetInternalConnectionStr()
|
||||
@@ -1773,9 +1777,12 @@ func (manager *SDBInstanceManager) newFromCloudDBInstance(ctx context.Context, u
|
||||
}
|
||||
|
||||
type SRdsCountStat struct {
|
||||
TotalRdsCount int
|
||||
TotalCpuCount int
|
||||
TotalMemSizeMb int
|
||||
TotalRdsCount int
|
||||
TotalCpuCount int
|
||||
TotalMemSizeMb int
|
||||
TotalDiskSizeGb int
|
||||
TotalDiskSizeUsedMb int
|
||||
DiskUsedRate float64
|
||||
}
|
||||
|
||||
func (man *SDBInstanceManager) TotalCount(
|
||||
@@ -1795,11 +1802,17 @@ func (man *SDBInstanceManager) TotalCount(
|
||||
|
||||
q := sq.Query(sqlchemy.COUNT("total_rds_count"),
|
||||
sqlchemy.SUM("total_cpu_count", sq.Field("vcpu_count")),
|
||||
sqlchemy.SUM("total_mem_size_mb", sq.Field("vmem_size_mb")))
|
||||
sqlchemy.SUM("total_mem_size_mb", sq.Field("vmem_size_mb")),
|
||||
sqlchemy.SUM("total_disk_size_gb", sq.Field("disk_size_gb")),
|
||||
sqlchemy.SUM("total_disk_size_used_mb", sq.Field("disk_size_used_mb")),
|
||||
)
|
||||
|
||||
stat := SRdsCountStat{}
|
||||
row := q.Row()
|
||||
err := q.Row2Struct(row, &stat)
|
||||
if stat.TotalDiskSizeGb > 0 {
|
||||
stat.DiskUsedRate = float64(stat.TotalDiskSizeUsedMb) / float64(stat.TotalDiskSizeGb) / 1024
|
||||
}
|
||||
return stat, err
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,8 @@ type SMongoDB struct {
|
||||
ReplicationNum int `nullable:"false" default:"0" list:"user" create:"optional"`
|
||||
|
||||
// 最大连接数
|
||||
Iops int `nullable:"true" list:"user" create:"optional"`
|
||||
MaxConnections int `nullable:"true" list:"user" create:"optional"`
|
||||
Iops int `nullable:"true" list:"user" create:"optional"`
|
||||
|
||||
// 实例IP地址
|
||||
IpAddr string `nullable:"false" list:"user"`
|
||||
@@ -504,6 +505,7 @@ func (self *SMongoDB) SyncWithCloudMongoDB(ctx context.Context, userCred mcclien
|
||||
if iops := ext.GetIops(); iops > 0 {
|
||||
self.Iops = iops
|
||||
}
|
||||
self.MaxConnections = ext.GetMaxConnections()
|
||||
self.NetworkAddress = ext.GetNetworkAddress()
|
||||
|
||||
if vpcId := ext.GetVpcId(); len(vpcId) > 0 {
|
||||
@@ -578,6 +580,7 @@ func (self *SCloudregion) newFromCloudMongoDB(ctx context.Context, userCred mccl
|
||||
ins.Port = ext.GetPort()
|
||||
ins.ReplicationNum = ext.GetReplicationNum()
|
||||
ins.Iops = ext.GetIops()
|
||||
ins.MaxConnections = ext.GetMaxConnections()
|
||||
ins.NetworkAddress = ext.GetNetworkAddress()
|
||||
|
||||
if zoneId := ext.GetZoneId(); len(zoneId) > 0 {
|
||||
|
||||
@@ -1011,6 +1011,8 @@ func BucketUsage(scope rbacutils.TRbacScope, ownerId mcclient.IIdentityProvider,
|
||||
count[getKey(scope, "buckets")] = bucketUsage.Buckets
|
||||
count[getKey(scope, "bucket_objects")] = bucketUsage.Objects
|
||||
count[getKey(scope, "bucket_bytes")] = bucketUsage.Bytes
|
||||
count[getKey(scope, "bucket_bytes_limit")] = bucketUsage.BytesLimit
|
||||
count[getKey(scope, "bucket_disk_used_rate")] = bucketUsage.DiskUsedRate
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -1041,6 +1043,9 @@ func DBInstanceUsage(scope rbacutils.TRbacScope, ownerId mcclient.IIdentityProvi
|
||||
count[getKey(scope, "rds")] = cnt.TotalRdsCount
|
||||
count[getKey(scope, "rds.cpu")] = cnt.TotalCpuCount
|
||||
count[getKey(scope, "rds.memory")] = cnt.TotalMemSizeMb
|
||||
count[getKey(scope, "rds.disk_size_gb")] = cnt.TotalDiskSizeGb
|
||||
count[getKey(scope, "rds.disk_size_used_mb")] = cnt.TotalDiskSizeUsedMb
|
||||
count[getKey(scope, "rds.disk_size_used_rate")] = cnt.DiskUsedRate
|
||||
return count
|
||||
}
|
||||
|
||||
|
||||
@@ -237,6 +237,13 @@ func (rds *SDBInstance) GetDiskSizeGB() int {
|
||||
return rds.DBInstanceStorage
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetDiskSizeUsedMB() int {
|
||||
if rds.DBInstanceDiskUsed == 0 {
|
||||
rds.Refresh()
|
||||
}
|
||||
return int(rds.DBInstanceDiskUsed / 1024 / 1024)
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetPort() int {
|
||||
if rds.Port == 0 {
|
||||
rds.Refresh()
|
||||
|
||||
@@ -39,6 +39,7 @@ type SMOngoDBAttribute struct {
|
||||
ConnectionDomain string `json:"ConnectionDomain"`
|
||||
}
|
||||
}
|
||||
MaxConnections int
|
||||
}
|
||||
|
||||
type SMongoDB struct {
|
||||
@@ -254,6 +255,11 @@ func (self *SMongoDB) GetIops() int {
|
||||
return iops
|
||||
}
|
||||
|
||||
func (self *SMongoDB) GetMaxConnections() int {
|
||||
maxConnection, _ := self.region.GetMaxConnections(self.DBInstanceId)
|
||||
return maxConnection
|
||||
}
|
||||
|
||||
func (self *SMongoDB) GetNetworkAddress() string {
|
||||
addr, _ := self.region.GetNetworkAddress(self.DBInstanceId)
|
||||
return addr
|
||||
@@ -314,6 +320,17 @@ func (self *SRegion) GetIops(id string) (int, error) {
|
||||
return ret[0].MaxIops, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetMaxConnections(id string) (int, error) {
|
||||
ret, err := self.GetMongoDBAttribute(id)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "DescribeDBInstanceAttribute err")
|
||||
}
|
||||
if len(ret) == 0 {
|
||||
return 0, errors.Wrapf(err, "ret missing err")
|
||||
}
|
||||
return ret[0].MaxConnections, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetNetworkAddress(id string) (string, error) {
|
||||
ret, err := self.GetMongoDBAttribute(id)
|
||||
if err != nil {
|
||||
|
||||
@@ -241,6 +241,13 @@ func (rds *SDBInstance) GetDiskSizeGB() int {
|
||||
return rds.DBInstanceStorage
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetDiskSizeUsedMB() int {
|
||||
if rds.DBInstanceDiskUsed == 0 {
|
||||
rds.Refresh()
|
||||
}
|
||||
return int(rds.DBInstanceDiskUsed / 1024 / 1024)
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetPort() int {
|
||||
if rds.Port == 0 {
|
||||
rds.Refresh()
|
||||
|
||||
@@ -115,3 +115,7 @@ func (instance *SDBInstanceBase) RecoveryFromBackup(conf *cloudprovider.SDBInsta
|
||||
func (instance *SDBInstanceBase) GetIops() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (instance *SDBInstanceBase) GetDiskSizeUsedMB() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package multicloud
|
||||
|
||||
type SMongodbBase struct {
|
||||
SVirtualResourceBase
|
||||
SBillingBase
|
||||
}
|
||||
|
||||
func (instance *SMongodbBase) GetMaxConnections() int {
|
||||
return 0
|
||||
}
|
||||
@@ -35,6 +35,8 @@ type SMongoDB struct {
|
||||
multicloud.QcloudTags
|
||||
multicloud.SVirtualResourceBase
|
||||
multicloud.SBillingBase
|
||||
multicloud.SMongodbBase
|
||||
|
||||
region *SRegion
|
||||
|
||||
IOPS int
|
||||
|
||||
Reference in New Issue
Block a user