Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: go/metrics2/docs.go

Issue 1722163002: Metrics2: Store a registry of Counters (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Address comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/metrics2/counter.go ('k') | go/metrics2/metrics.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package metrics2 1 package metrics2
2 2
3 /* 3 /*
4 Metrics2 Package 4 Metrics2 Package
5 ================ 5 ================
6 6
7 Concepts 7 Concepts
8 -------- 8 --------
9 9
10 The major difference between the old metrics format and the new is that, from th e app’s point of view, the old metrics were specified using a single metric name . In the new format, metrics are specified using a measurement name and a map[s tring]string of tags. Expect all instances of metrics types to require both a m easurement name and tags map instead of just the metric name. When using common .InitWithMetrics2, runtime stats including uptime are automatically recorded, an d the “host” and “app” tags are automatically set for all measurements. In many cases, it may be unnecessary to provide more tags, so you can just pass nil. 10 The major difference between the old metrics format and the new is that, from th e app’s point of view, the old metrics were specified using a single metric name . In the new format, metrics are specified using a measurement name and a map[s tring]string of tags. Expect all instances of metrics types to require both a m easurement name and tags map instead of just the metric name. When using common .InitWithMetrics2, runtime stats including uptime are automatically recorded, an d the “host” and “app” tags are automatically set for all measurements. In many cases, it may be unnecessary to provide more tags, so you can just pass nil.
11 11
12 Metrics Helpers 12 Metrics Helpers
13 --------------- 13 ---------------
14 The metrics2 package provides a number of helper structs and functions which sho uld be your primary mode of interacting with metrics. 14 The metrics2 package provides a number of helper structs and functions which sho uld be your primary mode of interacting with metrics.
15 15
16 ### Typed Metrics 16 ### Typed Metrics
17 17
18 Metrics2 provides a few typed metrics helpers which behave similarly to go_metri cs.GetOrRegisterGauge: once registered, the metric contains a single value which is pushed into InfluxDB at regular intervals. The value can be changed by call ing Update() on the Metric. The metrics are stored in a sort of registry so tha t you don’t need to keep the object around and can just do: metrics2.GetInt64Met ric(metric, tags).Update(value). 18 Metrics2 provides a few typed metrics helpers which behave similarly to go_metri cs.GetOrRegisterGauge: once registered, the metric contains a single value which is pushed into InfluxDB at regular intervals. The value can be changed by call ing Update() on the Metric. The metrics are stored in a sort of registry so tha t you don’t need to keep the object around and can just do: metrics2.GetInt64Met ric(metric, tags).Update(value).
19 19
20 ### Counter 20 ### Counter
21 21
22 Counter in the metrics2 package behaves similarly to those from go-metrics excep t that there is no GetOrRegisterCounter equivalent. Instead, you should call me trics2.NewCounter(name, tags), hold on to the returned struct instance and call Inc(), Dec(), etc, on it as desired. Note that Counter requires a name and not a measurement, because the measurement is always “counter”, and the provided nam e is inserted as a tag. 22 Counter in the metrics2 package behaves similarly to those from go-metrics excep t that there is no GetOrRegisterCounter equivalent. Instead, you should call me trics2.GetCounter(name, tags), hold on to the returned struct instance and call Inc(), Dec(), etc, on it as desired. Note that Counter requires a name and not a measurement, because the measurement is always “counter”, and the provided nam e is inserted as a tag.
23 23
24 ### Liveness 24 ### Liveness
25 25
26 Liveness in metrics2 behaves similarly to the old metrics liveness, except that you provide a name and tags. Call metrics2.NewLiveness() to start the liveness timer, and call Reset() on the instance to reset it to zero. Note that Liveness requires a name and not a measurement, because the measurement is always “liven ess”, and the provided name is inserted as a tag. 26 Liveness in metrics2 behaves similarly to the old metrics liveness, except that you provide a name and tags. Call metrics2.NewLiveness() to start the liveness timer, and call Reset() on the instance to reset it to zero. Note that Liveness requires a name and not a measurement, because the measurement is always “liven ess”, and the provided name is inserted as a tag.
27 27
28 ### Timer 28 ### Timer
29 29
30 Timer in metrics2 behaves similarly to the old metrics timer, except that you pr ovide a name and tags instead of a metric. Call metrics2.NewTimer(name, tags) t o start the timer and call Stop() on the instance to measure the duration and pu sh a data point into InfluxDB. Timer does not behave like a Gauge, in that it d oes not push values at regular intervals. Instead, it only pushes a value when Stop() is called. Be aware of this when creating alerts based on timers, since data points will not be evenly spaced and may not exist for a time period. Time r requires a name and not a measurement, because the measurement is always “time r” and the provided name is inserted as a tag. 30 Timer in metrics2 behaves similarly to the old metrics timer, except that you pr ovide a name and tags instead of a metric. Call metrics2.NewTimer(name, tags) t o start the timer and call Stop() on the instance to measure the duration and pu sh a data point into InfluxDB. Timer does not behave like a Gauge, in that it d oes not push values at regular intervals. Instead, it only pushes a value when Stop() is called. Be aware of this when creating alerts based on timers, since data points will not be evenly spaced and may not exist for a time period. Time r requires a name and not a measurement, because the measurement is always “time r” and the provided name is inserted as a tag.
31 31
32 ### FuncTimer 32 ### FuncTimer
33 33
34 FuncTimer is a special Timer designed specifically for timing the duration of fu nctions. It does not accept any parameters because it automatically fills in th e function name and package name in the tags. Just do defer metrics2.FuncTimer( ).Stop() at the beginning of the function. 34 FuncTimer is a special Timer designed specifically for timing the duration of fu nctions. It does not accept any parameters because it automatically fills in th e function name and package name in the tags. Just do defer metrics2.FuncTimer( ).Stop() at the beginning of the function.
35 35
36 Raw Data Insertion 36 Raw Data Insertion
37 ------------------ 37 ------------------
38 38
39 In addition to the above helpers, you can also insert data directly, without the use of a helper. There is a single function, RawAddInt64PointAtTime, which may be called to add a single point with a given measurement name, tag set, and tim estamp. This is useful for event-based measurements, or when none of the above helpers are appropriate. You should avoid using this unless you absolutely need it, since it does not play by the same rules as the other metrics types. 39 In addition to the above helpers, you can also insert data directly, without the use of a helper. There is a single function, RawAddInt64PointAtTime, which may be called to add a single point with a given measurement name, tag set, and tim estamp. This is useful for event-based measurements, or when none of the above helpers are appropriate. You should avoid using this unless you absolutely need it, since it does not play by the same rules as the other metrics types.
40 40
41 */ 41 */
OLDNEW
« no previous file with comments | « go/metrics2/counter.go ('k') | go/metrics2/metrics.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698