Stats
class Stats
This class provides static functions to give you access to the most common Stats actions.
It's typically used to start the desired Stats exporter and get access to Stats recording, Tag management and View registration.
Example:
use OpenCensus\Core\DaemonClient;
use OpenCensus\Trace\Tracer;
use OpenCensus\Tags\TagKey;
use OpenCensus\Tags\TagValue;
use OpenCensus\Tags\TagContext;
use OpenCensus\Stats\Stats;
use OpenCensus\Stats\Measure;
use OpenCensus\Stats\View\View;
use OpenCensus\Stats\View\Aggregation;
try {
$daemon = DaemonClient::init(array("socketPath" => "/tmp/ocdaemon.sock"));
Tracer::start($daemon);
Stats::setExporter($daemon);
$daemon->setReportingPeriod(2.0);
} catch (\Exception $e) {
// Unable to set Stats Exporter, proceeding as Noop
}
$frontendKey = TagKey::create("example.com/keys/frontend");
$videoSize = Measure::newIntMeasure("example.com/measure/video_size", "size of processed videos", Measure::BYTES);
Stats::registerView(new View(
"example.com/views/video_size",
"processed video size over time",
$videoSize,
Aggregation::distribution([0, 1<<16, 1<<32]),
$frontendKey
));
Tracer::inSpan(['name' => 'example.com/ProcessVideo'], function () use ($frontendKey, $videoSize) {
// process video
$tagCtx = TagContext::fromContext();
$tagCtx->insert($frontendKey, TagValue::create("mobile-ios9.3.5"));
sleep(1);
Stats::newMeasurementMap()
->put($videoSize->M(25648))
->record();
});
Methods
static Stats
getInstance()
Retrieve Stats instance.
static
static ExporterInterface
getExporter()
Retrieve our ExporterInterface.
static TagContext
newTagContext()
Return a new TagContext object.
static MeasurementInterface
newMeasurementMap()
Retrieve a new MeasurementInterface for recording Measurements
static bool
static bool
Details
at line 91
static Stats
getInstance()
Retrieve Stats instance.
at line 107
static
setExporter(ExporterInterface $exporter)
Set the ExporterInterface to use by the Stats components.
at line 117
static ExporterInterface
getExporter()
Retrieve our ExporterInterface.
at line 127
static TagContext
newTagContext()
Return a new TagContext object.
at line 137
static MeasurementInterface
newMeasurementMap()
Retrieve a new MeasurementInterface for recording Measurements
at line 151
static bool
registerView(View ...$views)
Register one or multiple views.
at line 162
static bool
unregisterView(View ...$views)
Unregister one or multiple views.