Skip to content

Commit fc6d53d

Browse files
committed
add spectator-js migration docs and fill out spectator-go docs
1 parent a4ccb4b commit fc6d53d

16 files changed

+710
-98
lines changed

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

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
```golang
10+
import (
11+
"github.com/Netflix/spectator-go/v2/spectator"
12+
)
13+
14+
func main() {
15+
config, _ := spectator.NewConfig("udp", nil, nil)
16+
registry, _ := spectator.NewRegistry(config)
17+
18+
registry.AgeGauge("time.sinceLastSuccess", nil).Set(1611081000)
19+
20+
lastSuccess := registry.NewId("time.sinceLastSuccess", nil)
21+
registry.AgeGaugeWithId(lastSuccess).set(1611081000)
22+
}
23+
```
24+
25+
To set `Now()` as the last success:
26+
27+
```golang
28+
import (
29+
"github.com/Netflix/spectator-go/v2/spectator"
30+
)
31+
32+
func main() {
33+
config, _ := spectator.NewConfig("udp", nil, nil)
34+
registry, _ := spectator.NewRegistry(config)
35+
36+
registry.AgeGauge("time.sinceLastSuccess", nil).Now()
37+
38+
lastSuccess := registry.NewId("time.sinceLastSuccess", nil)
39+
registry.AgeGaugeWithId(lastSuccess).Now()
40+
}
41+
```
42+
43+
By default, a maximum of `1000` Age Gauges are allowed per `spectatord` process, because there is no
44+
mechanism for cleaning them up. This value may be tuned with the `--age_gauge_limit` flag on the
45+
`spectatord` binary.
46+
47+
Since Age Gauges are long-lived entities that reside in the memory of the SpectatorD process, if
48+
you need to delete and re-create them for any reason, then you can use the [SpectatorD admin server]
49+
to accomplish this task. You can delete all Age Gauges or a single Age Gauge.
50+
51+
**Example:**
52+
53+
```
54+
curl -X DELETE \
55+
http://localhost:1234/metrics/A
56+
```
57+
58+
```
59+
curl -X DELETE \
60+
http://localhost:1234/metrics/A/fooIsTheName,some.tag=val1,some.otherTag=val2
61+
```
62+
63+
[SpectatorD admin server]: ../../../agent/usage.md#admin-server

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

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
```golang
10+
import (
11+
"github.com/Netflix/spectator-go/v2/spectator"
12+
)
13+
14+
func main() {
15+
config, _ := spectator.NewConfig("udp", nil, nil)
16+
registry, _ := spectator.NewRegistry(config)
17+
18+
registry.Counter("server.numRequests", nil).Increment()
19+
20+
numRequests := registry.NewId("server.numRequests", nil)
21+
registry.CounterWithId(numRequests).Increment()
22+
}
23+
```
24+
25+
You can also pass a value to `Add(int64)`, or `AddFloat(float64)`. This is useful when a collection
26+
of events happens together:
27+
28+
```golang
29+
import (
30+
"github.com/Netflix/spectator-go/v2/spectator"
31+
)
32+
33+
func main() {
34+
config, _ := spectator.NewConfig("udp", nil, nil)
35+
registry, _ := spectator.NewRegistry(config)
36+
37+
registry.Counter("queue.itemsAdded", nil).Add(10)
38+
39+
numRequests := registry.NewId("server.numRequests", nil)
40+
registry.CounterWithId(numRequests).Add(10)
41+
}
42+
```

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

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
```golang
12+
import (
13+
"github.com/Netflix/spectator-go/v2/spectator"
14+
)
15+
16+
func main() {
17+
config, _ := spectator.NewConfig("udp", nil, nil)
18+
registry, _ := spectator.NewRegistry(config)
19+
20+
registry.DistributionSummary("server.requestSize", nil).Record(10)
21+
22+
requestSize := registry.NewId("server.requestSize", nil)
23+
registry.DistributionSummaryWothId(requestSize).Record(10)
24+
}
25+
```

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

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
```golang
12+
import (
13+
"github.com/Netflix/spectator-go/v2/spectator"
14+
)
15+
16+
func main() {
17+
config, _ := spectator.NewConfig("udp", nil, nil)
18+
registry, _ := spectator.NewRegistry(config)
19+
20+
registry.Gauge("server.queueSize", nil).Set(10)
21+
22+
queueSize := registry.NewId("server.queueSize", nil)
23+
registry.GaugeWithId(queueSize).Set(10)
24+
}
25+
```
26+
27+
Gauges will report the last set value for 15 minutes. This done so that updates to the values do
28+
not need to be collected on a tight 1-minute schedule to ensure that Atlas shows unbroken lines in
29+
graphs. A custom TTL may be configured for gauges. SpectatorD enforces a minimum TTL of 5 seconds.
30+
31+
```golang
32+
import (
33+
"github.com/Netflix/spectator-go/v2/spectator"
34+
"time"
35+
)
36+
37+
func main() {
38+
config, _ := spectator.NewConfig("udp", nil, nil)
39+
registry, _ := spectator.NewRegistry(config)
40+
41+
registry.GaugeWithTTL("server.queueSize", nil, 120 * time.Second).Set(10)
42+
43+
queueSize := registry.NewId("server.queueSize", nil)
44+
registry.GaugeWithIdWithTTL(queueSize, 120 * time.Second).Set(10)
45+
}
46+
```

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

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
```golang
9+
import (
10+
"github.com/Netflix/spectator-go/v2/spectator"
11+
)
12+
13+
func main() {
14+
config, _ := spectator.NewConfig("udp", nil, nil)
15+
registry, _ := spectator.NewRegistry(config)
16+
17+
registry.MaxGauge("server.queueSize", nil).Set(10)
18+
19+
queueSize := registry.NewId("server.queueSize", nil)
20+
registry.MaxGaugeWithId(queueSize).Set(10)
21+
}
22+
```
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
```golang
10+
import (
11+
"github.com/Netflix/spectator-go/v2/spectator"
12+
)
13+
14+
func main() {
15+
config, _ := spectator.NewConfig("udp", nil, nil)
16+
registry, _ := spectator.NewRegistry(config)
17+
18+
registry.MonotonicCounterUint("iface.bytes", nil).Set(1)
19+
20+
ifaceBytes := registry.NewId("iface.bytes", nil)
21+
registry.MonotonicCounterUintWithId(ifaceBytes).Set(1)
22+
}
23+
```

