@jcit/signoz 0.1.0 → 0.1.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/cli.mjs +36 -19
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import { formatOutput, addExamples, credential, installErrorHandler, defineCliApp } from '@jcit/core';
|
|
3
4
|
import { c as createSignozClient } from './shared/signoz.DH9MeMIj.mjs';
|
|
4
5
|
import { consola } from 'consola';
|
|
@@ -59,26 +60,36 @@ function parseUntil(input) {
|
|
|
59
60
|
return parseSince(input);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
const MS_TO_NS = 1e6;
|
|
64
|
+
function buildPromqlRequest(query, startNs, endNs, step) {
|
|
63
65
|
return {
|
|
64
|
-
start,
|
|
65
|
-
end,
|
|
66
|
+
start: startNs,
|
|
67
|
+
end: endNs,
|
|
68
|
+
step,
|
|
66
69
|
compositeQuery: {
|
|
67
|
-
|
|
70
|
+
queryType: "promql",
|
|
71
|
+
panelType: "time_series",
|
|
72
|
+
promQueries: { A: { query, disabled: false } },
|
|
73
|
+
chQueries: {},
|
|
74
|
+
builderQueries: {}
|
|
68
75
|
}
|
|
69
76
|
};
|
|
70
77
|
}
|
|
71
|
-
function buildSqlRequest(query,
|
|
78
|
+
function buildSqlRequest(query, startNs, endNs) {
|
|
72
79
|
return {
|
|
73
|
-
start,
|
|
74
|
-
end,
|
|
80
|
+
start: startNs,
|
|
81
|
+
end: endNs,
|
|
75
82
|
compositeQuery: {
|
|
76
|
-
|
|
83
|
+
queryType: "clickhouse",
|
|
84
|
+
panelType: "time_series",
|
|
85
|
+
chQueries: { A: { query, disabled: false } },
|
|
86
|
+
promQueries: {},
|
|
87
|
+
builderQueries: {}
|
|
77
88
|
}
|
|
78
89
|
};
|
|
79
90
|
}
|
|
80
91
|
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 (
|
|
92
|
+
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 (must include timestamp WHERE clause)").option("-f, --file <path>", "Load query from JSON file (v3 query_range format)").option("--since <time>", "Start time: duration ago (1h, 30m, 7d) or ISO date", "1h").option("--until <time>", "End time: 'now', duration ago, or ISO date", "now").option("--step <seconds>", "Step interval in seconds (PromQL only)", "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
93
|
const modes = [opts.promql, opts.sql, opts.file].filter(Boolean);
|
|
83
94
|
if (modes.length === 0) {
|
|
84
95
|
cmd.error("specify one of --promql, --sql, or --file");
|
|
@@ -87,19 +98,23 @@ function registerQuery(program) {
|
|
|
87
98
|
cmd.error("specify only one of --promql, --sql, or --file");
|
|
88
99
|
}
|
|
89
100
|
const client = createSignozClient({ url: opts.url, token: opts.token });
|
|
90
|
-
const
|
|
91
|
-
const
|
|
101
|
+
const startNs = parseSince(opts.since) * MS_TO_NS;
|
|
102
|
+
const endNs = parseUntil(opts.until) * MS_TO_NS;
|
|
92
103
|
let body;
|
|
93
104
|
if (opts.promql) {
|
|
94
|
-
|
|
105
|
+
const step = Number(opts.step);
|
|
106
|
+
if (Number.isNaN(step) || step <= 0) {
|
|
107
|
+
cmd.error(`invalid --step value: "${opts.step}". Provide a positive number in seconds`);
|
|
108
|
+
}
|
|
109
|
+
body = buildPromqlRequest(opts.promql, startNs, endNs, step);
|
|
95
110
|
} else if (opts.sql) {
|
|
96
|
-
body = buildSqlRequest(opts.sql,
|
|
111
|
+
body = buildSqlRequest(opts.sql, startNs, endNs);
|
|
97
112
|
} else {
|
|
98
113
|
body = JSON.parse(readFileSync(opts.file, "utf-8"));
|
|
99
|
-
body.start =
|
|
100
|
-
body.end =
|
|
114
|
+
body.start = startNs;
|
|
115
|
+
body.end = endNs;
|
|
101
116
|
}
|
|
102
|
-
const result = await client("/api/
|
|
117
|
+
const result = await client("/api/v3/query_range", {
|
|
103
118
|
method: "POST",
|
|
104
119
|
body
|
|
105
120
|
});
|
|
@@ -107,9 +122,9 @@ function registerQuery(program) {
|
|
|
107
122
|
});
|
|
108
123
|
addExamples(cmd, [
|
|
109
124
|
"signoz query --promql 'rate(http_requests_total[5m])' --since 1h",
|
|
110
|
-
"signoz query --sql 'SELECT count() FROM signoz_logs.
|
|
125
|
+
"signoz query --sql 'SELECT count(*) FROM signoz_logs.distributed_logs_v2 WHERE timestamp >= ...'",
|
|
111
126
|
"signoz query -f my-query.json --since 7d --until 1d",
|
|
112
|
-
"signoz query --promql 'up' --format table"
|
|
127
|
+
"signoz query --promql 'up' --format table --step 30"
|
|
113
128
|
]);
|
|
114
129
|
}
|
|
115
130
|
|
|
@@ -123,9 +138,11 @@ function registerServices(program) {
|
|
|
123
138
|
}
|
|
124
139
|
|
|
125
140
|
installErrorHandler();
|
|
141
|
+
const require$1 = createRequire(import.meta.url);
|
|
142
|
+
const { version } = require$1("../package.json");
|
|
126
143
|
const program = defineCliApp({
|
|
127
144
|
name: "signoz",
|
|
128
|
-
version
|
|
145
|
+
version,
|
|
129
146
|
description: "CLI for SigNoz observability platform",
|
|
130
147
|
docsUrl: "https://github.com/m1heng/just-cli-it/tree/main/packages/signoz"
|
|
131
148
|
});
|