Compare commits

...

15 commits

Author SHA1 Message Date
Svilen Markov
03b616622e Fix bug when making single request in job 2025-04-14 01:07:04 +01:00
Svilen Markov
50e1da01fe Add newline 2025-04-13 17:40:30 +01:00
Svilen Markov
f8f50b26d8 Add mountpoint:info CLI command 2025-04-13 17:09:51 +01:00
Svilen Markov
a3bc133bcb Maybe fix for missing mountpoint info 2025-04-13 16:52:17 +01:00
Svilen Markov
50dae22ff4 Add restart: unless-stopped 2025-04-13 16:15:59 +01:00
Svilen Markov
5a91154eab Document function 2025-04-13 16:08:04 +01:00
Ralph Ocdol
d5b89d512a added unique to filter arrays with unique items in custom-api 2025-04-13 16:07:54 +01:00
Svilen Markov
97f43f88eb Only set title if attribute isn't set 2025-04-11 23:14:06 +01:00
Svilen Markov
3177af9524 Add rounded class 2025-04-11 22:34:53 +01:00
Svilen Markov
f99d22738c Add replaceMatches 2025-04-11 20:37:45 +01:00
Ralph Ocdol
ea7124db52 feat: custom-api's replaceAll with regex support 2025-04-11 20:37:36 +01:00
Lucas L.
b1247e5de6 Add filter on already seen links for RSS feeds 2025-04-11 20:34:47 +01:00
Svilen Markov
5ab962634e Fix sorting bug in twitch channels widget 2025-04-11 20:34:03 +01:00
Svilen Markov
d99944dcff Avoid spinning up unnecessary goroutines for single data jobs 2025-04-11 20:33:24 +01:00
Svilen Markov
920bcb06dc Print warnings when failing to get sensors 2025-04-11 19:34:49 +01:00
11 changed files with 123 additions and 30 deletions

View file

@ -195,6 +195,7 @@ services:
glance:
container_name: glance
image: glanceapp/glance
restart: unless-stopped
volumes:
- ./config:/app/config
ports:

View file

@ -389,6 +389,7 @@ The following helper functions provided by Glance are available:
- `trimSuffix(suffix string, str string) string`: Trims the suffix from a string.
- `trimSpace(str string) string`: Trims whitespace from a string on both ends.
- `replaceAll(old string, new string, str string) string`: Replaces all occurrences of a string in a string.
- `replaceMatches(pattern string, replacement string, str string) string`: Replaces all occurrences of a regular expression in a string.
- `findMatch(pattern string, str string) string`: Finds the first match of a regular expression in a string.
- `findSubmatch(pattern string, str string) string`: Finds the first submatch of a regular expression in a string.
- `sortByString(key string, order string, arr []JSON): []JSON`: Sorts an array of JSON objects by a string key in either ascending or descending order.
@ -396,6 +397,7 @@ The following helper functions provided by Glance are available:
- `sortByFloat(key string, order string, arr []JSON): []JSON`: Sorts an array of JSON objects by a float key in either ascending or descending order.
- `sortByTime(key string, layout string, order string, arr []JSON): []JSON`: Sorts an array of JSON objects by a time key in either ascending or descending order. The format must be provided in Go's [date format](https://pkg.go.dev/time#pkg-constants).
- `concat(strings ...string) string`: Concatenates multiple strings together.
- `unique(key string, arr []JSON) []JSON`: Returns a unique array of JSON objects based on the given key.
The following helper functions provided by Go's `text/template` are available:

View file

