mirror of
				https://github.com/TeaOSLab/EdgeCommon.git
				synced 2025-11-04 13:10:24 +08:00 
			
		
		
		
	指标增加一些易读的名称等信息
This commit is contained in:
		@@ -49,7 +49,7 @@ func FindAllMetricChartTypes() []*shared.Definition {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func FindAllMetricChartTypeName(chartType MetricChartType) string {
 | 
					func FindMetricChartTypeName(chartType MetricChartType) string {
 | 
				
			||||||
	for _, def := range FindAllMetricChartTypes() {
 | 
						for _, def := range FindAllMetricChartTypes() {
 | 
				
			||||||
		if def.Code == chartType {
 | 
							if def.Code == chartType {
 | 
				
			||||||
			return def.Name
 | 
								return def.Name
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package serverconfigs
 | 
					package serverconfigs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// MetricItemCategory 指标分类
 | 
					// MetricItemCategory 指标分类
 | 
				
			||||||
type MetricItemCategory = string
 | 
					type MetricItemCategory = string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -22,29 +24,94 @@ const (
 | 
				
			|||||||
	MetricItemPeriodUnitMonth  MetricItemPeriodUnit = "month"
 | 
						MetricItemPeriodUnitMonth  MetricItemPeriodUnit = "month"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// HTTP相关指标对象
 | 
					// FindAllMetricKeyDefinitions 指标对象定义
 | 
				
			||||||
type metricKeyDefinition struct {
 | 
					func FindAllMetricKeyDefinitions(category MetricItemCategory) []*shared.Definition {
 | 
				
			||||||
	Name        string `json:"name"`
 | 
					 | 
				
			||||||
	Code        string `json:"code"`
 | 
					 | 
				
			||||||
	Description string `json:"description"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type metricValueDefinition struct {
 | 
					 | 
				
			||||||
	Name        string `json:"name"`
 | 
					 | 
				
			||||||
	Code        string `json:"code"`
 | 
					 | 
				
			||||||
	Description string `json:"description"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func FindAllHTTPMetricKeyDefinitions() []*metricKeyDefinition {
 | 
					 | 
				
			||||||
	// TODO
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func FindAllMetricValueDefinitions(category MetricItemCategory) []*metricValueDefinition {
 | 
					 | 
				
			||||||
	switch category {
 | 
						switch category {
 | 
				
			||||||
	case MetricItemCategoryHTTP:
 | 
						case MetricItemCategoryHTTP:
 | 
				
			||||||
		return []*metricValueDefinition{
 | 
							return []*shared.Definition{
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "客户端地址(IP)",
 | 
				
			||||||
 | 
									Code:        "${remoteAddr}",
 | 
				
			||||||
 | 
									Description: "会依次根据X-Forwarded-For、X-Real-IP、RemoteAddr获取",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "直接客户端地址(IP)",
 | 
				
			||||||
 | 
									Code:        "${rawRemoteAddr}",
 | 
				
			||||||
 | 
									Description: "返回直接连接服务的客户端原始IP地址",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "客户端用户名",
 | 
				
			||||||
 | 
									Code:        "${remoteUser}",
 | 
				
			||||||
 | 
									Description: "通过基本认证填入的用户名",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "请求URI",
 | 
				
			||||||
 | 
									Code:        "${requestURI}",
 | 
				
			||||||
 | 
									Description: "包含参数",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "请求路径",
 | 
				
			||||||
 | 
									Code:        "${requestPath}",
 | 
				
			||||||
 | 
									Description: "不包含参数",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "文件扩展名",
 | 
				
			||||||
 | 
									Code:        "${requestPathExtension}",
 | 
				
			||||||
 | 
									Description: "请求路径中的文件扩展名,包括点符号,比如.html、.png",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "主机名",
 | 
				
			||||||
 | 
									Code:        "${host}",
 | 
				
			||||||
 | 
									Description: "通常是请求的域名",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "请求协议",
 | 
				
			||||||
 | 
									Code:        "${proto}",
 | 
				
			||||||
 | 
									Description: "http或https",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "HTTP协议",
 | 
				
			||||||
 | 
									Code:        "${proto}",
 | 
				
			||||||
 | 
									Description: "包含版本的HTTP请求协议,类似于HTTP/1.0",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "URL参数值",
 | 
				
			||||||
 | 
									Code:        "${arg.NAME}",
 | 
				
			||||||
 | 
									Description: "单个URL参数值",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "Header值",
 | 
				
			||||||
 | 
									Code:        "${header.NAME}",
 | 
				
			||||||
 | 
									Description: "单个Header值,比如${header.User-Agent}",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name:        "Cookie值",
 | 
				
			||||||
 | 
									Code:        "${cookie.NAME}",
 | 
				
			||||||
 | 
									Description: "单个cookie值,比如${cookie.sid}",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// =========  以下是响应  =========
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Name: "响应的Content-Type值",
 | 
				
			||||||
 | 
									Code: "${response.contentType}",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						case MetricItemCategoryTCP:
 | 
				
			||||||
 | 
							// TODO
 | 
				
			||||||
 | 
							return []*shared.Definition{}
 | 
				
			||||||
 | 
						case MetricItemCategoryUDP:
 | 
				
			||||||
 | 
							// TODO
 | 
				
			||||||
 | 
							return []*shared.Definition{}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return []*shared.Definition{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FindAllMetricValueDefinitions 指标数值定义
 | 
				
			||||||
 | 
					func FindAllMetricValueDefinitions(category MetricItemCategory) []*shared.Definition {
 | 
				
			||||||
 | 
						switch category {
 | 
				
			||||||
 | 
						case MetricItemCategoryHTTP:
 | 
				
			||||||
 | 
							return []*shared.Definition{
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Name: "请求数",
 | 
									Name: "请求数",
 | 
				
			||||||
				Code: "${countRequest}",
 | 
									Code: "${countRequest}",
 | 
				
			||||||
@@ -63,7 +130,7 @@ func FindAllMetricValueDefinitions(category MetricItemCategory) []*metricValueDe
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case MetricItemCategoryTCP:
 | 
						case MetricItemCategoryTCP:
 | 
				
			||||||
		return []*metricValueDefinition{
 | 
							return []*shared.Definition{
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Name: "连接数",
 | 
									Name: "连接数",
 | 
				
			||||||
				Code: "${countConnection}",
 | 
									Code: "${countConnection}",
 | 
				
			||||||
@@ -78,7 +145,7 @@ func FindAllMetricValueDefinitions(category MetricItemCategory) []*metricValueDe
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case MetricItemCategoryUDP:
 | 
						case MetricItemCategoryUDP:
 | 
				
			||||||
		return []*metricValueDefinition{
 | 
							return []*shared.Definition{
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Name: "连接数",
 | 
									Name: "连接数",
 | 
				
			||||||
				Code: "${countConnection}",
 | 
									Code: "${countConnection}",
 | 
				
			||||||
@@ -93,21 +160,16 @@ func FindAllMetricValueDefinitions(category MetricItemCategory) []*metricValueDe
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return []*metricValueDefinition{}
 | 
						return []*shared.Definition{}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FindAllTCPMetricKeyDefinitions TCP相关指标对象
 | 
					func FindMetricValueName(category MetricItemCategory, code string) string {
 | 
				
			||||||
func FindAllTCPMetricKeyDefinitions() []*metricKeyDefinition {
 | 
						for _, def := range FindAllMetricValueDefinitions(category) {
 | 
				
			||||||
	// TODO
 | 
							if def.Code == code {
 | 
				
			||||||
 | 
								return def.Name
 | 
				
			||||||
	return nil
 | 
							}
 | 
				
			||||||
}
 | 
						}
 | 
				
			||||||
 | 
						return code
 | 
				
			||||||
// FindAllUDPMetricKeyDefinitions UDP相关指标对象
 | 
					 | 
				
			||||||
func FindAllUDPMetricKeyDefinitions() []*metricKeyDefinition {
 | 
					 | 
				
			||||||
	// TODO
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// HumanMetricTime 格式化时间,让时间更易读
 | 
					// HumanMetricTime 格式化时间,让时间更易读
 | 
				
			||||||
@@ -141,3 +203,19 @@ func HumanMetricTime(periodUnit MetricItemPeriodUnit, time string) string {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return time
 | 
						return time
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func FindMetricPeriodUnitName(unit string) string {
 | 
				
			||||||
 | 
						switch unit {
 | 
				
			||||||
 | 
						case MetricItemPeriodUnitMonth:
 | 
				
			||||||
 | 
							return "月"
 | 
				
			||||||
 | 
						case MetricItemPeriodUnitWeek:
 | 
				
			||||||
 | 
							return "周"
 | 
				
			||||||
 | 
						case MetricItemPeriodUnitDay:
 | 
				
			||||||
 | 
							return "天"
 | 
				
			||||||
 | 
						case MetricItemPeriodUnitHour:
 | 
				
			||||||
 | 
							return "小时"
 | 
				
			||||||
 | 
						case MetricItemPeriodUnitMinute:
 | 
				
			||||||
 | 
							return "分钟"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user