Skip to content

Commit

Permalink
fix: added config option for page refresh interval
Browse files Browse the repository at this point in the history
  • Loading branch information
henrywhitaker3 committed Apr 20, 2024
1 parent 75ee96b commit beccef7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ configuration:
ui:
# The title of the page
title: Status Page
# How often the page reloads
refresh: 30s

imagePullSecrets: []
nameOverride: ""
Expand Down
6 changes: 5 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type Service struct {
}

type UI struct {
PageTitle string `yaml:"title"`
PageTitle string `yaml:"title"`
RefreshInterval time.Duration `yaml:"refresh"`
}

type Metrics struct {
Expand Down Expand Up @@ -96,6 +97,9 @@ func setDefaults(conf *Config) {
if conf.UI.PageTitle == "" {
conf.UI.PageTitle = "PromPage"
}
if conf.UI.RefreshInterval == 0 {
conf.UI.RefreshInterval = time.Second * 30
}
}

func (c *Config) Validate() error {
Expand Down
2 changes: 2 additions & 0 deletions internal/http/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type statusData struct {
Outage string
BannerClasses string
Version string
Refresh int
}

func (s statusData) Sprintf(format string, a ...any) string {
Expand All @@ -59,6 +60,7 @@ func NewStatusPageHandler(app *app.App, cache *ResultCache) echo.HandlerFunc {
Outage: op,
BannerClasses: bannerClasses(op),
Version: app.Version,
Refresh: int(app.Config.UI.RefreshInterval / time.Millisecond),
}
var buf bytes.Buffer
if err := tmpl.Execute(&buf, data); err != nil {
Expand Down
Binary file added internal/resources/static/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion internal/resources/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/tailwind.css?v={{ .Version }}" />
<link rel="icon" type="image/png" href="/static/icon.png" />
<title>{{ .Config.UI.PageTitle }}</title>
</head>
<body class="mx-auto min-h-dvh w-full md:w-3/4 p-6 md:p-8 lg:p-6 lg:w-1/2 flex flex-col justify-between bg-neutral-50">
Expand Down Expand Up @@ -54,7 +55,7 @@ <h3 class="text-lg font-bold inline-block mr-2">{{ .Service.Name }}</h2>
</div>

<script>
setTimeout(() => { location.reload() }, 15000)
setTimeout(() => { location.reload() }, {{ .Refresh }})
</script>
</body>
</html>

0 comments on commit beccef7

Please sign in to comment.