diff --git a/CHANGELOG.md b/CHANGELOG.md index 8247d8b..cdcd958 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +# 2.31 (2023-10-18) +- 支持日志图在 Grafana v10 的展示,日志图可以指定想展示的字段,ycol格式为`字段1,字段2` +- 流图支持多条线,ycol格式为`#:#指标1,指标2` +- 修改表格区域的名字为ycol,使多个表格在同一个图表时,可以区分。 + +![image.png](https://cdn.nlark.com/yuque/0/2023/png/182537/1697599988480-6ddc340d-9b64-4531-abbf-748eff4c0df9.png#averageHue=%231e2126&clientId=ue09f9ab6-6409-4&from=paste&height=480&id=u63975600&originHeight=960&originWidth=1630&originalType=binary&ratio=2&rotation=0&showTitle=false&size=363161&status=done&style=none&taskId=u01fdf5fe-b863-44da-b5f8-a3ae4512280&title=&width=815) + + +![image.png](https://cdn.nlark.com/yuque/0/2023/png/182537/1697600032996-be73fb93-a181-4f56-a42d-9ebdba626227.png#averageHue=%23202327&clientId=ue09f9ab6-6409-4&from=paste&height=515&id=u8bdbba62&originHeight=1030&originWidth=2130&originalType=binary&ratio=2&rotation=0&showTitle=false&size=562357&status=done&style=none&taskId=uf3ac8398-be19-4a16-abc7-740eebef31c&title=&width=1065) + +- Supports the display of log graphs in Grafana v10. Log graphs can specify the fields you want to display. The ycol format is `Field 1, Field 2` +- The flow graph supports multiple lines, and the ycol format is `#:#Indicator 1,Indicator 2` +- Modify the name of the table area to ycol so that multiple tables can be distinguished when they are in the same chart. + # 2.30 (2023-07-25) - 优化SLS Grafana插件后端结构,现支持加入自定义Resource API功能。 - 引入gotoSLS功能,用户可以方便地跳转到SLS控制台进行查询,和体验SLS控制台更强大的功能,跳转附带当前Grafana的query、时间信息。在DataSource界面配置roleArn可实现STS跳转,若不配置,则按照正常直接访问逻辑跳转(需要登录控制台)。 diff --git a/dist/CHANGELOG.md b/dist/CHANGELOG.md index 8247d8b..cdcd958 100644 --- a/dist/CHANGELOG.md +++ b/dist/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +# 2.31 (2023-10-18) +- 支持日志图在 Grafana v10 的展示,日志图可以指定想展示的字段,ycol格式为`字段1,字段2` +- 流图支持多条线,ycol格式为`#:#指标1,指标2` +- 修改表格区域的名字为ycol,使多个表格在同一个图表时,可以区分。 + +![image.png](https://cdn.nlark.com/yuque/0/2023/png/182537/1697599988480-6ddc340d-9b64-4531-abbf-748eff4c0df9.png#averageHue=%231e2126&clientId=ue09f9ab6-6409-4&from=paste&height=480&id=u63975600&originHeight=960&originWidth=1630&originalType=binary&ratio=2&rotation=0&showTitle=false&size=363161&status=done&style=none&taskId=u01fdf5fe-b863-44da-b5f8-a3ae4512280&title=&width=815) + + +![image.png](https://cdn.nlark.com/yuque/0/2023/png/182537/1697600032996-be73fb93-a181-4f56-a42d-9ebdba626227.png#averageHue=%23202327&clientId=ue09f9ab6-6409-4&from=paste&height=515&id=u8bdbba62&originHeight=1030&originWidth=2130&originalType=binary&ratio=2&rotation=0&showTitle=false&size=562357&status=done&style=none&taskId=uf3ac8398-be19-4a16-abc7-740eebef31c&title=&width=1065) + +- Supports the display of log graphs in Grafana v10. Log graphs can specify the fields you want to display. The ycol format is `Field 1, Field 2` +- The flow graph supports multiple lines, and the ycol format is `#:#Indicator 1,Indicator 2` +- Modify the name of the table area to ycol so that multiple tables can be distinguished when they are in the same chart. + # 2.30 (2023-07-25) - 优化SLS Grafana插件后端结构,现支持加入自定义Resource API功能。 - 引入gotoSLS功能,用户可以方便地跳转到SLS控制台进行查询,和体验SLS控制台更强大的功能,跳转附带当前Grafana的query、时间信息。在DataSource界面配置roleArn可实现STS跳转,若不配置,则按照正常直接访问逻辑跳转(需要登录控制台)。 diff --git a/dist/README.md b/dist/README.md index 6597865..b2b7e89 100644 --- a/dist/README.md +++ b/dist/README.md @@ -4,7 +4,7 @@ 日志服务 SLS 是云原生观测分析平台,为Log/Metric/Trace等数据提供大规模、低成本、实时平台化服务。一站式提供数据采集、加工、分析、告警可视化与投递功能,全面提升研发、运维、运营和安全等场景数字化能力。[官方文档](https://www.aliyun.com/product/sls)
本仓库为阿里云日志服务Grafana数据源插件。使用本插件的前提,需要您使用日志服务产品,并拥有至少1个已配置采集的LogStore。 # 2. 安装 -依赖 Grafana 8.0 及以上版本 , Grafana 8.0 以下请使用1.0版本。
于[Release处下载](https://github.com/aliyun/aliyun-log-grafana-datasource-plugin/releases)本插件到grafana插件目录下,修改配置文件 , 然后重启grafana。 +依赖 Grafana 8.0 及以上版本 , Grafana 8.0 以下请使用1.0版本。
于[Release处下载](https://github.com/aliyun/aliyun-log-grafana-datasource-plugin/releases)本插件到grafana插件目录下,修改配置文件,在配置文件的[plugins] 节点中,设置 `allow_loading_unsigned_plugins = aliyun-log-service-datasource`, 然后重启grafana。 - mac - 插件目录: `/usr/local/var/lib/grafana/plugins` diff --git a/dist/gpx_log-service-datasource_darwin_amd64 b/dist/gpx_log-service-datasource_darwin_amd64 index ed735c7..ed17e84 100755 Binary files a/dist/gpx_log-service-datasource_darwin_amd64 and b/dist/gpx_log-service-datasource_darwin_amd64 differ diff --git a/dist/gpx_log-service-datasource_darwin_arm64 b/dist/gpx_log-service-datasource_darwin_arm64 index 964db9a..451336e 100755 Binary files a/dist/gpx_log-service-datasource_darwin_arm64 and b/dist/gpx_log-service-datasource_darwin_arm64 differ diff --git a/dist/gpx_log-service-datasource_linux_amd64 b/dist/gpx_log-service-datasource_linux_amd64 index d734f6b..84de217 100755 Binary files a/dist/gpx_log-service-datasource_linux_amd64 and b/dist/gpx_log-service-datasource_linux_amd64 differ diff --git a/dist/gpx_log-service-datasource_linux_arm b/dist/gpx_log-service-datasource_linux_arm index dd0fc40..bff6b93 100755 Binary files a/dist/gpx_log-service-datasource_linux_arm and b/dist/gpx_log-service-datasource_linux_arm differ diff --git a/dist/gpx_log-service-datasource_linux_arm64 b/dist/gpx_log-service-datasource_linux_arm64 index d00770c..ecbed40 100755 Binary files a/dist/gpx_log-service-datasource_linux_arm64 and b/dist/gpx_log-service-datasource_linux_arm64 differ diff --git a/dist/gpx_log-service-datasource_windows_amd64.exe b/dist/gpx_log-service-datasource_windows_amd64.exe index d30baa6..9c55797 100755 Binary files a/dist/gpx_log-service-datasource_windows_amd64.exe and b/dist/gpx_log-service-datasource_windows_amd64.exe differ diff --git a/dist/plugin.json b/dist/plugin.json index adbfa5c..3faadf6 100644 --- a/dist/plugin.json +++ b/dist/plugin.json @@ -37,8 +37,8 @@ } ], "screenshots": [], - "version": "2.30", - "updated": "2023-07-25" + "version": "2.31", + "updated": "2023-10-18" }, "dependencies": { "grafanaDependency": ">=7.0.0", diff --git a/pkg/sls-plugin.go b/pkg/sls-plugin.go index c1d3518..de0a460 100644 --- a/pkg/sls-plugin.go +++ b/pkg/sls-plugin.go @@ -377,22 +377,27 @@ func (ds *SlsDatasource) BuildFlowGraphV2(logs []map[string]string, xcol string, return } ds.SortLogs(logs, xcol) - metricName := ycols[1] + metricNames := strings.Split(ycols[1], ",") + metricMap := make(map[string]bool) + for _, n := range metricNames { + metricMap[n] = true + } var labelNames []string for k := range logs[0] { - if k != "__source__" && k != "__time__" && k != metricName && k != xcol { + if k != "__source__" && k != "__time__" && !metricMap[k] && k != xcol { labelNames = append(labelNames, k) } } sort.Strings(labelNames) timeFields := make(map[string][]time.Time) - metricFields := make(map[string][]float64) - + nameMetricFields := make(map[string]map[string][]float64) + for _, n := range metricNames { + nameMetricFields[n] = make(map[string][]float64) + } frameLabelsMap := make(map[string]map[string]string) for _, alog := range logs { timeVal := alog[xcol] - metricVal := alog[metricName] labels := map[string]string{} labelsKey := "" for _, l := range labelNames { @@ -407,20 +412,29 @@ func (ds *SlsDatasource) BuildFlowGraphV2(logs []map[string]string, xcol string, } else { timeFields[labelsKey] = []time.Time{toTime(timeVal)} } - floatV, err := strconv.ParseFloat(metricVal, 64) - if err != nil { - log.DefaultLogger.Info("BuildFlowGraphV2", "ParseFloat", err, "value", metricVal) - } - if _, ok := metricFields[labelsKey]; ok { - metricFields[labelsKey] = append(metricFields[labelsKey], floatV) - } else { - metricFields[labelsKey] = []float64{floatV} + for _, n := range metricNames { + metricVal := alog[n] + floatV, err := strconv.ParseFloat(metricVal, 64) + if err != nil { + log.DefaultLogger.Info("BuildFlowGraphV2", "ParseFloat", err, "value", metricVal) + } + if _, ok := nameMetricFields[n][labelsKey]; ok { + nameMetricFields[n][labelsKey] = append(nameMetricFields[n][labelsKey], floatV) + } else { + nameMetricFields[n][labelsKey] = []float64{floatV} + } } } for k, v := range timeFields { frame := data.NewFrame("") frame.Fields = append(frame.Fields, data.NewField("Time", nil, v)) - frame.Fields = append(frame.Fields, data.NewField("Value", frameLabelsMap[k], metricFields[k])) + if len(metricNames) == 1 { + frame.Fields = append(frame.Fields, data.NewField("Value", frameLabelsMap[k], nameMetricFields[metricNames[0]][k])) + } else { + for _, n := range metricNames { + frame.Fields = append(frame.Fields, data.NewField(n, frameLabelsMap[k], nameMetricFields[n][k])) + } + } *frames = append(*frames, frame) } } @@ -659,7 +673,7 @@ func (ds *SlsDatasource) BuildTimingGraph(logs []map[string]string, xcol string, } func (ds *SlsDatasource) BuildTable(logs []map[string]string, xcol string, ycols []string, keys []string, frames *data.Frames) { - frame := data.NewFrame("response") + frame := data.NewFrame(strings.Join(ycols, ",")) fieldMap := make(map[string][]string) @@ -709,47 +723,48 @@ func (ds *SlsDatasource) BuildTable(logs []map[string]string, xcol string, ycols } func (ds *SlsDatasource) BuildLogs(logs []map[string]string, ycols []string, frames *data.Frames) { - frame := data.NewFrame("response") + frame := data.NewFrame("") frame.Meta = &data.FrameMeta{ PreferredVisualization: data.VisTypeLogs, } - yset := make(map[string]bool) - for _, ycol := range ycols { - yset[ycol] = true - } + fieldMap := make(map[string][]string) + var keyArr []string var times []time.Time + if len(ycols) == 1 && ycols[0] == "" { + for _, alog := range logs { + for k := range alog { + if _, ok := fieldMap[k]; !ok { + fieldMap[k] = make([]string, 0) + keyArr = append(keyArr, k) + } + } + } + } else { + for _, ycol := range ycols { + fieldMap[ycol] = make([]string, 0) + keyArr = append(keyArr, ycol) + } + } var values []string for _, alog := range logs { message := "" - var keys []string - for k := range alog { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - v := alog[k] - if k == "__time__" { - floatValue, err := strconv.ParseFloat(v, 64) - if err != nil { - log.DefaultLogger.Info("BuildLogs", "ParseTime", err) - continue - } - times = append(times, time.Unix(int64(floatValue), 0)) - } - if len(ycols) > 0 && ycols[0] != "" { - if yset[k] { - message = message + k + `="` + strings.ReplaceAll(v, `"`, `'`) + `" ` - } - } else { - message = message + k + `="` + strings.ReplaceAll(v, `"`, `'`) + `" ` - } + for _, k := range keyArr { + fieldMap[k] = append(fieldMap[k], alog[k]) + message = message + k + `="` + strings.ReplaceAll(alog[k], `"`, `'`) + `" ` } + timeValue, _ := strconv.ParseFloat(alog["__time__"], 64) + t := time.Unix(int64(timeValue), 0) + times = append(times, t) values = append(values, message) } - frame.Fields = append(frame.Fields, - data.NewField("time", nil, times), - data.NewField("message", nil, values), - ) + + if len(times) > 0 { + frame.Fields = append(frame.Fields, data.NewField("time", nil, times)) + } + frame.Fields = append(frame.Fields, data.NewField("message", nil, values)) + for _, v := range keyArr { + frame.Fields = append(frame.Fields, data.NewField(v, nil, fieldMap[v])) + } *frames = append(*frames, frame) }