-
Notifications
You must be signed in to change notification settings - Fork 443
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
metrics histogram example #1330
Changes from 2 commits
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 |
---|---|---|
|
@@ -44,21 +44,49 @@ void initMetrics(const std::string &name) | |
new metric_sdk::MeterProvider(std::move(exporters))); | ||
auto p = std::static_pointer_cast<metric_sdk::MeterProvider>(provider); | ||
p->AddMetricReader(std::move(reader)); | ||
|
||
// counter view | ||
std::unique_ptr<metric_sdk::InstrumentSelector> instrument_selector{ | ||
new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kCounter, name)}; | ||
std::unique_ptr<metric_sdk::MeterSelector> meter_selector{ | ||
new metric_sdk::MeterSelector(name, version, schema)}; | ||
std::unique_ptr<metric_sdk::View> view{ | ||
std::unique_ptr<metric_sdk::View> sum_view{ | ||
new metric_sdk::View{name, "description", metric_sdk::AggregationType::kSum}}; | ||
p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)); | ||
p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view)); | ||
|
||
// histogram view | ||
std::unique_ptr<metric_sdk::InstrumentSelector> histogram_instrument_selector{ | ||
new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kHistogram, name)}; | ||
std::unique_ptr<metric_sdk::MeterSelector> histogram_meter_selector{ | ||
new metric_sdk::MeterSelector(name, version, schema)}; | ||
std::unique_ptr<metric_sdk::View> histogram_view{ | ||
new metric_sdk::View{name, "description", metric_sdk::AggregationType::kHistogram}}; | ||
p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector), | ||
std::move(histogram_view)); | ||
metrics_api::Provider::SetMeterProvider(provider); | ||
} | ||
} // namespace | ||
int main() | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
if (argc != 2) | ||
{ | ||
std::puts("invalid number of command line arguments"); | ||
return 0; | ||
} | ||
|
||
std::string example_type(argv[1]); | ||
std::string name{"ostream_metric_example"}; | ||
initMetrics(name); | ||
foo_library(name); | ||
|
||
if (example_type == "counter") | ||
{ | ||
foo_library::counter_example(name); | ||
} | ||
else | ||
{ | ||
foo_library::histogram_example(name); | ||
} | ||
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. Would also be a good use-case to create both counter and histogram if no argument is specified - to demonstrate getting metrics from multiple instruments simultaneously. 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. thanks, added multiple instruments simultaneously. |
||
} | ||
#else | ||
int main() {} | ||
|
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.
May be as an enhancement later, just like
val
, we can also have randomattributes
passed. Define 4-5 kv-attributes, select one of them randomly, and pass inRecord
method.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.
thanks, added random attribute.