package host import ( "log" "strings" "github.com/wcharczuk/go-chart/v2" ) // This file contains utilities to create charts based on the different data // When a chart is rendered, it can return either an SVG or PNG. SVG is preferrable. func (h *Host) ChartMemory() string { h.getNodeInfo() log.Println("Generating Chart") c := chart.PieChart{ Width: 128, Height: 128, Values: []chart.Value{ {Value: float64(h.NodeMemory.Free) / float64(h.NodeMemory.Total), Label: "Free"}, {Value: float64(h.NodeMemory.Cached) / float64(h.NodeMemory.Total), Label: "Cached"}, {Value: float64(h.NodeMemory.Buffers) / float64(h.NodeMemory.Total), Label: "Buffers"}, }, } sb := new(strings.Builder) log.Println("Rendering chart") if err := c.Render(chart.SVG, sb); err != nil { return err.Error() } return sb.String() }