@ -6,6 +6,7 @@ import (
"os"
"strings"
"github.com/shirou/gopsutil/v4/disk"
"github.com/shirou/gopsutil/v4/sensors"
)
@ -18,11 +19,13 @@ const (
cliIntentConfigPrint
cliIntentDiagnose
cliIntentSensorsPrint
cliIntentMountpointInfo
)
type cliOptions struct {
intent cliIntent
configPath string
args []string
}
func parseCliOptions() (*cliOptions, error) {
@ -46,6 +49,7 @@ func parseCliOptions() (*cliOptions, error) {
fmt.Println(" config:validate Validate the config file")
fmt.Println(" config:print Print the parsed config file with embedded includes")
fmt.Println(" sensors:print List all sensors")
fmt.Println(" mountpoint:info Print information about a given mountpoint path")
fmt.Println(" diagnose Run diagnostic checks")
}
configPath := flags.String("config", "glance.yml", "Set config path")
@ -72,6 +76,12 @@ func parseCliOptions() (*cliOptions, error) {
} else {
return nil, unknownCommandErr
}
} else if len(args) == 2 {
if args[0] == "mountpoint:info" {
intent = cliIntentMountpointInfo
} else {
return nil, unknownCommandErr
}
} else {
return nil, unknownCommandErr
}
@ -79,6 +89,7 @@ func parseCliOptions() (*cliOptions, error) {
return &cliOptions{
intent: intent,
configPath: *configPath,
args: args,
}, nil
}
@ -86,6 +97,12 @@ func cliSensorsPrint() int {
tempSensors, err := sensors.SensorsTemperatures()
if err != nil {
fmt.Printf("Failed to retrieve list of sensors: %v\n", err)
if warns, ok := err.(*sensors.Warnings); ok {
for _, w := range warns.List {
fmt.Printf(" - %v\n", w)
}
}
return 1
}
@ -100,3 +117,23 @@ func cliSensorsPrint() int {
return 0
}
func cliMountpointInfo(requestedPath string) int {
usage, err := disk.Usage(requestedPath)
if err != nil {
fmt.Printf("Failed to retrieve info for path %s: %v\n", requestedPath, err)
if warns, ok := err.(*disk.Warnings); ok {
for _, w := range warns.List {
fmt.Printf(" - %v\n", w)
}
}
return 1
}
fmt.Println("Path:", usage.Path)
fmt.Println("FS type:", ternary(usage.Fstype == "", "unknown", usage.Fstype))
fmt.Printf("Used percent: %.1f%%\n", usage.UsedPercent)
return 0
}

View file

@ -51,6 +51,8 @@ func Main() int {
fmt.Println(string(contents))
case cliIntentSensorsPrint:
return cliSensorsPrint()
case cliIntentMountpointInfo:
return cliMountpointInfo(options.args[1])
case cliIntentDiagnose:
runDiagnostic()
}

View file

@ -649,7 +649,7 @@ function setupTruncatedElementTitles() {
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
if (element.title === "") element.title = element.textContent;
if (element.getAttribute("title") === null) element.title = element.textContent;
}
}

View file