Diff for: docs/spectator/lang/go/meters/monotonic-counter.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
```golang
10+
import (
11+
"github.com/Netflix/spectator-go/v2/spectator"
12+
)
13+
14+
func main() {
15+
config, _ := spectator.NewConfig("udp", nil, nil)
16+
registry, _ := spectator.NewRegistry(config)
17+
18+
registry.MonotonicCounter("iface.bytes", nil).Set(10)
19+
20+
ifaceBytes := registry.NewId("iface.bytes", nil)
21+
registry.MonotonicCounterWithId(ifaceBytes).Set(10)
22+
}
23+
```
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
```golang
14+
import (
15+
"github.com/Netflix/spectator-go/v2/spectator"
16+
)
17+
18+
func main() {
19+
config, _ := spectator.NewConfig("udp", nil, nil)
20+
registry, _ := spectator.NewRegistry(config)
21+
22+
registry.PercentileDistributionSummary("server.requestSize", nil).Record(10)
23+
24+
requestSize := registry.NewId("server.requestSize", nil)
25+
registry.PercentileDistributionSummaryWothId(requestSize).Record(10)
26+
}
27+
```

Diff for: docs/spectator/lang/go/meters/percentile-timer.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
```golang
14+
import (
15+
"github.com/Netflix/spectator-go/v2/spectator"
16+
"time"
17+
)
18+
19+
func main() {
20+
config, _ := spectator.NewConfig("udp", nil, nil)
21+
registry, _ := spectator.NewRegistry(config)
22+
23+
registry.PercentileTimer("server.requestLatency", nil).Record(500 * time.Millisecond)
24+
25+
requestLatency := registry.NewId("server.requestLatency", nil)
26+
registry.PercentileTimerWithId(requestLatency).Record(500 * time.Millisecond)
27+
}
28+
```

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

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
A Timer is used to measure how long (in seconds) some event is taking.
2+
3+
Call `record()` with a value:
4+
5+
```golang
6+
import (
7+
"github.com/Netflix/spectator-go/v2/spectator"
8+
"time"
9+
)
10+
11+
func main() {
12+
config, _ := spectator.NewConfig("udp", nil, nil)
13+
registry, _ := spectator.NewRegistry(config)
14+
15+
registry.Timer("server.requestLatency", nil).Record(500 * time.Millisecond)
16+
17+
requestLatency := registry.NewId("server.requestLatency", nil)
18+
registry.TimerWithId(requestLatency).Record(500 * time.Millisecond)
19+
}
20+
```

0 commit comments

Comments
 (0)