@jcit/signoz 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 just-cli-it contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+
package/dist/cli.mjs ADDED
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env node
2
+ import { formatOutput, addExamples, credential, installErrorHandler, defineCliApp } from '@jcit/core';
3
+ import { c as createSignozClient } from './shared/signoz.DH9MeMIj.mjs';
4
+ import { consola } from 'consola';
5
+ import { readFileSync } from 'node:fs';
6
+
7
+ function registerAlerts(program) {
8
+ const cmd = program.command("alerts").description("List all alert rules").option("--format <format>", "Output format: json | table | text", "text").option("--url <url>", "SigNoz API base URL").option("--token <token>", "SigNoz API token").action(async (opts) => {
9
+ const client = createSignozClient({ url: opts.url, token: opts.token });
10
+ const alerts = await client("/api/v1/rules");
11
+ formatOutput(alerts, opts.format);
12
+ });
13
+ addExamples(cmd, ["signoz alerts", "signoz alerts --format json"]);
14
+ }
15
+
16
+ const SERVICE = "signoz";
17
+ function registerAuth(program) {
18
+ const auth = program.command("auth").description("Manage SigNoz authentication");
19
+ const login = auth.command("login").description("Store SigNoz credentials in system keychain").option("--url <url>", "SigNoz API base URL").option("--token <token>", "SigNoz API token").action(async (opts) => {
20
+ const url = opts.url ?? await consola.prompt("SigNoz API base URL:", { type: "text" });
21
+ const token = opts.token ?? await consola.prompt("SigNoz API token:", { type: "text", style: "password" });
22
+ credential.store(SERVICE, "url", url);
23
+ credential.store(SERVICE, "token", token);
24
+ consola.success("Credentials stored in system keychain.");
25
+ });
26
+ addExamples(login, [
27
+ "signoz auth login",
28
+ "signoz auth login --url https://signoz.example.com --token my-api-key"
29
+ ]);
30
+ auth.command("logout").description("Remove stored SigNoz credentials").action(() => {
31
+ credential.delete(SERVICE, "url");
32
+ credential.delete(SERVICE, "token");
33
+ consola.success("Credentials removed.");
34
+ });
35
+ }
36
+
37
+ const DURATION_RE = /^(\d+)(s|m|h|d)$/;
38
+ const UNITS = {
39
+ s: 1e3,
40
+ m: 6e4,
41
+ h: 36e5,
42
+ d: 864e5
43
+ };
44
+ function parseDuration(input) {
45
+ const match = input.match(DURATION_RE);
46
+ if (!match) throw new Error(`Invalid duration: "${input}". Use format like 1h, 30m, 7d`);
47
+ return Number(match[1]) * UNITS[match[2]];
48
+ }
49
+ function parseSince(input) {
50
+ if (DURATION_RE.test(input)) {
51
+ return Date.now() - parseDuration(input);
52
+ }
53
+ const ts = new Date(input).getTime();
54
+ if (Number.isNaN(ts)) throw new Error(`Invalid time: "${input}"`);
55
+ return ts;
56
+ }
57
+ function parseUntil(input) {
58
+ if (input === "now") return Date.now();
59
+ return parseSince(input);
60
+ }
61
+
62
+ function buildPromqlRequest(query, start, end, step) {
63
+ return {
64
+ start,
65
+ end,
66
+ compositeQuery: {
67
+ queries: [{ type: "promql", spec: { name: "A", query, step } }]
68
+ }
69
+ };
70
+ }
71
+ function buildSqlRequest(query, start, end) {
72
+ return {
73
+ start,
74
+ end,
75
+ compositeQuery: {
76
+ queries: [{ type: "clickhouse_sql", spec: { name: "A", query, disabled: false } }]
77
+ }
78
+ };
79
+ }
80
+ function registerQuery(program) {
81
+ const cmd = program.command("query").description("Query traces, logs, and metrics via the unified query API").option("--promql <expr>", "PromQL expression").option("--sql <query>", "ClickHouse SQL query").option("-f, --file <path>", "Load query from JSON file (v5 query_range format)").option("--since <duration>", "Start time: duration (1h, 30m, 7d) or ISO date", "1h").option("--until <time>", "End time: 'now', duration, or ISO date", "now").option("--step <seconds>", "Step interval in seconds (PromQL time series)", "60").option("--format <format>", "Output format: json | table | text", "json").option("--url <url>", "SigNoz API base URL").option("--token <token>", "SigNoz API token").action(async (opts) => {
82
+ const modes = [opts.promql, opts.sql, opts.file].filter(Boolean);
83
+ if (modes.length === 0) {
84
+ cmd.error("specify one of --promql, --sql, or --file");
85
+ }
86
+ if (modes.length > 1) {
87
+ cmd.error("specify only one of --promql, --sql, or --file");
88
+ }
89
+ const client = createSignozClient({ url: opts.url, token: opts.token });
90
+ const start = parseSince(opts.since);
91
+ const end = parseUntil(opts.until);
92
+ let body;
93
+ if (opts.promql) {
94
+ body = buildPromqlRequest(opts.promql, start, end, Number(opts.step));
95
+ } else if (opts.sql) {
96
+ body = buildSqlRequest(opts.sql, start, end);
97
+ } else {
98
+ body = JSON.parse(readFileSync(opts.file, "utf-8"));
99
+ body.start = start;
100
+ body.end = end;
101
+ }
102
+ const result = await client("/api/v5/query_range", {
103
+ method: "POST",
104
+ body
105
+ });
106
+ formatOutput(result, opts.format);
107
+ });
108
+ addExamples(cmd, [
109
+ "signoz query --promql 'rate(http_requests_total[5m])' --since 1h",
110
+ "signoz query --sql 'SELECT count() FROM signoz_logs.distributed_logs' --since 24h",
111
+ "signoz query -f my-query.json --since 7d --until 1d",
112
+ "signoz query --promql 'up' --format table"
113
+ ]);
114
+ }
115
+
116
+ function registerServices(program) {
117
+ const cmd = program.command("services").description("List all SigNoz services").option("--format <format>", "Output format: json | table | text", "text").option("--url <url>", "SigNoz API base URL").option("--token <token>", "SigNoz API token").action(async (opts) => {
118
+ const client = createSignozClient({ url: opts.url, token: opts.token });
119
+ const services = await client("/api/v1/services/list");
120
+ formatOutput(services, opts.format);
121
+ });
122
+ addExamples(cmd, ["signoz services", "signoz services --format json"]);
123
+ }
124
+
125
+ installErrorHandler();
126
+ const program = defineCliApp({
127
+ name: "signoz",
128
+ version: "0.0.1",
129
+ description: "CLI for SigNoz observability platform",
130
+ docsUrl: "https://github.com/m1heng/just-cli-it/tree/main/packages/signoz"
131
+ });
132
+ registerAuth(program);
133
+ registerQuery(program);
134
+ registerAlerts(program);
135
+ registerServices(program);
136
+ program.parseAsync();
@@ -0,0 +1,10 @@
1
+ import * as ofetch from 'ofetch';
2
+
3
+ interface SignozAuthOptions {
4
+ url?: string;
5
+ token?: string;
6
+ }
7
+ declare function createSignozClient(opts?: SignozAuthOptions): <T>(path: string, fetchOptions?: Parameters<ofetch.$Fetch>[1]) => Promise<T>;
8
+
9
+ export { createSignozClient };
10
+ export type { SignozAuthOptions };
@@ -0,0 +1,10 @@
1
+ import * as ofetch from 'ofetch';
2
+
3
+ interface SignozAuthOptions {
4
+ url?: string;
5
+ token?: string;
6
+ }
7
+ declare function createSignozClient(opts?: SignozAuthOptions): <T>(path: string, fetchOptions?: Parameters<ofetch.$Fetch>[1]) => Promise<T>;
8
+
9
+ export { createSignozClient };
10
+ export type { SignozAuthOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export { c as createSignozClient } from './shared/signoz.DH9MeMIj.mjs';
2
+ import '@jcit/core';
3
+ import 'consola';
@@ -0,0 +1,18 @@
1
+ import { credential, createApiClient } from '@jcit/core';
2
+ import { consola } from 'consola';
3
+
4
+ const SERVICE = "signoz";
5
+ const DEFAULT_BASE_URL = "http://localhost:3301";
6
+ function createSignozClient(opts = {}) {
7
+ const baseURL = credential.resolve(SERVICE, "url", { flag: opts.url, envVar: "SIGNOZ_URL" }) ?? DEFAULT_BASE_URL;
8
+ const token = credential.resolve(SERVICE, "token", { flag: opts.token, envVar: "SIGNOZ_TOKEN" }) ?? "";
9
+ if (!token) {
10
+ consola.warn("No API token configured. Run 'signoz auth login' or pass --token.");
11
+ }
12
+ return createApiClient({
13
+ baseURL,
14
+ headers: token ? { "SIGNOZ-API-KEY": token } : {}
15
+ });
16
+ }
17
+
18
+ export { createSignozClient as c };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@jcit/signoz",
3
+ "version": "0.1.0",
4
+ "description": "CLI for SigNoz observability platform",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/m1heng/just-cli-it.git",
8
+ "directory": "packages/signoz"
9
+ },
10
+ "type": "module",
11
+ "bin": {
12
+ "signoz": "./dist/cli.mjs"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.mjs",
17
+ "types": "./dist/index.d.mts"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "commander": "^14.0.0",
25
+ "consola": "^3.4.0",
26
+ "@jcit/core": "0.1.0"
27
+ },
28
+ "devDependencies": {
29
+ "unbuild": "^3.3.1"
30
+ },
31
+ "scripts": {
32
+ "build": "unbuild",
33
+ "dev": "unbuild --stub"
34
+ }
35
+ }