Diagnostics Metrics¶
Application metrics collection.
Metrics Module¶
Performance and monitoring metrics.
This submodule provides metric classes for counters, gauges, histograms, and timers.
Examples¶
from rite.diagnostics.metrics import ( ... metrics_counter, ... metrics_gauge, ... metrics_histogram, ... metrics_timer ... ) counter = metrics_counter("requests") counter.increment()
Modules¶
metrics_counter
¶
Counter Metric¶
Counter that can only increase.
Examples¶
from rite.diagnostics.metrics import metrics_counter counter = metrics_counter("requests") counter.increment() counter.value 1
Classes¶
metrics_counter(name: str)
¶
Counter metric that only increases.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Metric name. |
|
value |
float
|
Current counter value. |
Examples:
>>> counter = metrics_counter("api_calls")
>>> counter.increment()
>>> counter.increment(5)
>>> counter.value
6
Initialize counter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name. |
required |
metrics_gauge
¶
Gauge Metric¶
Gauge that can increase or decrease.
Examples¶
from rite.diagnostics.metrics import metrics_gauge gauge = metrics_gauge("temperature") gauge.set(25.0) gauge.value 25.0
Classes¶
metrics_gauge(name: str, initial_value: float = 0.0)
¶
Gauge metric that can go up or down.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Metric name. |
|
value |
float
|
Current gauge value. |
Examples:
>>> gauge = metrics_gauge("memory_usage")
>>> gauge.set(100)
>>> gauge.increment(50)
>>> gauge.decrement(25)
>>> gauge.value
125.0
Initialize gauge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name. |
required |
initial_value
|
float
|
Starting value. |
0.0
|
Attributes¶
value: float
property
¶Get current value.
Functions¶
decrement(amount: float = 1.0) -> None
¶Decrease gauge value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
Amount to subtract. |
1.0
|
increment(amount: float = 1.0) -> None
¶Increase gauge value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
Amount to add. |
1.0
|
reset() -> None
¶Reset gauge to zero.
set(value: float) -> None
¶
metrics_histogram
¶
Histogram Metric¶
Histogram to track distribution of values.
Examples¶
from rite.diagnostics.metrics import metrics_histogram hist = metrics_histogram("response_time") hist.observe(0.5) hist.count 1
Classes¶
metrics_histogram(name: str)
¶
Histogram metric for value distributions.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Metric name. |
|
count |
int
|
Number of observations. |
sum |
float
|
Sum of all values. |
Examples:
>>> hist = metrics_histogram("latency")
>>> hist.observe(1.0)
>>> hist.observe(2.0)
>>> hist.observe(3.0)
>>> hist.mean
2.0
Initialize histogram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name. |
required |
Attributes¶
count: int
property
¶Get number of observations.
mean: float
property
¶Get mean of values.
median: float
property
¶Get median of values.
sum: float
property
¶Get sum of all values.
Functions¶
observe(value: float) -> None
¶percentile(p: float) -> float
¶reset() -> None
¶Clear all observations.
metrics_timer
¶
Timer Metric¶
Timer to measure durations as context manager.
Examples¶
from rite.diagnostics.metrics import metrics_timer timer = metrics_timer("operation") with timer: ... pass timer.count 1
Classes¶
metrics_timer(name: str)
¶
Timer metric using context manager.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Metric name. |
|
count |
int
|
Number of timing measurements. |
total |
float
|
Total time measured. |
Examples:
>>> timer = metrics_timer("request")
>>> with timer:
... time.sleep(0.01)
>>> timer.count
1
>>> timer.total > 0
True
Initialize timer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name. |
required |
options: show_root_heading: true show_source: false heading_level: 2