Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
80fa610f
Commit
80fa610f
authored
7 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
Add some comments to metrics classes
parent
5e16c1dc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/metrics/metric.py
+27
-1
27 additions, 1 deletion
synapse/metrics/metric.py
with
27 additions
and
1 deletion
synapse/metrics/metric.py
+
27
−
1
View file @
80fa610f
...
@@ -24,8 +24,16 @@ def map_concat(func, items):
...
@@ -24,8 +24,16 @@ def map_concat(func, items):
class
BaseMetric
(
object
):
class
BaseMetric
(
object
):
"""
Base class for metrics which report a single value per label set
"""
def
__init__
(
self
,
name
,
labels
=
[]):
def
__init__
(
self
,
name
,
labels
=
[]):
"""
Args:
name (str): principal name for this metric
labels (list(str)): names of the labels which will be reported
for this metric
"""
self
.
name
=
name
self
.
name
=
name
self
.
labels
=
labels
# OK not to clone as we never write it
self
.
labels
=
labels
# OK not to clone as we never write it
...
@@ -36,7 +44,7 @@ class BaseMetric(object):
...
@@ -36,7 +44,7 @@ class BaseMetric(object):
return
not
len
(
self
.
labels
)
return
not
len
(
self
.
labels
)
def
_render_labelvalue
(
self
,
value
):
def
_render_labelvalue
(
self
,
value
):
# TODO:
some kind of value escape
# TODO:
escape backslashes, quotes and newlines
return
'"
%s
"'
%
(
value
)
return
'"
%s
"'
%
(
value
)
def
_render_key
(
self
,
values
):
def
_render_key
(
self
,
values
):
...
@@ -47,6 +55,20 @@ class BaseMetric(object):
...
@@ -47,6 +55,20 @@ class BaseMetric(object):
for
k
,
v
in
zip
(
self
.
labels
,
values
)])
for
k
,
v
in
zip
(
self
.
labels
,
values
)])
)
)
def
render
(
self
):
"""
Render this metric
Each metric is rendered as:
name{label1=
"
val1
"
,label2=
"
val2
"
} value
https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-details
Returns:
iterable[str]: rendered metrics
"""
raise
NotImplementedError
()
class
CounterMetric
(
BaseMetric
):
class
CounterMetric
(
BaseMetric
):
"""
The simplest kind of metric; one that stores a monotonically-increasing
"""
The simplest kind of metric; one that stores a monotonically-increasing
...
@@ -62,6 +84,10 @@ class CounterMetric(BaseMetric):
...
@@ -62,6 +84,10 @@ class CounterMetric(BaseMetric):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
CounterMetric
,
self
).
__init__
(
*
args
,
**
kwargs
)
super
(
CounterMetric
,
self
).
__init__
(
*
args
,
**
kwargs
)
# dict[list[str]]: value for each set of label values. the keys are the
# label values, in the same order as the labels in self.labels.
#
# (if the metric is a scalar, the (single) key is the empty list).
self
.
counts
=
{}
self
.
counts
=
{}
# Scalar metrics are never empty
# Scalar metrics are never empty
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment