Compare commits

...

5 Commits

Author SHA1 Message Date
Magnus Åhall
63956de837 Bumped to v9 2024-05-20 18:58:17 +02:00
Magnus Åhall
e4dbabfea5 Fixed last updated value on datapoints 2024-05-20 18:57:47 +02:00
Magnus Åhall
7724c742ad Version parameter 2024-05-20 13:21:22 +02:00
Magnus Åhall
ff1c848c58 Bumped to v8 2024-05-20 13:19:22 +02:00
Magnus Åhall
787009c621 Removed fonts 2024-05-20 13:18:40 +02:00
5 changed files with 34 additions and 6 deletions

View File

@ -117,6 +117,8 @@ func DatapointAdd[T any](name string, value T) (err error) { // {{{
return return
} }
service.Db.Conn.Exec(`UPDATE datapoint SET last_value = NOW() WHERE name=$1`, name)
return return
} // }}} } // }}}

11
main.go
View File

@ -26,12 +26,13 @@ import (
"time" "time"
) )
const VERSION = "v7" const VERSION = "v9"
var ( var (
logger *slog.Logger logger *slog.Logger
flagConfigFile string flagConfigFile string
flagDev bool flagDev bool
flagVersion bool
service *ws.Service service *ws.Service
logFile *os.File logFile *os.File
parsedTemplates map[string]*template.Template parsedTemplates map[string]*template.Template
@ -59,6 +60,7 @@ func init() { // {{{
cfgPath := path.Join(confDir, "smon.yaml") cfgPath := path.Join(confDir, "smon.yaml")
flag.StringVar(&flagConfigFile, "config", cfgPath, "Path and filename of the YAML configuration file") flag.StringVar(&flagConfigFile, "config", cfgPath, "Path and filename of the YAML configuration file")
flag.BoolVar(&flagDev, "dev", false, "reload templates on each request") flag.BoolVar(&flagDev, "dev", false, "reload templates on each request")
flag.BoolVar(&flagVersion, "version", false, "Display version and exit")
flag.Parse() flag.Parse()
componentFilenames, err = getComponentFilenames(viewFS) componentFilenames, err = getComponentFilenames(viewFS)
@ -70,6 +72,11 @@ func init() { // {{{
} // }}} } // }}}
func main() { // {{{ func main() { // {{{
if flagVersion {
fmt.Println(VERSION)
os.Exit(0)
}
var err error var err error
werr.Init() werr.Init()
@ -261,7 +268,7 @@ func entryDatapoint(w http.ResponseWriter, r *http.Request, sess *session.T) { /
WHERE WHERE
service=$1 AND service=$1 AND
prio=$2 prio=$2
`, `,
(*notificationService).GetType(), (*notificationService).GetType(),
(*notificationService).GetPrio(), (*notificationService).GetPrio(),
problemID, problemID,

View File

@ -1,6 +1,2 @@
{{ define "fonts" }} {{ define "fonts" }}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap" rel="stylesheet">
{{ end }} {{ end }}

View File

@ -5,6 +5,18 @@
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
{{ template "fonts" }} {{ template "fonts" }}
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/main.css"> <link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/main.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.2.1/dist/chart.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/luxon@3.3.0/build/global/luxon.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@1.3.1"></script>
<script type="importmap">
{
"imports": {
"chart.js": "/js/{{ .VERSION }}/lib/chartjs/index.d.ts"
}
}
</script>
</head> </head>
<body> <body>
<div id="layout"> <div id="layout">

View File

@ -2,8 +2,19 @@
{{ $version := .VERSION }} {{ $version := .VERSION }}
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/datapoints.css"> <link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/datapoints.css">
<script type="module" defer>
import { DataGraph } from "/js/{{ .VERSION }}/datapoint_graph.mjs"
const graph = new DataGraph({{ .Data.Datapoint }})
graph.setData({{ .Data.Values }})
graph.render('chart')
</script>
{{ block "page_label" . }}{{end}} {{ block "page_label" . }}{{end}}
<div>
<canvas id="chart"></canvas>
</div>
<div id="values"> <div id="values">
{{ range .Data.Values }} {{ range .Data.Values }}
<div class="value">{{ format_time .Ts }}</div> <div class="value">{{ format_time .Ts }}</div>