big-spender 0.14.1 → 0.14.2
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/dist/collector.mjs +23 -11
- package/package.json +1 -1
package/dist/collector.mjs
CHANGED
|
@@ -9,13 +9,7 @@
|
|
|
9
9
|
// and POSTs it as a second snapshot under the device id "cursor".
|
|
10
10
|
//
|
|
11
11
|
// Zero dependencies, Node >= 20 (or Bun). `big-spender install` copies this single file to
|
|
12
|
-
// ~/.local/share/big-spender/collector.mjs and schedules it. See the package README.
|
|
13
|
-
//
|
|
14
|
-
// Usage:
|
|
15
|
-
// node collector.mjs # parse new log bytes, POST the snapshot
|
|
16
|
-
// node collector.mjs --dry-run # print the snapshot + a 24h summary, no POST
|
|
17
|
-
// node collector.mjs --summary # print only the 24h summary
|
|
18
|
-
// node collector.mjs --reset # forget local state and rescan everything
|
|
12
|
+
// ~/.local/share/big-spender/collector.mjs and schedules it. See the package README and USAGE below.
|
|
19
13
|
//
|
|
20
14
|
// Env: BIG_SPENDER_DEVICE_ID, BIG_SPENDER_INGEST_URL, BIG_SPENDER_INGEST_TOKEN and optionally
|
|
21
15
|
// BIG_SPENDER_CURSOR_API_KEY and BIG_SPENDER_POLL_LIMITS=off (see templates/env.example).
|
|
@@ -54,10 +48,28 @@ const CURSOR_PAGE_SIZE = 1000;
|
|
|
54
48
|
// The server's date floor (EARLIEST_DATE in schema.ts); the backfill reads from here.
|
|
55
49
|
const CURSOR_EARLIEST_MS = Date.parse('2020-01-01T00:00:00Z');
|
|
56
50
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
const USAGE = `Usage: node collector.mjs [--dry-run | --summary] [--reset]
|
|
52
|
+
|
|
53
|
+
(no flag) read new log data and POST the snapshot
|
|
54
|
+
--dry-run print the snapshot and a 24h summary; sends nothing
|
|
55
|
+
--summary print only the 24h summary; sends nothing
|
|
56
|
+
--reset forget local state and rescan everything
|
|
57
|
+
-h, --help print this help`;
|
|
58
|
+
|
|
59
|
+
// Checked before anything else runs: an ignored typo such as --dryrun would post a real snapshot.
|
|
60
|
+
const args = process.argv.slice(2);
|
|
61
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
62
|
+
console.log(USAGE);
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
const unknown = args.find((a) => !['--dry-run', '--summary', '--reset'].includes(a));
|
|
66
|
+
if (unknown !== undefined) {
|
|
67
|
+
console.error(`[big-spender] unknown argument: ${unknown}\n\n${USAGE}`);
|
|
68
|
+
process.exit(2);
|
|
69
|
+
}
|
|
70
|
+
const DRY_RUN = args.includes('--dry-run');
|
|
71
|
+
const SUMMARY_ONLY = args.includes('--summary');
|
|
72
|
+
const RESET = args.includes('--reset');
|
|
61
73
|
|
|
62
74
|
const HOME = homedir();
|
|
63
75
|
const CACHE_DIR = join(process.env.XDG_CACHE_HOME || join(HOME, '.cache'), 'big-spender');
|