Skip to content

Commit 2e36cb4

Browse files
authored
update spectator-js docs for the thin-client release (#195)
1 parent c22df47 commit 2e36cb4

14 files changed

+649
-173
lines changed

Diff for: docs/spectator/lang/nodejs/meters/age-gauge.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
The value is the time in seconds since the epoch at which an event has successfully occurred, or
2+
`0` to use the current time in epoch seconds. After an Age Gauge has been set, it will continue
3+
reporting the number of seconds since the last time recorded, for as long as the SpectatorD
4+
process runs. The purpose of this metric type is to enable users to more easily implement the
5+
Time Since Last Success alerting pattern.
6+
7+
To set a specific time as the last success:
8+
9+
```python
10+
from spectator import Registry
11+
12+
registry = Registry()
13+
registry.age_gauge("time.sinceLastSuccess").set(1611081000)
14+
15+
last_success = registry.new_id("time.sinceLastSuccess")
16+
registry.age_gauge_with_id(last_success).set(1611081000)
17+
```
18+
19+
To set `now()` as the last success:
20+
21+
```javascript
22+
import {Registry} from "nflx-spectator";
23+
24+
const registry = new Registry();
25+
void registry.age_gauge("time.sinceLastSuccess").now();
26+
27+
const last_success = registry.new_id("time.sinceLastSuccess");
28+
void registry.age_gauge_with_id(last_success).now();
29+
```
30+
31+
By default, a maximum of `1000` Age Gauges are allowed per `spectatord` process, because there is no
32+
mechanism for cleaning them up. This value may be tuned with the `--age_gauge_limit` flag on the
33+
`spectatord` binary.
34+
35+
Since Age Gauges are long-lived entities that reside in the memory of the SpectatorD process, if
36+
you need to delete and re-create them for any reason, then you can use the [SpectatorD admin server]
37+
to accomplish this task. You can delete all Age Gauges or a single Age Gauge.
38+
39+
**Example:**
40+
41+
```
42+
curl -X DELETE \
43+
http://localhost:1234/metrics/A
44+
```
45+
46+
```
47+
curl -X DELETE \
48+
http://localhost:1234/metrics/A/fooIsTheName,some.tag=val1,some.otherTag=val2
49+
```
50+
51+
[SpectatorD admin server]: ../../../agent/usage.md#admin-server

Diff for: docs/spectator/lang/nodejs/meters/counter.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
TBD
1+
A Counter is used to measure the rate at which an event is occurring. Considering an API endpoint,
2+
a Counter could be used to measure the rate at which it is being accessed.
3+
4+
Counters are reported to the backend as a rate-per-second. In Atlas, the `:per-step` operator can
5+
be used to convert them back into a value-per-step on a graph.
6+
7+
Call `increment()` when an event occurs:
8+
9+
```javascript
10+
import {Registry} from "nflx-spectator";
11+
12+
const registry = new Registry();
13+
void registry.counter("server.numRequests").increment();
14+
15+
const num_requests = registry.new_id("server.numRequests");
16+
void registry.counter_with_id(num_requests).increment();
17+
```
18+
19+
You can also pass a value to `increment()`. This is useful when a collection of events happens
20+
together:
21+
22+
```javascript
23+
import {Registry} from "nflx-spectator";
24+
25+
const registry = new Registry();
26+
void registry.counter("queue.itemsAdded").increment(10);
27+
28+
const num_requests = registry.new_id("server.numRequests");
29+
void registry.counter_with_id(num_requests).increment(10);
30+
```

Diff for: docs/spectator/lang/nodejs/meters/dist-summary.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
TBD
1+
A Distribution Summary is used to track the distribution of events. It is similar to a Timer, but
2+
more general, in that the size does not have to be a period of time. For example, a Distribution
3+
Summary could be used to measure the payload sizes of requests hitting a server.
4+
5+
Always use base units when recording data, to ensure that the tick labels presented on Atlas graphs
6+
are readable. If you are measuring payload size, then use bytes, not kilobytes (or some other unit).
7+
This means that a `4K` tick label will represent 4 kilobytes, rather than 4 kilo-kilobytes.
8+
9+
Call `record()` with a value:
10+
11+
```javascript
12+
import {Registry} from "nflx-spectator";
13+
14+
const registry = new Registry();
15+
void registry.distribution_summary("server.requestSize").record(10);
16+
17+
const request_size = registry.new_id("server.requestSize");
18+
void registry.distribution_summary_with_id(request_size).record(10);
19+
```

Diff for: docs/spectator/lang/nodejs/meters/gauge.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
TBD
1+
A gauge is a value that is sampled at some point in time. Typical examples for gauges would be
2+
the size of a queue or number of threads in a running state. Since gauges are not updated inline
3+
when a state change occurs, there is no information about what might have occurred between samples.
4+
5+
Consider monitoring the behavior of a queue of tasks. If the data is being collected once a minute,
6+
then a gauge for the size will show the size when it was sampled. The size may have been much
7+
higher or lower at some point during interval, but that is not known.
8+
9+
Call `set()` with a value:
10+
11+
```javascript
12+
import {Registry} from "nflx-spectator";
13+
14+
const registry = new Registry();
15+
void registry.gauge("server.queueSize").set(10);
16+
17+
const queue_size = registry.new_id("server.queueSize");
18+
void registry.gauge_with_id(queue_size).set(10);
19+
```
20+
21+
Gauges will report the last set value for 15 minutes. This done so that updates to the values do
22+
not need to be collected on a tight 1-minute schedule to ensure that Atlas shows unbroken lines in
23+
graphs. A custom TTL may be configured for gauges. SpectatorD enforces a minimum TTL of 5 seconds.
24+
25+
```javascript
26+
import {Registry} from "nflx-spectator";
27+
28+
const registry = new Registry();
29+
void registry.gauge("server.queueSize", ttl_seconds=120).set(10);
30+
31+
const queue_size = registry.new_id("server.queueSize");
32+
void registry.gauge_with_id(queue_size, ttl_seconds=120).set(10);
33+
```

Diff for: docs/spectator/lang/nodejs/meters/max-gauge.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
The value is a number that is sampled at a point in time, but it is reported as a maximum Gauge
2+
value to the backend. This ensures that only the maximum value observed during a reporting interval
3+
is sent to the backend, thus over-riding the last-write-wins semantics of standard Gauges. Unlike
4+
standard Gauges, Max Gauges do not continue to report to the backend, and there is no TTL.
5+
6+
Call `set()` with a value:
7+
8+
```javascript
9+
import {Registry} from "nflx-spectator";
10+
11+
const registry = new Registry();
12+
void registry.max_gauge("server.queueSize").set(10);
13+
14+
const queue_size = registry.new_id("server.queueSize");
15+
void registry.max_gauge_with_id(queue_size).set(10);
16+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
A Monotonic Counter (uint64) is used to measure the rate at which an event is occurring, when the
2+
source data is a monotonically increasing number. A minimum of two samples must be sent, in order to
3+
calculate a delta value and report it to the backend as a rate-per-second. A variety of networking
4+
metrics may be reported monotonically, and this metric type provides a convenient means of recording
5+
these values, at the expense of a slower time-to-first metric.
6+
7+
Call `set()` when an event occurs:
8+
9+
```javascript
10+
import {Registry} from "nflx-spectator";
11+
12+
const registry = new Registry();
13+
void registry.monotonic_counter_uint("iface.bytes").set(BigInt(1));
14+
15+
const iface_bytes = registry.new_id("iface.bytes");
16+
void registry.monotonic_counter_uint_with_id(iface_bytes).set(BigInt(1));
17+
```
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
A Monotonic Counter (float) is used to measure the rate at which an event is occurring, when the
2+
source data is a monotonically increasing number. A minimum of two samples must be sent, in order to
3+
calculate a delta value and report it to the backend as a rate-per-second. A variety of networking
4+
metrics may be reported monotonically, and this metric type provides a convenient means of recording
5+
these values, at the expense of a slower time-to-first metric.
6+
7+
Call `set()` when an event occurs:
8+
9+
```javascript
10+
import {Registry} from "nflx-spectator";
11+
12+
const registry = new Registry();
13+
void registry.monotonic_counter("iface.bytes").set(10);
14+
15+
const iface_bytes = registry.new_id("iface.bytes");
16+
void registry.monotonic_counter_with_id(iface_bytes).set(10)
17+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The value tracks the distribution of events, with percentile estimates. It is similar to a
2+
`PercentileTimer`, but more general, because the size does not have to be a period of time.
3+
4+
For example, it can be used to measure the payload sizes of requests hitting a server or the
5+
number of records returned from a query.
6+
7+
In order to maintain the data distribution, they have a higher storage cost, with a worst-case of
8+
up to 300X that of a standard Distribution Summary. Be diligent about any additional dimensions
9+
added to Percentile Distribution Summaries and ensure that they have a small bounded cardinality.
10+
11+
Call `record()` with a value:
12+
13+
```javascript
14+
import {Registry} from "nflx-spectator";
15+
16+
const registry = new Registry();
17+
void registry.pct_distribution_summary("server.requestSize").record(10);
18+
19+
const request_size = registry.new_id("server.requestSize");
20+
void registry.pct_distribution_summary_with_id(request_size).record(10);
21+
```
+28-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
TBD
1+
The value is the number of seconds that have elapsed for an event, with percentile estimates.
2+
3+
This metric type will track the data distribution by maintaining a set of Counters. The
4+
distribution can then be used on the server side to estimate percentiles, while still
5+
allowing for arbitrary slicing and dicing based on dimensions.
6+
7+
In order to maintain the data distribution, they have a higher storage cost, with a worst-case of
8+
up to 300X that of a standard Timer. Be diligent about any additional dimensions added to Percentile
9+
Timers and ensure that they have a small bounded cardinality.
10+
11+
Call `record()` with a value:
12+
13+
```javascript
14+
import {Registry} from "nflx-spectator";
15+
16+
const registry = new Registry();
17+
void registry.pct_timer("server.requestLatency").record(0.01);
18+
19+
const request_latency = registry.new_id("server.requestLatency");
20+
void registry.pct_timer_with_id(request_latency).record(0.01);
21+
22+
const start = process.hrtime();
23+
// do work
24+
void registry.pct_timer("server.requestLatency").record(process.hrtime(start));
25+
```
26+
27+
The `record()` method accepts `number[]` output from `hrtime` and converts it to seconds, as a
28+
convenience for recording latencies.

Diff for: docs/spectator/lang/nodejs/meters/timer.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
TBD
1+
A Timer is used to measure how long (in seconds) some event is taking.
2+
3+
Call `record()` with a value:
4+
5+
```javascript
6+
import {Registry} from "nflx-spectator";
7+
8+
const registry = new Registry();
9+
void registry.timer("server.requestLatency").record(0.01);
10+
11+
const request_latency = registry.new_id("server.requestLatency");
12+
void registry.timer_with_id(request_latency).record(0.01);
13+
14+
const start = process.hrtime();
15+
// do work
16+
void registry.timer("server.requestLatency").record(process.hrtime(start));
17+
```
18+
19+
The `record()` method accepts `number[]` output from `hrtime` and converts it to seconds, as a
20+
convenience for recording latencies.

Diff for: docs/spectator/lang/nodejs/migrations.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TBD

0 commit comments

Comments
 (0)