UNPKG

4.24 kBTypeScriptView Raw
1/**
2 * Copyright 2019, OpenCensus Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { LabelKey, LabelValue, Metric, MetricDescriptorType, TimeSeries, Timestamp } from '../export/types';
17import { Meter } from '../types';
18import { CumulativePoint } from './types';
19/**
20 * Cumulative metric is used to record aggregated metrics that represents a
21 * single numerical value accumulated over a time interval. The value can only
22 * increase or be reset to zero on restart or reset the event.
23 */
24export declare class Cumulative implements Meter {
25 readonly labelKeys: LabelKey[];
26 readonly constantLabels: Map<LabelKey, LabelValue>;
27 private readonly metricDescriptor;
28 private labelKeysLength;
29 private defaultLabelValues;
30 private registeredPoints;
31 private readonly constantLabelValues;
32 /**
33 * Constructs a new Cumulative instance.
34 *
35 * @param name The name of the metric.
36 * @param description The description of the metric.
37 * @param unit The unit of the metric.
38 * @param type The type of metric.
39 * @param labelKeys The list of the label keys.
40 * @param constantLabels The map of constant labels for the Metric.
41 */
42 constructor(name: string, description: string, unit: string, type: MetricDescriptorType, labelKeys: LabelKey[], constantLabels: Map<LabelKey, LabelValue>);
43 /**
44 * Creates a TimeSeries and returns a Point if the specified
45 * labelValues is not already associated with this cumulative, else returns an
46 * existing Point.
47 *
48 * It is recommended to keep a reference to the Point instead of always
49 * calling this method for manual operations.
50 *
51 * @param labelValues The list of the label values.
52 * @returns The value of single cumulative.
53 */
54 getOrCreateTimeSeries(labelValues: LabelValue[]): CumulativePoint;
55 /**
56 * Returns a Point for a cumulative with all labels not set, or default
57 * labels.
58 *
59 * @returns The value of single cumulative.
60 */
61 getDefaultTimeSeries(): CumulativePoint;
62 /**
63 * Removes the TimeSeries from the cumulative metric, if it is present. i.e.
64 * references to previous Point objects are invalid (not part of the
65 * metric).
66 *
67 * @param labelValues The list of label values.
68 */
69 removeTimeSeries(labelValues: LabelValue[]): void;
70 /**
71 * Removes all TimeSeries from the cumulative metric. i.e. references to all
72 * previous Point objects are invalid (not part of the metric).
73 */
74 clear(): void;
75 /**
76 * Registers a TimeSeries and returns a Point if the specified
77 * labelValues is not already associated with this cumulative, else returns an
78 * existing Point.
79 *
80 * @param labelValues The list of the label values.
81 * @returns The value of single cumulative.
82 */
83 private registerTimeSeries;
84 /**
85 * Provides a Metric with one or more TimeSeries.
86 *
87 * @returns The Metric, or null if TimeSeries is not present in Metric.
88 */
89 getMetric(): Metric | null;
90}
91/**
92 * The value of a single point in the Cumulative.TimeSeries.
93 */
94export declare class CumulativePointEntry implements CumulativePoint {
95 private readonly labelValues;
96 private startTimestamp;
97 private value;
98 constructor(labelValues: LabelValue[]);
99 /** Reset cumulative metric. */
100 reset(): void;
101 /**
102 * Increment the cumulative metric.
103 * @param val The new value.
104 */
105 inc(val?: number): void;
106 /**
107 * Returns the TimeSeries with one or more Point.
108 *
109 * @param now The time at which the cumulative is recorded.
110 * @returns The TimeSeries.
111 */
112 getTimeSeries(now: Timestamp): TimeSeries;
113}