@ -2038,6 +2038,7 @@ details[open] .summary::after {
.color-primary { color: var(--color-primary); }
.cursor-help { cursor: help; }
.rounded { border-radius: var(--border-radius); }
.break-all { word-break: break-all; }
.text-left { text-align: left; }
.text-right { text-align: right; }

View file

@ -471,6 +471,13 @@ var customAPITemplateFuncs = func() template.FuncMap {
"replaceAll": func(old, new, s string) string {
return strings.ReplaceAll(s, old, new)
},
"replaceMatches": func(pattern, replacement, s string) string {
if s == "" {
return ""
}
return getCachedRegexp(pattern).ReplaceAllString(s, replacement)
},
"findMatch": func(pattern, s string) string {
if s == "" {
return ""
@ -536,6 +543,18 @@ var customAPITemplateFuncs = func() template.FuncMap {
"concat": func(items ...string) string {
return strings.Join(items, "")
},
"unique": func(key string, results []decoratedGJSONResult) []decoratedGJSONResult {
seen := make(map[string]struct{})
out := make([]decoratedGJSONResult, 0, len(results))
for _, result := range results {
val := result.String(key)
if _, ok := seen[val]; !ok {
seen[val] = struct{}{}
out = append(out, result)
}
}
return out
},
}
for key, value := range globalTemplateFunctions {

View file

@ -331,6 +331,7 @@ func fetchItemsFromRSSFeeds(requests []rssFeedRequest) (rssFeedItemList, error)
failed := 0
entries := make(rssFeedItemList, 0, len(feeds)*10)
seen := make(map[string]struct{})
for i := range feeds {
if errs[i] != nil {
@ -339,7 +340,13 @@ func fetchItemsFromRSSFeeds(requests []rssFeedRequest) (rssFeedItemList, error)
continue
}
entries = append(entries, feeds[i]...)
for _, item := range feeds[i] {
if _, exists := seen[item.Link]; exists {
continue
}
entries = append(entries, item)
seen[item.Link] = struct{}{}
}
}
if failed == len(requests) {

View file

@ -196,6 +196,10 @@ func fetchChannelFromTwitchTask(channel string) (twitchChannel, error) {
slog.Warn("Failed to parse Twitch stream started at", "error", err, "started_at", streamMetadata.UserOrNull.Stream.StartedAt)
}
}
} else {
// This prevents live channels with 0 viewers from being
// incorrectly sorted lower than offline channels
result.ViewersCount = -1
}
return result, nil

View file

@ -181,6 +181,11 @@ func workerPoolDo[I any, O any](job *workerPoolJob[I, O]) ([]O, []error, error)
return results, errs, nil
}
if len(job.data) == 1 {
results[0], errs[0] = job.task(job.data[0])
return results, errs, nil
}
tasksQueue := make(chan *workerPoolTask[I, O])
resultsQueue := make(chan *workerPoolTask[I, O])

View file

@ -227,35 +227,50 @@ func Collect(req *SystemInfoRequest) (*SystemInfo, []error) {
}
}
filesystems, err := disk.Partitions(false)
if err == nil {
for _, fs := range filesystems {
mpReq, ok := req.Mountpoints[fs.Mountpoint]
isHidden := req.HideMountpointsByDefault
if ok && mpReq.Hide != nil {
isHidden = *mpReq.Hide
}
if isHidden {
continue
}
usage, err := disk.Usage(fs.Mountpoint)
if err == nil {
mpInfo := MountpointInfo{
Path: fs.Mountpoint,
Name: mpReq.Name,
TotalMB: usage.Total / 1024 / 1024,
UsedMB: usage.Used / 1024 / 1024,
UsedPercent: uint8(math.Min(usage.UsedPercent, 100)),
}
info.Mountpoints = append(info.Mountpoints, mpInfo)
} else {
addErr(fmt.Errorf("getting filesystem usage for %s: %v", fs.Mountpoint, err))
}
addedMountpoints := map[string]struct{}{}
addMountpointInfo := func(requestedPath string, mpReq MointpointRequest) {
if _, exists := addedMountpoints[requestedPath]; exists {
return
}
} else {
addErr(fmt.Errorf("getting filesystems: %v", err))
isHidden := req.HideMountpointsByDefault
if mpReq.Hide != nil {
isHidden = *mpReq.Hide
}
if isHidden {
return
}
usage, err := disk.Usage(requestedPath)
if err == nil {
mpInfo := MountpointInfo{
Path: requestedPath,
Name: mpReq.Name,
TotalMB: usage.Total / 1024 / 1024,
UsedMB: usage.Used / 1024 / 1024,
UsedPercent: uint8(math.Min(usage.UsedPercent, 100)),
}
info.Mountpoints = append(info.Mountpoints, mpInfo)
addedMountpoints[requestedPath] = struct{}{}
} else {
addErr(fmt.Errorf("getting filesystem usage for %s: %v", requestedPath, err))
}
}
if !req.HideMountpointsByDefault {
filesystems, err := disk.Partitions(false)
if err == nil {
for _, fs := range filesystems {
addMountpointInfo(fs.Mountpoint, req.Mountpoints[fs.Mountpoint])
}
} else {
addErr(fmt.Errorf("getting filesystems: %v", err))
}
}
for mountpoint, mpReq := range req.Mountpoints {
addMountpointInfo(mountpoint, mpReq)
}
sort.Slice(info.Mountpoints, func(a, b int) bool {