26 lines
673 B
Go
26 lines
673 B
Go
|
package host
|
||
|
|
||
|
import (
|
||
|
"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 {
|
||
|
c := chart.PieChart{
|
||
|
Width: 256,
|
||
|
Height: 256,
|
||
|
Values: []chart.Value{
|
||
|
{Value: float64(h.NodeMemory.Free / h.NodeMemory.Total), Label: "Free"},
|
||
|
{Value: float64(h.NodeMemory.Cached / h.NodeMemory.Total), Label: "Cached"},
|
||
|
{Value: float64(h.NodeMemory.Buffers / h.NodeMemory.Total), Label: "Buffers"},
|
||
|
},
|
||
|
}
|
||
|
sb := new(strings.Builder)
|
||
|
c.Render(chart.SVG, sb)
|
||
|
return sb.String()
|
||
|
}
|