-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prometheus exporter #294
Prometheus exporter #294
Changes from 48 commits
f839e21
f89b60a
ed6f363
4ec6dc3
15f687f
9397a8a
750fd30
1edfeba
123fc3b
ecaacc3
ec8cbf3
6ce4afb
a14667e
033a1ea
3722f70
a492f88
8a9417e
ff0b9a0
eb8ba4f
05f653c
5c7460f
9515063
3827a23
4fb0061
3fde245
3fd06bd
338f173
1d1d4c8
549a5e1
ad877b0
936022a
64a3f95
35b201b
a444034
3de80f8
6225dbf
ae3425c
7a89d7b
cd0787b
1a65e5d
79ce303
6db375c
bc9e485
2f5984e
5dd3c92
52067bd
92fb0cc
006f94b
5bef7f0
f442bc5
a905d2b
ed73ffd
191738b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import random | ||
import time | ||
|
||
from opencensus.stats import aggregation as aggregation_module | ||
from opencensus.stats.exporters import prometheus_exporter as prometheus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we keep the file name as prometheus? Instead of prometheus_exporter, which already resides under opencensus/stats/exporters, hence the _exporter suffix here there is redundant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got your point, but this is how the exporters files where named in trace and stats before. I believe they were just following the pattern. But I like your suggestion, I think we can open an issue about this. |
||
from opencensus.stats import measure as measure_module | ||
from opencensus.stats import stats as stats_module | ||
from opencensus.stats import view as view_module | ||
from opencensus.tags import tag_key as tag_key_module | ||
from opencensus.tags import tag_map as tag_map_module | ||
from opencensus.tags import tag_value as tag_value_module | ||
from pprint import pprint | ||
|
||
MiB = 1 << 20 | ||
FRONTEND_KEY = tag_key_module.TagKey("my.org/keys/frontend") | ||
VIDEO_SIZE_MEASURE = measure_module.MeasureInt( | ||
"my.org/measures/video_size", "size of processed videos", "By") | ||
VIDEO_SIZE_VIEW_NAME = "my.org/views/video_size" | ||
VIDEO_SIZE_DISTRIBUTION = aggregation_module.DistributionAggregation( | ||
[0.0, 16.0 * MiB, 256.0 * MiB]) | ||
VIDEO_SIZE_VIEW = view_module.View(VIDEO_SIZE_VIEW_NAME, | ||
"processed video size over time", | ||
[FRONTEND_KEY], | ||
VIDEO_SIZE_MEASURE, | ||
VIDEO_SIZE_DISTRIBUTION) | ||
|
||
|
||
def main(): | ||
stats = stats_module.Stats() | ||
view_manager = stats.view_manager | ||
stats_recorder = stats.stats_recorder | ||
|
||
exporter = prometheus.new_stats_exporter(prometheus.Options(namespace="opencensus")) | ||
view_manager.register_exporter(exporter) | ||
|
||
# Register view. | ||
view_manager.register_view(VIDEO_SIZE_VIEW) | ||
|
||
# Sleep for [0, 10] milliseconds to fake work. | ||
time.sleep(random.randint(1, 10) / 1000.0) | ||
|
||
# Process video. | ||
# Record the processed video size. | ||
tag_value = tag_value_module.TagValue(str(random.randint(1, 10000))) | ||
tag_map = tag_map_module.TagMap() | ||
tag_map.insert(FRONTEND_KEY, tag_value) | ||
measure_map = stats_recorder.new_measurement_map() | ||
measure_map.measure_int_put(VIDEO_SIZE_MEASURE, 25 * MiB) | ||
measure_map.record(tag_map) | ||
|
||
# Use the line below to see the data on prometheus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the lines here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'm not sure. If we remove, the user may not be able to access Prometheus before the code finishes. This is just a way to |
||
# while True: | ||
# pass | ||
|
||
# Get aggregated stats and print it to console. | ||
view_data = view_manager.get_view(VIDEO_SIZE_VIEW_NAME) | ||
pprint(vars(view_data)) | ||
for k, v in view_data._tag_value_aggregation_data_map.items(): | ||
pprint(k) | ||
pprint(vars(v)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,7 +230,6 @@ def increment_bucket_count(self, value): | |
return i | ||
|
||
self._counts_per_bucket[(len(self._bounds))-1] += 1 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spurious line? Please remove it. |
||
return i | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spurious?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it