|
| 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 |
0 commit comments