@@ -78,57 +78,52 @@ The **Azure Monitor Metrics Exporter** allows you to export metrics to `Azure Mo
7878* Put the instrumentation key in ``APPINSIGHTS_INSTRUMENTATIONKEY `` environment variable.
7979* You can also specify the instrumentation key explicitly in the code, which will take priority over a set environment variable.
8080
81- Using the Metrics exporter
82- *****************************
83-
84- .. code :: python
85-
86- import time
87-
88- from opencensus.ext.azure import metrics_exporter
89- from opencensus.stats import aggregation as aggregation_module
90- from opencensus.stats import measure as measure_module
91- from opencensus.stats import stats as stats_module
92- from opencensus.stats import view as view_module
93- from opencensus.tags import tag_map as tag_map_module
94-
95- stats = stats_module.stats
96- view_manager = stats.view_manager
97- stats_recorder = stats.stats_recorder
98-
99- CARROTS_MEASURE = measure_module.MeasureInt(" carrots" ,
100- " number of carrots" ,
101- " carrots" )
102- CARROTS_VIEW = view_module.View(" carrots_view" ,
103- " number of carrots" ,
104- [],
105- CARROTS_MEASURE ,
106- aggregation_module.CountAggregation())
107-
108-
109- def main ():
110- # Enable metrics
111- # Set the interval in seconds in which you want to send metrics
112- exporter = metrics_exporter.new_metrics_exporter()
113- view_manager.register_exporter(exporter)
114-
115- view_manager.register_view(CARROTS_VIEW )
116- mmap = stats_recorder.new_measurement_map()
117- tmap = tag_map_module.TagMap()
118-
119- mmap.measure_int_put(CARROTS_MEASURE , 1000 )
120- mmap.record(tmap)
121- # Default export interval is every 15.0s
122- # Your application should run for at least this amount
123- # of time so the exporter will meet this interval
124- # Sleep can fulfill this
125- time.sleep(60 )
126-
127- print (" Done recording metrics" )
128-
81+ .. code :: python
12982
130- if __name__ == " __main__" :
131- main()
83+ import time
84+
85+ from opencensus.ext.azure import metrics_exporter
86+ from opencensus.stats import aggregation as aggregation_module
87+ from opencensus.stats import measure as measure_module
88+ from opencensus.stats import stats as stats_module
89+ from opencensus.stats import view as view_module
90+ from opencensus.tags import tag_map as tag_map_module
91+
92+ stats = stats_module.stats
93+ view_manager = stats.view_manager
94+ stats_recorder = stats.stats_recorder
95+
96+ CARROTS_MEASURE = measure_module.MeasureInt(" carrots" ,
97+ " number of carrots" ,
98+ " carrots" )
99+ CARROTS_VIEW = view_module.View(" carrots_view" ,
100+ " number of carrots" ,
101+ [],
102+ CARROTS_MEASURE ,
103+ aggregation_module.CountAggregation())
104+
105+ def main ():
106+ # Enable metrics
107+ # Set the interval in seconds in which you want to send metrics
108+ exporter = metrics_exporter.new_metrics_exporter()
109+ view_manager.register_exporter(exporter)
110+
111+ view_manager.register_view(CARROTS_VIEW )
112+ mmap = stats_recorder.new_measurement_map()
113+ tmap = tag_map_module.TagMap()
114+
115+ mmap.measure_int_put(CARROTS_MEASURE , 1000 )
116+ mmap.record(tmap)
117+ # Default export interval is every 15.0s
118+ # Your application should run for at least this amount
119+ # of time so the exporter will meet this interval
120+ # Sleep can fulfill this
121+ time.sleep(60 )
122+
123+ print (" Done recording metrics" )
124+
125+ if __name__ == " __main__" :
126+ main()
132127
133128 Trace
134129~~~~~
0 commit comments