@yaks/file 0.0.0-stage → 0.2.36
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.
- package/LICENSE +202 -0
- package/README.md +121 -2
- package/_dist/blobs.d.ts +16 -0
- package/_dist/blobs.d.ts.map +1 -0
- package/_dist/io.d.ts +148 -0
- package/_dist/io.d.ts.map +1 -0
- package/_dist/local.d.ts +18 -0
- package/_dist/local.d.ts.map +1 -0
- package/_dist/mod.d.ts +27 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/occupancy.d.ts +207 -0
- package/_dist/occupancy.d.ts.map +1 -0
- package/_dist/service.d.ts +31 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/views.d.ts +24 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +9 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/blobs.js +47 -0
- package/blobs.js.map +1 -0
- package/blobs.ts +52 -0
- package/deno.json +1 -0
- package/io.js +361 -0
- package/io.js.map +1 -0
- package/io.ts +528 -0
- package/local.js +105 -0
- package/local.js.map +1 -0
- package/local.ts +91 -0
- package/measure.js +88 -0
- package/measure.js.map +1 -0
- package/measure.ts +109 -0
- package/mod.js +86 -0
- package/mod.js.map +1 -0
- package/mod.ts +84 -0
- package/occupancy.js +256 -0
- package/occupancy.js.map +1 -0
- package/occupancy.ts +341 -0
- package/package.json +54 -4
- package/page.js +296 -0
- package/page.js.map +1 -0
- package/page.ts +444 -0
- package/service.js +116 -0
- package/service.js.map +1 -0
- package/service.ts +155 -0
- package/upkeep.js +52 -0
- package/upkeep.js.map +1 -0
- package/upkeep.ts +78 -0
- package/views.js +27 -0
- package/views.js.map +1 -0
- package/views.ts +25 -0
- package/vocab.js +19 -0
- package/vocab.js.map +1 -0
- package/vocab.json +163 -0
- package/vocab.ts +20 -0
package/page.ts
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A machine's disks, as the browsing app draws them. For each volume: how full
|
|
3
|
+
* it is and how fast that is changing; what fills it, a tree of directories
|
|
4
|
+
* and files to open, each with its share and its change since a week before;
|
|
5
|
+
* its largest files; and day by day. The file the graph keeps its pages in
|
|
6
|
+
* says how much of it is free pages, from the store's own measurement
|
|
7
|
+
* (`kept{file, free}`, @yaks/journal), and links to History.
|
|
8
|
+
*
|
|
9
|
+
* Everything is read from the rows the duty writes (./service.ts): opening the
|
|
10
|
+
* page measures nothing. Which directories are open is the page's own state,
|
|
11
|
+
* a `Disclosure{open}` on an entity derived from the volume and the path; a
|
|
12
|
+
* directory holding a tenth of what is used opens by itself until then.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
|
|
17
|
+
import { parse } from '@yaks/query'
|
|
18
|
+
import {
|
|
19
|
+
type Answer,
|
|
20
|
+
type Bundle,
|
|
21
|
+
type Io,
|
|
22
|
+
mention,
|
|
23
|
+
type Props,
|
|
24
|
+
useNamed,
|
|
25
|
+
type View,
|
|
26
|
+
} from '@yaks/inspect'
|
|
27
|
+
import { Head, Loading, Meter, Section, Table } from '@yaks/ui'
|
|
28
|
+
import { disclosed, disclosureAt, isOpen } from '@yaks/ux'
|
|
29
|
+
import { joined, size } from './mod.js'
|
|
30
|
+
import {
|
|
31
|
+
change,
|
|
32
|
+
files,
|
|
33
|
+
grew,
|
|
34
|
+
type Line,
|
|
35
|
+
lines,
|
|
36
|
+
named,
|
|
37
|
+
type Occupancy,
|
|
38
|
+
occupancyIn,
|
|
39
|
+
occupancyOf,
|
|
40
|
+
opens,
|
|
41
|
+
pagesFree,
|
|
42
|
+
perDay,
|
|
43
|
+
since,
|
|
44
|
+
uncounted,
|
|
45
|
+
within,
|
|
46
|
+
} from './occupancy.js'
|
|
47
|
+
|
|
48
|
+
let { Body, Cell, Heading, Row } = Table
|
|
49
|
+
|
|
50
|
+
/** How many days of looks the trend reads. */
|
|
51
|
+
export let DAYS = 31
|
|
52
|
+
|
|
53
|
+
/** How many days before the latest look a change is read against. */
|
|
54
|
+
export let WEEK = 7
|
|
55
|
+
|
|
56
|
+
/** How many of the largest files are listed. */
|
|
57
|
+
export let FILES = 15
|
|
58
|
+
|
|
59
|
+
// What the trend reads of each look: its figures, never its paths.
|
|
60
|
+
let FIGURES = ['day', 'at', 'size', 'used', 'free', 'counted']
|
|
61
|
+
.map((p) => `occupancy.${p}`).join(',')
|
|
62
|
+
|
|
63
|
+
type Volume = { machine: string; mount: string }
|
|
64
|
+
type Kept = { file?: string; free?: number }
|
|
65
|
+
|
|
66
|
+
let rows = (a?: Answer): Bundle[] => a?.rows ?? []
|
|
67
|
+
let looks = (a?: Answer): Occupancy[] =>
|
|
68
|
+
rows(a).map((b) => occupancyIn(b)).filter((o): o is Occupancy => !!o)
|
|
69
|
+
let share = (part: number, whole: number) =>
|
|
70
|
+
whole ? `${Math.round((part / whole) * 100)}%` : ''
|
|
71
|
+
|
|
72
|
+
let waiting = (got: Answer | undefined, what: string) =>
|
|
73
|
+
got?.error
|
|
74
|
+
? h(Section.Sub, { role: 'alert' }, got.error)
|
|
75
|
+
: !got?.ready
|
|
76
|
+
? h(Loading, {}, `Loading ${what}…`)
|
|
77
|
+
: null
|
|
78
|
+
|
|
79
|
+
// The rows under headings every table here has: a name, a bar, numbers.
|
|
80
|
+
let Ranked = (
|
|
81
|
+
{ heads, children }: { heads: string[]; children?: ReactNode },
|
|
82
|
+
) =>
|
|
83
|
+
h(
|
|
84
|
+
Table,
|
|
85
|
+
{ cols: [null, null, ...heads.map(() => 'num')] },
|
|
86
|
+
h(
|
|
87
|
+
Table.Head,
|
|
88
|
+
{},
|
|
89
|
+
h(
|
|
90
|
+
Row,
|
|
91
|
+
{},
|
|
92
|
+
h(Heading, {}, ''),
|
|
93
|
+
h(Heading, {}, ''),
|
|
94
|
+
...heads.map((k) => h(Heading, { key: k, mod: 'num' }, k)),
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
h(Body, {}, children),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
// A row of bytes: its name, its share of `of` as a bar, its bytes and how
|
|
101
|
+
// they changed. A directory's row is pressed to open or close it, by the
|
|
102
|
+
// pointer or by Enter or Space where it has the keyboard.
|
|
103
|
+
let Measured = (
|
|
104
|
+
{ name, bytes, of, grown, mod, open, toggle }: {
|
|
105
|
+
name: ReactNode
|
|
106
|
+
bytes: number
|
|
107
|
+
of: number
|
|
108
|
+
grown: string
|
|
109
|
+
mod?: string
|
|
110
|
+
open?: boolean
|
|
111
|
+
toggle?: () => void
|
|
112
|
+
},
|
|
113
|
+
) =>
|
|
114
|
+
h(
|
|
115
|
+
Row,
|
|
116
|
+
toggle
|
|
117
|
+
? {
|
|
118
|
+
mod: [mod, 'picks'],
|
|
119
|
+
tabIndex: 0,
|
|
120
|
+
'aria-expanded': open,
|
|
121
|
+
onClick: toggle,
|
|
122
|
+
onKeyDown: (e: KeyboardEvent) => {
|
|
123
|
+
if (e.key != 'Enter' && e.key != ' ') return
|
|
124
|
+
e.preventDefault()
|
|
125
|
+
toggle()
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
: { mod },
|
|
129
|
+
h(Cell, {}, name),
|
|
130
|
+
h(Cell, {}, h(Meter, { value: bytes / (of || 1), width: 10 })),
|
|
131
|
+
h(Cell, { mod: 'num' }, size(bytes)),
|
|
132
|
+
h(Cell, { mod: 'num' }, grown),
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
// Where a path is the file the graph keeps its pages in: how many of them
|
|
136
|
+
// are free, linking to History, which says more.
|
|
137
|
+
let freePages = (volume: string, path: string, kept?: Kept) => {
|
|
138
|
+
let free = pagesFree(kept, volume, path)
|
|
139
|
+
return free == null
|
|
140
|
+
? []
|
|
141
|
+
: [' · ', h('a', { href: '/?page=history' }, `${size(free)} free pages`)]
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Leading room a level deep in the tree, kept by both hosts.
|
|
145
|
+
let indent = (depth: number) => ' '.repeat(depth)
|
|
146
|
+
|
|
147
|
+
/** What fills a volume: every directory and file listed in a directory, the
|
|
148
|
+
* open ones' own beneath them, and what each leaves too small to list. */
|
|
149
|
+
let Tree = (
|
|
150
|
+
{ io, eid, newer, older, kept }: {
|
|
151
|
+
io: Io
|
|
152
|
+
eid: string
|
|
153
|
+
newer: Occupancy
|
|
154
|
+
older?: Occupancy
|
|
155
|
+
kept?: Kept
|
|
156
|
+
},
|
|
157
|
+
) => {
|
|
158
|
+
let state = (path: string): Bundle => {
|
|
159
|
+
let at = disclosureAt(`${eid}|${path}`)
|
|
160
|
+
return io.state(at) ?? { entity: { eid: at } }
|
|
161
|
+
}
|
|
162
|
+
let opened = (path: string, bytes: number) => {
|
|
163
|
+
let s = state(path)
|
|
164
|
+
return opens(s.Disclosure ? isOpen(s) : undefined, bytes, newer.used)
|
|
165
|
+
}
|
|
166
|
+
// A directory wears whether it is open; a file stands where that would.
|
|
167
|
+
let name = (l: Line): ReactNode =>
|
|
168
|
+
l.rest
|
|
169
|
+
? within(newer, l.path).listed.length ? 'the rest' : 'all of it'
|
|
170
|
+
: l.open == null
|
|
171
|
+
? [' ', named(l.path), ...freePages(eid, l.path, kept)]
|
|
172
|
+
: `${l.open ? '▾' : '▸'} ${named(l.path)}`
|
|
173
|
+
let missed = uncounted(newer)
|
|
174
|
+
return h(
|
|
175
|
+
Ranked,
|
|
176
|
+
{ heads: ['bytes', older ? `since ${older.day}` : 'change'] },
|
|
177
|
+
lines(newer, opened).map((l) =>
|
|
178
|
+
h(
|
|
179
|
+
Measured,
|
|
180
|
+
{
|
|
181
|
+
key: `${l.path}${l.rest ? '…' : ''}`,
|
|
182
|
+
mod: l.rest ? 'quiet' : undefined,
|
|
183
|
+
name: [indent(l.depth), name(l)],
|
|
184
|
+
bytes: l.bytes,
|
|
185
|
+
of: newer.counted,
|
|
186
|
+
grown: l.rest ? '' : change(grew(older, newer, l.path), !!older),
|
|
187
|
+
open: l.open,
|
|
188
|
+
toggle: l.open == null || l.rest
|
|
189
|
+
? undefined
|
|
190
|
+
: () => io.set([disclosed(state(l.path), !l.open)]),
|
|
191
|
+
},
|
|
192
|
+
)
|
|
193
|
+
),
|
|
194
|
+
missed
|
|
195
|
+
? h(Measured, {
|
|
196
|
+
key: '…',
|
|
197
|
+
mod: 'quiet',
|
|
198
|
+
name: 'not counted: unreadable here, or the filesystem’s own',
|
|
199
|
+
bytes: missed,
|
|
200
|
+
of: newer.counted,
|
|
201
|
+
grown: '',
|
|
202
|
+
})
|
|
203
|
+
: null,
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The largest files on a volume, by where they are on its machine. */
|
|
208
|
+
let Files = (
|
|
209
|
+
{ eid, mount, newer, older, kept }: {
|
|
210
|
+
eid: string
|
|
211
|
+
mount: string
|
|
212
|
+
newer: Occupancy
|
|
213
|
+
older?: Occupancy
|
|
214
|
+
kept?: Kept
|
|
215
|
+
},
|
|
216
|
+
) => {
|
|
217
|
+
let largest = files(newer, FILES)
|
|
218
|
+
return largest.length
|
|
219
|
+
? h(
|
|
220
|
+
Section,
|
|
221
|
+
{},
|
|
222
|
+
h(
|
|
223
|
+
Section.Title,
|
|
224
|
+
{},
|
|
225
|
+
'Largest files ',
|
|
226
|
+
h(Section.Count, {}, String(largest.length)),
|
|
227
|
+
),
|
|
228
|
+
h(
|
|
229
|
+
Ranked,
|
|
230
|
+
{ heads: ['bytes', older ? `since ${older.day}` : 'change'] },
|
|
231
|
+
largest.map(([path, bytes]) =>
|
|
232
|
+
h(Measured, {
|
|
233
|
+
key: path,
|
|
234
|
+
name: [joined(mount, path), ...freePages(eid, path, kept)],
|
|
235
|
+
bytes,
|
|
236
|
+
of: newer.counted,
|
|
237
|
+
grown: change(grew(older, newer, path), !!older),
|
|
238
|
+
})
|
|
239
|
+
),
|
|
240
|
+
),
|
|
241
|
+
)
|
|
242
|
+
: null
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** Each day's look, newest first, beside the day before it. */
|
|
246
|
+
let Days = ({ days }: { days: Occupancy[] }) =>
|
|
247
|
+
h(
|
|
248
|
+
Section,
|
|
249
|
+
{},
|
|
250
|
+
h(
|
|
251
|
+
Section.Title,
|
|
252
|
+
{},
|
|
253
|
+
'Day by day ',
|
|
254
|
+
h(Section.Count, {}, String(days.length)),
|
|
255
|
+
),
|
|
256
|
+
h(
|
|
257
|
+
Ranked,
|
|
258
|
+
{ heads: ['used', 'free', 'change'] },
|
|
259
|
+
days.map((o, i) => {
|
|
260
|
+
let before = days[i + 1]
|
|
261
|
+
return h(
|
|
262
|
+
Row,
|
|
263
|
+
{ key: o.day },
|
|
264
|
+
h(Cell, {}, o.day),
|
|
265
|
+
h(Cell, {}, h(Meter, { value: o.used / (o.size || 1), width: 10 })),
|
|
266
|
+
h(Cell, { mod: 'num' }, size(o.used)),
|
|
267
|
+
h(Cell, { mod: 'num' }, size(o.free)),
|
|
268
|
+
h(
|
|
269
|
+
Cell,
|
|
270
|
+
{ mod: 'num' },
|
|
271
|
+
before ? change(o.used - before.used, true) : '',
|
|
272
|
+
),
|
|
273
|
+
)
|
|
274
|
+
}),
|
|
275
|
+
),
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
/** A volume: how full it is and how fast that is changing, what fills it,
|
|
279
|
+
* its largest files, and day by day. */
|
|
280
|
+
let Disk = (
|
|
281
|
+
{ io, volume, named: onMachine, kept }: {
|
|
282
|
+
io: Io
|
|
283
|
+
volume: Bundle
|
|
284
|
+
named?: boolean
|
|
285
|
+
kept?: Kept
|
|
286
|
+
},
|
|
287
|
+
): JSX.Element => {
|
|
288
|
+
let eid = volume.entity.eid
|
|
289
|
+
let { machine, mount } = volume.volume as Volume
|
|
290
|
+
let trend = io.ask({
|
|
291
|
+
days:
|
|
292
|
+
`.occupancy.volume=${eid} .order=-occupancy.day .limit=${DAYS} .fields=${FIGURES}`,
|
|
293
|
+
}).days
|
|
294
|
+
let days = looks(trend)
|
|
295
|
+
let [last] = days
|
|
296
|
+
let then = since(days, WEEK)
|
|
297
|
+
let full = io.ask(
|
|
298
|
+
last
|
|
299
|
+
? {
|
|
300
|
+
now: `.entity.eid=${occupancyOf(eid, last.day)} *`,
|
|
301
|
+
...then ? { then: `.entity.eid=${occupancyOf(eid, then.day)} *` } : {},
|
|
302
|
+
}
|
|
303
|
+
: {},
|
|
304
|
+
)
|
|
305
|
+
let newer = looks(full.now)[0]
|
|
306
|
+
let older = looks(full.then)[0]
|
|
307
|
+
let daily = then && perDay(then, last, (o) => o.used)
|
|
308
|
+
return h(
|
|
309
|
+
Section,
|
|
310
|
+
{ 'data-volume': eid },
|
|
311
|
+
h(
|
|
312
|
+
Section.Title,
|
|
313
|
+
{},
|
|
314
|
+
mount,
|
|
315
|
+
onMachine ? [' on ', mention(io, machine)] : null,
|
|
316
|
+
),
|
|
317
|
+
waiting(trend, 'its looks') ?? (!last
|
|
318
|
+
? h(
|
|
319
|
+
Section.Sub,
|
|
320
|
+
{},
|
|
321
|
+
'Not looked at yet: the duty looks at the disks of the computer it runs on every hour.',
|
|
322
|
+
)
|
|
323
|
+
: [
|
|
324
|
+
h(Meter, {
|
|
325
|
+
key: 'fill',
|
|
326
|
+
value: last.used / (last.size || 1),
|
|
327
|
+
width: 40,
|
|
328
|
+
}),
|
|
329
|
+
h(
|
|
330
|
+
Head.Facts,
|
|
331
|
+
{ key: 'facts' },
|
|
332
|
+
`${size(last.used)} of ${size(last.size)} used (${
|
|
333
|
+
share(last.used, last.size)
|
|
334
|
+
})`,
|
|
335
|
+
`${size(last.free)} free`,
|
|
336
|
+
...daily == null ? [] : [
|
|
337
|
+
daily
|
|
338
|
+
? `${change(daily, true)} a day since ${then!.day}`
|
|
339
|
+
: `unchanged since ${then!.day}`,
|
|
340
|
+
],
|
|
341
|
+
`looked ${io.when(last.at)}`,
|
|
342
|
+
),
|
|
343
|
+
!newer ? waiting(full.now, 'what fills it') : h(
|
|
344
|
+
Section,
|
|
345
|
+
{ key: 'tree' },
|
|
346
|
+
h(Section.Title, {}, 'What fills it'),
|
|
347
|
+
h(Tree, { io, eid, newer, older, kept }),
|
|
348
|
+
),
|
|
349
|
+
newer
|
|
350
|
+
? h(Files, { key: 'files', eid, mount, newer, older, kept })
|
|
351
|
+
: null,
|
|
352
|
+
h(Days, { key: 'days', days }),
|
|
353
|
+
]),
|
|
354
|
+
)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// The store's own measurement of its file, where the graph keeps one.
|
|
358
|
+
let keptOf = (io: Io): Kept | undefined => {
|
|
359
|
+
let got = io.ask(
|
|
360
|
+
io.vocab.comp('kept')
|
|
361
|
+
? { kept: '.kept .order=-kept.day .limit=1 .fields=kept.file,kept.free' }
|
|
362
|
+
: {},
|
|
363
|
+
).kept
|
|
364
|
+
return rows(got)[0]?.kept as Kept | undefined
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** The disks of each machine a volume is known on, or of one. */
|
|
368
|
+
let Disks = (
|
|
369
|
+
{ io, volumes, named: onMachine }: {
|
|
370
|
+
io: Io
|
|
371
|
+
volumes?: Answer
|
|
372
|
+
named?: boolean
|
|
373
|
+
},
|
|
374
|
+
) => {
|
|
375
|
+
let kept = keptOf(io)
|
|
376
|
+
let all = rows(volumes).toSorted((a, b) =>
|
|
377
|
+
String((a.volume as Volume).mount).localeCompare(
|
|
378
|
+
String((b.volume as Volume).mount),
|
|
379
|
+
)
|
|
380
|
+
)
|
|
381
|
+
useNamed(io, all.map((v) => (v.volume as Volume).machine))
|
|
382
|
+
return waiting(volumes, 'the disks') ?? (all.length
|
|
383
|
+
? h(
|
|
384
|
+
'div',
|
|
385
|
+
{},
|
|
386
|
+
all.map((v) =>
|
|
387
|
+
h(Disk, { key: v.entity.eid, io, volume: v, named: onMachine, kept })
|
|
388
|
+
),
|
|
389
|
+
)
|
|
390
|
+
: h(
|
|
391
|
+
Section.Sub,
|
|
392
|
+
{},
|
|
393
|
+
'No disk of it has been looked at. The duty looks at the disks of the computer it runs on.',
|
|
394
|
+
))
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** A machine's disks, or a volume's, under its head. */
|
|
398
|
+
export let DisksTab = ({ e, io, got }: Props): JSX.Element =>
|
|
399
|
+
h(
|
|
400
|
+
'div',
|
|
401
|
+
{ 'data-disks': e.entity.eid },
|
|
402
|
+
io.show(e, 'Inspect.Head', {}),
|
|
403
|
+
e.volume
|
|
404
|
+
? h(Disk, { io, volume: e, kept: keptOf(io) })
|
|
405
|
+
: h(Disks, { io, volumes: got.volumes }),
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
/** Every disk looked at, by machine: the page the sidebar offers. */
|
|
409
|
+
export let DisksPage = ({ io, got }: Props): JSX.Element =>
|
|
410
|
+
h(
|
|
411
|
+
'article',
|
|
412
|
+
{},
|
|
413
|
+
h(
|
|
414
|
+
Head,
|
|
415
|
+
{},
|
|
416
|
+
h(Head.Title, {}, 'Disks'),
|
|
417
|
+
h(
|
|
418
|
+
Head.Sub,
|
|
419
|
+
{},
|
|
420
|
+
'How full each disk is and what fills it, from a look every hour by the computer it is on.',
|
|
421
|
+
),
|
|
422
|
+
),
|
|
423
|
+
h(Disks, { io, volumes: got.volumes, named: true }),
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
let machine = parse('.machine')
|
|
427
|
+
let volume = parse('.volume')
|
|
428
|
+
|
|
429
|
+
/** The views this package draws in the browsing app. */
|
|
430
|
+
export let inspectViews: View[] = [
|
|
431
|
+
{
|
|
432
|
+
view: 'Disks.Page',
|
|
433
|
+
match: true,
|
|
434
|
+
asks: () => ({ volumes: '.volume *' }),
|
|
435
|
+
Render: DisksPage,
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
view: 'Disks',
|
|
439
|
+
match: machine,
|
|
440
|
+
asks: (e) => ({ volumes: `.volume.machine=${e.entity.eid} *` }),
|
|
441
|
+
Render: DisksTab,
|
|
442
|
+
},
|
|
443
|
+
{ view: 'Disks', match: volume, Render: DisksTab },
|
|
444
|
+
]
|
package/service.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What fills this computer's disks, as a duty: the module a server imports at
|
|
3
|
+
* `@yaks/file/service`. Each pass reads the computer's disks, and walks
|
|
4
|
+
* each one whose day has no look yet (one filesystem at a time through the
|
|
5
|
+
* file API) into the day's `occupancy` row. A walk lstats every file on the
|
|
6
|
+
* disk, about a CPU for minutes on a box of agents' checkouts, so a disk is
|
|
7
|
+
* walked once a day, never more. The Disks page reads only those rows (./page.ts),
|
|
8
|
+
* so opening it measures nothing.
|
|
9
|
+
*
|
|
10
|
+
* A walk stops when the process winds down, and the next process
|
|
11
|
+
* walks again from its first pass; what an earlier walk read is still in the
|
|
12
|
+
* kernel's cache, so the next goes faster.
|
|
13
|
+
*
|
|
14
|
+
* Each pass also tells the host of a disk newly below its floor, and every
|
|
15
|
+
* `AGAIN` prunes the configured mirror caches (./upkeep.ts).
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/ import { disksAt, paced, walk } from "./measure.js";
|
|
19
|
+
import { homedir } from "./io.js";
|
|
20
|
+
import { sleep } from "@yaks/fp";
|
|
21
|
+
import { volumeOf } from "./mod.js";
|
|
22
|
+
import { here } from "./local.js";
|
|
23
|
+
import { lows, prune } from "./upkeep.js";
|
|
24
|
+
import { listed, occupancyIn, occupancyOf } from "./occupancy.js";
|
|
25
|
+
/** How long a pass waits for the next, in milliseconds: five minutes, so a
|
|
26
|
+
* disk running low is told within them. A walk still waits for the next day. */ export let EVERY = 5 * 60 * 1000;
|
|
27
|
+
/** How often the mirror caches are pruned: an hour. */ export let AGAIN = 60 * 60 * 1000;
|
|
28
|
+
/** This computer, measured through the file API: the disks holding its root
|
|
29
|
+
* and the home directory. */ export let computer = {
|
|
30
|
+
disks: ()=>disksAt([
|
|
31
|
+
'/',
|
|
32
|
+
homedir()
|
|
33
|
+
]),
|
|
34
|
+
// A quarter of one CPU at most: unpaced, a walk held a whole CPU for over
|
|
35
|
+
// ten minutes beside agents' test runs (bug 60286e2677).
|
|
36
|
+
walk: (mount, least, signal)=>walk(mount, least, signal, undefined, paced())
|
|
37
|
+
};
|
|
38
|
+
/** One pass: walk each of this computer's disks whose day has no look yet,
|
|
39
|
+
* into its day's row. */ export let pass = async (g, look = computer, now = Date.now(), signal)=>{
|
|
40
|
+
let machine = await here(g);
|
|
41
|
+
let day = new Date(now).toISOString().slice(0, 10);
|
|
42
|
+
for (let disk of (await look.disks())){
|
|
43
|
+
let volume = volumeOf(machine, disk.mount);
|
|
44
|
+
let eid = occupancyOf(volume, day);
|
|
45
|
+
let held = await g.get([
|
|
46
|
+
eid,
|
|
47
|
+
volume
|
|
48
|
+
], [
|
|
49
|
+
'occupancy',
|
|
50
|
+
'volume'
|
|
51
|
+
]);
|
|
52
|
+
let had = held.find((b)=>b.entity.eid == eid);
|
|
53
|
+
let known = held.find((b)=>b.entity.eid == volume);
|
|
54
|
+
if (occupancyIn(had)) continue;
|
|
55
|
+
let walk = await look.walk(disk.mount, listed(disk.size), signal);
|
|
56
|
+
if (!walk) return;
|
|
57
|
+
// The filesystem's figures as the walk ends, so they and it agree.
|
|
58
|
+
let { size, used, free } = (await look.disks()).find((d)=>d.mount == disk.mount) ?? disk;
|
|
59
|
+
await g.apply([
|
|
60
|
+
...known?.volume ? [] : [
|
|
61
|
+
{
|
|
62
|
+
entity: {
|
|
63
|
+
eid: volume
|
|
64
|
+
},
|
|
65
|
+
volume: {
|
|
66
|
+
machine,
|
|
67
|
+
mount: disk.mount
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
{
|
|
72
|
+
entity: {
|
|
73
|
+
eid
|
|
74
|
+
},
|
|
75
|
+
occupancy: {
|
|
76
|
+
volume,
|
|
77
|
+
day,
|
|
78
|
+
at: new Date().toISOString(),
|
|
79
|
+
size,
|
|
80
|
+
used,
|
|
81
|
+
free,
|
|
82
|
+
...walk
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
], {
|
|
86
|
+
trusted: true
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
/** Look, then look again every `every`, until the signal aborts. An already
|
|
91
|
+
* aborted signal is one pass. Each pass tells the host of a disk newly below
|
|
92
|
+
* its floor, as a failure: a full disk fails every write on it. */ export let service = async (host, options = {}, signal = AbortSignal.abort())=>{
|
|
93
|
+
let report = (e, step)=>(host.report ?? console.error)(e, {
|
|
94
|
+
tags: {
|
|
95
|
+
step
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
let told = new Set();
|
|
99
|
+
let pruned = 0;
|
|
100
|
+
for(;;){
|
|
101
|
+
let stopping = signal.aborted ? undefined : signal;
|
|
102
|
+
// Each step that failed is told, and the next pass tries it again.
|
|
103
|
+
await computer.disks().then((disks)=>lows(disks, told, options.floor)).then((low)=>low.forEach((e)=>report(e, 'disk space'))).catch((e)=>report(e, 'disk space'));
|
|
104
|
+
if (Date.now() - pruned >= AGAIN) {
|
|
105
|
+
pruned = Date.now();
|
|
106
|
+
for (let mirror of options.mirrors ?? []){
|
|
107
|
+
await prune(mirror, stopping).catch((e)=>report(e, 'cache prune'));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
await pass(host.graph, computer, Date.now(), stopping).catch((e)=>report(e, 'disk look'));
|
|
111
|
+
if (signal.aborted) return;
|
|
112
|
+
await sleep(options.every ?? EVERY, signal);
|
|
113
|
+
if (signal.aborted) return;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=service.js.map
|
package/service.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sources":["./service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;CAiBC,GACD,SAAS,OAAO,EAAE,KAAK,EAAE,IAAI,uBAAsB;AACnD,SAAS,OAAO,kBAAiB;AAEjC,SAAS,KAAK,wBAA6B;AAC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