Recording measurements

Source code example

packagemainimport("go.opencensus.io/stats")funcmain(){mLatencyMs=stats.Float64("latency","The latency in milliseconds","ms")mLines=stats.Int64("lines_in","The number of lines processed","1")mBytesIn=stats.Int64("bytes_in","The number of bytes received","By")// Invoking .M produces measurements that we then record against
// a context "ctx" with tags.
stats.Record(ctx,mLatencyMs.M(17),mLines.M(238),mBytesIn.M(7000))}

packageio.opencensus.metrics.snippet;importio.opencensus.stats.Measure.MeasureDouble;importio.opencensus.stats.Measure.MeasureLong;importio.opencensus.stats.Stats;importio.opencensus.stats.StatsRecorder;publicclassJavaSnippet{privatestaticfinalMeasureDoubleM_LATENCY_MS=MeasureDouble.create("latency","The latency in milliseconds","ms");privatestaticfinalMeasureLongM_LINES=MeasureLong.create("lines_in","The number of lines processed","1");privatestaticfinalMeasureLongM_BYTES_IN=MeasureLong.create("bytes_in","The number of bytes received","By");privatestaticfinalStatsRecorderSTATS_RECORDER=Stats.getStatsRecorder();publicstaticvoidmain(String[]args){// Record the values, having already added tags in the current context
STATS_RECORDER.newMeasureMap().put(M_LATENCY_MS,17.0).put(M_LINES,238).put(M_BYTES_IN,7000).record();}}

#/usr/bin/env pythonfromopencensus.statsimportstatsfromopencensus.statsimportmeasuredefmain():m_latency_ms=measure.MeasureFloat("latency","The latency in milliseconds","ms")m_lines=measure.MeasureInt("lines_in","The number of lines processed","1")m_bytes_in=measure.MeasureInt("bytes_in","The number of bytes received","By")mmap=stats.Stats().stats_recorder.new_measurement_map()mmap.measure_float_put(m_latency_ms,17)mmap.measure_int_put(m_lines,238)mmap.measure_int_put(m_bytes_in,7000)# Record the measurements against tags in "tmap"mmap.record(tmap);if__name__=='__main__':main()

#include"opencensus/stats/stats.h"opencensus::stats::MeasureDoubleLatencyMsMeasure(){staticconstautomeasure=opencensus::stats::MeasureDouble::Register("latency","The latency in milliseconds","ms");returnmeasure;}opencensus::stats::MeasureInt64LinesMeasure(){staticconstautomeasure=opencensus::stats::MeasureDouble::Register("lines_in","The number of lines processed","1");returnmeasure;}opencensus::stats::MeasureInt64BytesInMeasure(){staticconstautomeasure=opencensus::stats::MeasureDouble::Register("bytes_in","The number of bytes received","By");returnmeasure;}intmain(intargc,char**argv){opencensus::stats::Record({{LatencyMsMeasure(),17.0}},{{LinesMeasure(),238}},{{BytesInMeasure(),7000}});}