一、安装插件
安装infinity插件
二、配置数据源
三、配置图表
1、数据
这边提供一个go的demo
package main
import (
"math/rand"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
rand.Seed(time.Now().Unix())
router.GET("/api/data", func(ctx *gin.Context) {
var data []Metric
for i := 0; i < 10; i++ {
data = append(data, Metric{Entity: "m1", Value: rand.Float64() * 10.0, Time: time.Now().Add(time.Duration(-i) * time.Minute).UnixMilli()})
data = append(data, Metric{Entity: "m2", Value: rand.Float64() * 10.0, Time: time.Now().Add(time.Duration(-i) * time.Minute).UnixMilli()})
data = append(data, Metric{Entity: "m3", Value: rand.Float64() * 10.0, Time: time.Now().Add(time.Duration(-i) * time.Minute).UnixMilli()})
}
ctx.JSON(http.StatusOK, data)
})
router.Run(":8080")
}
type Metric struct {
Entity string `json:"entity"`
Value interface{} `json:"value"`
Time int64 `json:"time"`
}