Skip to content

Commit 6568273

Browse files
authored
Spectator-CPP-2.0(#225)
Add documentation for the Spectator-CPP-2.0
1 parent b873fdf commit 6568273

File tree

14 files changed

+728
-88
lines changed

14 files changed

+728
-88
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
```cpp
10+
#include <registry.h>
11+
12+
int main()
13+
{
14+
auto config = Config(WriterConfig(WriterTypes::UDP));
15+
auto r = Registry(config);
16+
17+
// Option 1: Directly create an Age Gauge
18+
auto successAgeGauge = r.CreateAgeGauge("time.sinceLastSuccess");
19+
successAgeGauge.Set(1611081000);
20+
21+
// Option 2: Create an Age Gauge from a MeterID
22+
auto successMeter = r.CreateNewId("time.sinceLastSuccess");
23+
r.CreateAgeGauge(successMeter).Set(1611081000);
24+
}
25+
```
26+
27+
To set `Now()` as the last success:
28+
29+
```cpp
30+
#include <registry.h>
31+
32+
int main()
33+
{
34+
auto config = Config(WriterConfig(WriterTypes::UDP));
35+
auto r = Registry(config);
36+
37+
// Option 1: Directly create an Age Gauge
38+
auto successAgeGauge = r.CreateAgeGauge("time.sinceLastSuccess");
39+
successAgeGauge.Now();
40+
41+
// Option 2: Create an Age Gauge from a MeterID
42+
auto successMeter = r.CreateNewId("time.sinceLastSuccess");
43+
r.CreateAgeGauge(successMeter).Now();
44+
}
45+
```
46+
47+
By default, a maximum of `1000` Age Gauges are allowed per `spectatord` process, because there is no
48+
mechanism for cleaning them up. This value may be tuned with the `--age_gauge_limit` flag on the
49+
`spectatord` binary.
50+
51+
Since Age Gauges are long-lived entities that reside in the memory of the SpectatorD process, if
52+
you need to delete and re-create them for any reason, then you can use the [SpectatorD admin server]
53+
to accomplish this task. You can delete all Age Gauges or a single Age Gauge.
54+
55+
**Example:**
56+
57+
```
58+
curl -X DELETE \
59+
http://localhost:1234/metrics/A
60+
```
61+
62+
```
63+
curl -X DELETE \
64+
http://localhost:1234/metrics/A/fooIsTheName,some.tag=val1,some.otherTag=val2
65+
```
66+
67+
[SpectatorD admin server]: ../../../agent/usage.md#admin-server
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
```cpp
10+
#include <registry.h>
11+
12+
int main()
13+
{
14+
auto config = Config(WriterConfig(WriterTypes::UDP));
15+
auto r = Registry(config);
16+
17+
// Option 1: Directly create a Counter
18+
auto serverRequestCounter = r.CreateCounter("server.numRequests");
19+
serverRequestCounter.Increment();
20+
21+
// Option 2: Create a Counter from a MeterID
22+
auto serverRequestMeter = r.CreateNewId("server.numRequests");
23+
r.CreateCounter(serverRequestMeter).Increment();
24+
}
25+
```
26+
27+
You can also pass a value to `Increment()`. This is useful when a collection of events happens
28+
together:
29+
30+
```cpp
31+
#include <registry.h>
32+
33+
int main()
34+
{
35+
auto config = Config(WriterConfig(WriterTypes::UDP));
36+
auto r = Registry(config);
37+
38+
// Option 1: Directly create a Counter
39+
auto serverRequestCounter = r.CreateCounter("server.numRequests");
40+
serverRequestCounter.Increment(10);
41+
42+
// Option 2: Create a Counter from a MeterID
43+
auto serverRequestMeter = r.CreateNewId("server.numRequests");
44+
r.CreateCounter(serverRequestMeter).Increment(10);
45+
}
46+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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. Note that the C++
4+
implementation of Distribution Summary allows for the recording of floating point values, which the
5+
other thin clients do not allow.
6+
7+
Always use base units when recording data, to ensure that the tick labels presented on Atlas graphs
8+
are readable. If you are measuring payload size, then use bytes, not kilobytes (or some other unit).
9+
This means that a `4K` tick label will represent 4 kilobytes, rather than 4 kilo-kilobytes.
10+
11+
Call `Record()` with a value:
12+
13+
```cpp
14+
#include <registry.h>
15+
16+
int main()
17+
{
18+
auto config = Config(WriterConfig(WriterTypes::UDP));
19+
auto r = Registry(config);
20+
21+
// Option 1: Directly create a Distribution Summary
22+
auto serverRequestSize = r.CreateDistributionSummary("server.requestSize");
23+
serverRequestSize.Record(42);
24+
25+
// Option 2: Create a Distribution Summary from a MeterID
26+
auto serverRequestMeter = r.CreateNewId("server.requestSize");
27+
r.CreateDistributionSummary(serverRequestMeter).Record(42);
28+
}
29+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
```cpp
12+
#include <registry.h>
13+
14+
int main()
15+
{
16+
auto config = Config(WriterConfig(WriterTypes::UDP));
17+
auto r = Registry(config);
18+
19+
// Option 1: Directly create a Gauge
20+
auto serverQueueSize = r.CreateGauge("server.queueSize");
21+
serverQueueSize.Set(10);
22+
23+
// Option 2: Create a Gauge from a MeterID
24+
auto serverQueueMeter = r.CreateNewId("server.queueSize");
25+
r.CreateGauge(serverQueueMeter).Set(10);
26+
}
27+
```
28+
29+
Gauges will report the last set value for 15 minutes. This done so that updates to the values do
30+
not need to be collected on a tight 1-minute schedule to ensure that Atlas shows unbroken lines in
31+
graphs. A custom TTL may be configured for gauges. SpectatorD enforces a minimum TTL of 5 seconds.
32+
33+
```cpp
34+
#include <registry.h>
35+
36+
int main()
37+
{
38+
auto config = Config(WriterConfig(WriterTypes::UDP));
39+
auto r = Registry(config);
40+
41+
// Option 1: Directly create a Gauge
42+
auto serverQueueSize = r.CreateGauge("server.queueSize", {}, 120);
43+
serverQueueSize.Set(10);
44+
45+
// Option 2: Create a Gauge from a MeterID
46+
auto serverQueueMeter = r.CreateNewId("server.queueSize");
47+
r.CreateGauge(serverQueueMeter, 120).Set(10);
48+
}
49+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
```cpp
9+
#include <registry.h>
10+
11+
int main()
12+
{
13+
auto config = Config(WriterConfig(WriterTypes::UDP));
14+
auto r = Registry(config);
15+
16+
// Option 1: Directly create a Max Gauge
17+
auto serverQueueSize = r.CreateMaxGauge("server.queueSize");
18+
serverQueueSize.Set(10);
19+
20+
// Option 2: Create a Gauge from a MeterID
21+
auto serverQueueMeter = r.CreateNewId("server.queueSize");
22+
r.CreateMaxGauge(serverQueueMeter).Set(10);
23+
}
24+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
```cpp
10+
#include <registry.h>
11+
12+
int main()
13+
{
14+
auto config = Config(WriterConfig(WriterTypes::UDP));
15+
auto r = Registry(config);
16+
17+
// Option 1: Directly create a Monotonic Counter uint64_t
18+
auto interfaceBytes = r.CreateMonotonicCounterUint("iface.bytes");
19+
interfaceBytes.Set(10);
20+
21+
// Option 2: Create a Monotonic Counter uint64_t from a MeterID
22+
auto interfaceBytesMeter = r.CreateNewId("iface.bytes");
23+
r.CreateMonotonicCounterUint(interfaceBytesMeter).Set(10);
24+
}
25+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
```cpp
10+
#include <registry.h>
11+
12+
int main()
13+
{
14+
auto config = Config(WriterConfig(WriterTypes::UDP));
15+
auto r = Registry(config);
16+
17+
// Option 1: Directly create a Monotonic Counter
18+
auto interfaceBytes = r.CreateMonotonicCounter("iface.bytes");
19+
interfaceBytes.Set(10);
20+
21+
// Option 2: Create a Monotonic Counter from a MeterID
22+
auto interfaceBytesMeter = r.CreateNewId("iface.bytes");
23+
r.CreateMonotonicCounter(interfaceBytesMeter).Set(10);
24+
}
25+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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. Note that the C++ implementation of Percentile Distribution
6+
Summary allows for the recording of floating point values, which the other thin clients do not
7+
allow.
8+
9+
In order to maintain the data distribution, they have a higher storage cost, with a worst-case of
10+
up to 300X that of a standard Distribution Summary. Be diligent about any additional dimensions
11+
added to Percentile Distribution Summaries and ensure that they have a small bounded cardinality.
12+
13+
Call `Record()` with a value:
14+
15+
```cpp
16+
#include <registry.h>
17+
18+
int main()
19+
{
20+
auto config = Config(WriterConfig(WriterTypes::UDP));
21+
auto r = Registry(config);
22+
23+
// Option 1: Directly create a Percentile Distribution Summary
24+
auto serverSize = r.CreatePercentDistributionSummary("server.requestSize");
25+
serverSize.Record(10);
26+
27+
// Option 2: Create a Percentile Distribution Summary from a MeterID
28+
auto requestSizeMeter = r.CreateNewId("server.requestSize");
29+
r.CreatePercentDistributionSummary(requestSizeMeter).Record(10);
30+
}
31+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
```cpp
14+
#include <registry.h>
15+
16+
int main()
17+
{
18+
auto config = Config(WriterConfig(WriterTypes::UDP));
19+
auto r = Registry(config);
20+
21+
// Option 1: Directly create a Percentile Timer
22+
auto serverLatency = r.CreatePercentTimer("server.requestLatency");
23+
serverLatency.Record(10);
24+
25+
// Option 2: Create a Percentile Timer from a MeterID
26+
auto requestLatencyMeter = r.CreateNewId("server.requestLatency");
27+
r.CreatePercentTimer(requestLatencyMeter).Record(10);
28+
}
29+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
A Timer is used to measure how long (in seconds) some event is taking.
2+
3+
Call `Record()` with a value:
4+
5+
```cpp
6+
#include <registry.h>
7+
8+
int main()
9+
{
10+
auto config = Config(WriterConfig(WriterTypes::UDP));
11+
auto r = Registry(config);
12+
13+
// Option 1: Directly create a Timer
14+
auto serverLatency = r.CreateTimer("server.requestLatency");
15+
serverLatency.Record(10);
16+
17+
// Option 2: Create a Timer from a MeterID
18+
auto requestLatencyMeter = r.CreateNewId("server.requestLatency");
19+
r.CreateTimer(requestLatencyMeter).Record(10);
20+
}
21+
```

0 commit comments

Comments
 (0)