@yuuki824/kanshi 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.env.example +34 -0
  2. package/Dockerfile +53 -0
  3. package/LICENSE +661 -0
  4. package/README.md +219 -0
  5. package/bin/kanshi.js +63 -0
  6. package/docker-compose.yml +84 -0
  7. package/go.mod +3 -0
  8. package/internal/access/access.go +275 -0
  9. package/internal/access/listeners.go +229 -0
  10. package/internal/config/config.go +256 -0
  11. package/internal/config/defaults_other.go +5 -0
  12. package/internal/config/defaults_windows.go +4 -0
  13. package/internal/config/envfile.go +147 -0
  14. package/internal/dockerstats/dial.go +32 -0
  15. package/internal/dockerstats/dial_other.go +13 -0
  16. package/internal/dockerstats/dial_windows.go +62 -0
  17. package/internal/dockerstats/dockerstats.go +626 -0
  18. package/internal/roots/roots.go +175 -0
  19. package/internal/roots/roots_linux.go +132 -0
  20. package/internal/roots/roots_windows.go +74 -0
  21. package/internal/server/access.go +155 -0
  22. package/internal/server/server.go +523 -0
  23. package/internal/server/static.go +165 -0
  24. package/internal/storage/cache.go +283 -0
  25. package/internal/storage/dir_linux.go +177 -0
  26. package/internal/storage/dir_windows.go +244 -0
  27. package/internal/storage/statat_fast.go +21 -0
  28. package/internal/storage/statat_other.go +11 -0
  29. package/internal/storage/storage.go +598 -0
  30. package/internal/storage/sysnum_amd64.go +7 -0
  31. package/internal/storage/sysnum_generic.go +7 -0
  32. package/internal/storage/walk.go +342 -0
  33. package/internal/vitals/vitals.go +246 -0
  34. package/internal/vitals/vitals_linux.go +548 -0
  35. package/internal/vitals/vitals_windows.go +286 -0
  36. package/main.go +129 -0
  37. package/main_other.go +11 -0
  38. package/main_windows.go +29 -0
  39. package/package.json +49 -0
  40. package/web/app.js +835 -0
  41. package/web/apple-touch-icon.png +0 -0
  42. package/web/icon.svg +6 -0
  43. package/web/index.html +151 -0
  44. package/web/style.css +356 -0
  45. package/web/treemap.js +217 -0
package/.env.example ADDED
@@ -0,0 +1,34 @@
1
+ # Copy to .env (Docker Compose) or kanshi.env (the standalone binary) to
2
+ # override. Every value here is the built-in default.
3
+
4
+ # Who can open the dashboard. This computer (localhost) always can. Add any of:
5
+ # lan other devices on your local network, wired or Wi-Fi
6
+ # tailscale your devices on your tailnet
7
+ # all every interface — kanshi has no login, so only behind a firewall
8
+ # Combine with commas, e.g. KANSHI_ACCESS=lan,tailscale
9
+ KANSHI_ACCESS=local
10
+ KANSHI_PORT=8100
11
+
12
+ # Live metrics
13
+ KANSHI_POLL_INTERVAL=5
14
+ KANSHI_DOCKER_CONCURRENCY=8
15
+ KANSHI_IDLE_TIMEOUT=30
16
+
17
+ # Storage map. "auto" is / plus every drive under /mnt on Linux, or C:\, your
18
+ # user folder and every other fixed drive on Windows. List paths to replace
19
+ # that, or mix: auto,/srv
20
+ KANSHI_STORAGE_ROOTS=auto
21
+ # A cached folder size older than this many seconds is measured again the next
22
+ # time the folder around it is opened.
23
+ KANSHI_STORAGE_INTERVAL=21600
24
+ # Paths to skip entirely, comma separated. The biggest win on a Docker host is
25
+ # /var/lib/docker — ~100k overlay2 files.
26
+ KANSHI_STORAGE_EXCLUDE=
27
+ # Share of one core, in percent, the walk may average. 100 = unthrottled.
28
+ KANSHI_STORAGE_CPU=25
29
+ # Folder levels remembered from each measurement. Deeper folders are measured
30
+ # when they are opened.
31
+ KANSHI_TREE_DEPTH=4
32
+ # Where folder sizes are cached. Defaults to ~/.cache/kanshi/storage.cache on
33
+ # Linux and %LocalAppData%\kanshi\storage.cache on Windows.
34
+ #KANSHI_STORAGE_CACHE=
package/Dockerfile ADDED
@@ -0,0 +1,53 @@
1
+ # Build stage. It always runs on the build machine's own architecture and
2
+ # cross-compiles for the target, which Go does natively — so a multi-arch
3
+ # image builds at full speed with no QEMU emulation. The module has no
4
+ # third-party dependencies, so there is nothing to download.
5
+ FROM --platform=$BUILDPLATFORM golang:1.27-alpine AS build
6
+
7
+ ARG TARGETOS=linux
8
+ ARG TARGETARCH
9
+ ARG VERSION=dev
10
+
11
+ WORKDIR /src
12
+ COPY go.mod ./
13
+ COPY main.go main_other.go ./
14
+ COPY internal ./internal
15
+ COPY web ./web
16
+
17
+ # CGO off because nothing here needs libc: /proc is read as plain files and the
18
+ # Docker socket is a plain unix socket. That is what makes a scratch image
19
+ # possible at all.
20
+ ENV CGO_ENABLED=0
21
+ RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath \
22
+ -ldflags="-s -w -X main.version=${VERSION}" -o /kanshi .
23
+
24
+ # Runtime stage. The web assets are embedded in the binary, so the image is one
25
+ # static file and nothing else — no shell, no package manager, no CVE surface.
26
+ FROM scratch
27
+
28
+ ARG VERSION=dev
29
+ LABEL org.opencontainers.image.title="kanshi" \
30
+ org.opencontainers.image.description="A one-page, mobile-first glance at a homeserver: CPU, memory, a storage treemap and Docker containers." \
31
+ org.opencontainers.image.source="https://github.com/rene-roid/kanshi" \
32
+ org.opencontainers.image.licenses="AGPL-3.0-only" \
33
+ org.opencontainers.image.version="${VERSION}"
34
+
35
+ COPY --from=build /kanshi /kanshi
36
+
37
+ # The Compose file mounts the host's / here; the storage map then finds the
38
+ # host's drives under /hostfs/mnt on its own.
39
+ ENV KANSHI_HOST_ROOT=/hostfs
40
+
41
+ # Folder sizes are cached here so a restart does not walk the disk again. The
42
+ # root filesystem is read-only, so this has to be a volume.
43
+ ENV KANSHI_STORAGE_CACHE=/data/storage.cache
44
+ VOLUME /data
45
+
46
+ EXPOSE 8100
47
+
48
+ # The probe is the binary itself: a scratch image has no curl to call. It asks
49
+ # 127.0.0.1, which is listened on in every access mode.
50
+ HEALTHCHECK --interval=60s --timeout=5s --start-period=10s --retries=3 \
51
+ CMD ["/kanshi", "-healthcheck"]
52
+
53
+ ENTRYPOINT ["/kanshi"]