v0.3.0-prod

This commit is contained in:
Mateusz Gruszczyński committed 2026-11-04 14:57:48 +01:00
1 parent 387933957e
commit 9d093b691c
21 files changed
+1239 -180

No files matched your search

+63 -3
View File
@@ -21,6 +21,28 @@ type Manager struct {
mu sync.Mutex
}
// Graph colors mirror the dashboard's theme tokens (internal/web/assets/app.css)
// so rendered PNGs sit visually in place inside the panel cards. Each range
// is rendered twice (dark + light) so the client can pick the variant that
// matches the active site theme without round-tripping through rrdtool.
const (
graphColorPanel = "#181c19" // --panel (dark)
graphColorField = "#121713" // --field (dark plot canvas)
graphColorLine = "#313832" // --line (dark minor grid)
graphColorLine2 = "#485149" // --line2 (dark axis / major grid)
graphColorText = "#edf0ecCC"
graphColorAccent = "#8fb9a4" // --accent (dark)
graphColorAccentFill = "#8fb9a43d"
graphLightColorPanel = "#ffffff" // --panel (light)
graphLightColorField = "#f7f8f6" // --panel2 (light plot canvas)
graphLightColorLine = "#cbd2cb" // --line (light minor grid)
graphLightColorLine2 = "#aeb8af" // --line2 (light axis / major grid)
graphLightColorText = "#202622CC"
graphLightColorAccent = "#507b67" // --accent (light)
graphLightColorAccentFill = "#507b673d"
)
type Range struct{ Key, Start, Title string }
var Ranges = []Range{
@@ -77,7 +99,7 @@ func (m *Manager) Last(ctx context.Context) (int, error) {
return int(f + 0.5), err
}
func (m *Manager) Graph(ctx context.Context, key string) (string, error) {
func (m *Manager) Graph(ctx context.Context, key, theme string) (string, error) {
var rg *Range
for i := range Ranges {
if Ranges[i].Key == key {
@@ -91,7 +113,14 @@ func (m *Manager) Graph(ctx context.Context, key string) (string, error) {
if err := os.MkdirAll(m.GraphDir, 0750); err != nil {
return "", err
}
out := filepath.Join(m.GraphDir, key+".png")
panel, field, line, line2, text, accent, accentFill := graphColorPanel, graphColorField, graphColorLine, graphColorLine2, graphColorText, graphColorAccent, graphColorAccentFill
suffix := ""
if theme == "light" {
panel, field, line, line2, text, accent, accentFill = graphLightColorPanel, graphLightColorField, graphLightColorLine, graphLightColorLine2, graphLightColorText, graphLightColorAccent, graphLightColorAccentFill
suffix = "-light"
}
out := filepath.Join(m.GraphDir, key+suffix+".png")
m.mu.Lock()
defer m.mu.Unlock()
@@ -100,7 +129,38 @@ func (m *Manager) Graph(ctx context.Context, key string) (string, error) {
}
def := "DEF:online=" + m.Path + ":online:LAST"
args := []string{"graph", out, "--imgformat", "PNG", "--start", rg.Start, "--end", "now", "--width", "1200", "--height", "320", "--lower-limit", "0", "--alt-autoscale-max", "--title", rg.Title, "--vertical-label", "użytkownicy", "--border", "0", def, "LINE2:online#2F6FED:Online", "GPRINT:online:LAST:Aktualnie\\: %4.0lf", "GPRINT:online:AVERAGE:Średnio\\: %4.0lf", "GPRINT:online:MAX:Maks.\\: %4.0lf\\n"}
watermark := "linuxiarz.pl · " + time.Now().Format("2006-01-02 15:04")
args := []string{
"graph", out,
"--imgformat", "PNG",
"--start", rg.Start, "--end", "now",
"--width", "1200", "--height", "320",
"--lower-limit", "0", "--alt-autoscale-max", "--rigid",
"--slope-mode",
"--title", rg.Title,
"--vertical-label", "użytkownicy",
"--border", "0",
"--color", "BACK" + panel,
"--color", "CANVAS" + field,
"--color", "FONT" + text,
"--color", "AXIS" + line2,
"--color", "ARROW" + line2,
"--color", "GRID" + line,
"--color", "MGRID" + line2,
"--color", "FRAME" + panel,
"--font", "DEFAULT:0:",
"--font", "TITLE:13:",
"--font", "AXIS:9:",
"--font", "LEGEND:10:",
"--font", "UNIT:9:",
"--watermark", watermark,
def,
"AREA:online" + accentFill,
"LINE2:online" + accent + ":Online",
"GPRINT:online:LAST:Aktualnie\\: %4.0lf",
"GPRINT:online:AVERAGE:Średnio\\: %4.0lf",
"GPRINT:online:MAX:Maks.\\: %4.0lf\\n",
}
cmd := exec.CommandContext(ctx, m.Tool, args...)
var stderr bytes.Buffer
cmd.Stderr = &stderr