def __call__(self): """ Returns a derived gauge for outgoing requests per second Calculated by obtaining by getting the number of outgoing requests made using the requests library within an elapsed time and dividing that value over the elapsed time. :rtype: :class:`opencensus.metrics.export.gauge.DerivedLongGauge` :return: The gauge representing the outgoing requests metric """ gauge = DerivedDoubleGauge(DependencyRateMetric.NAME, 'Outgoing Requests per second', 'rps', []) gauge.create_default_time_series(DependencyRateMetric.get_value) return gauge
def __call__(self): """ Returns a derived gauge for incoming requests execution rate Calculated by getting the time it takes to make an incoming request and dividing over the amount of incoming requests over an elapsed time. :rtype: :class:`opencensus.metrics.export.gauge.DerivedLongGauge` :return: The gauge representing the incoming requests metric """ gauge = DerivedDoubleGauge(RequestsAvgExecutionMetric.NAME, 'Incoming Requests Average Execution Rate', 'milliseconds', []) gauge.create_default_time_series(RequestsAvgExecutionMetric.get_value) return gauge
def __call__(self): """ Returns a derived gauge for the CPU usage for the current process. Return values range from 0.0 to 100.0 inclusive. :rtype: :class:`opencensus.metrics.export.gauge.DerivedDoubleGauge` :return: The gauge representing the process cpu usage metric """ gauge = DerivedDoubleGauge(ProcessCPUMetric.NAME, 'Process CPU usage as a percentage', 'percentage', []) gauge.create_default_time_series(ProcessCPUMetric.get_value) # From the psutil docs: the first time this method is called with # interval = None it will return a meaningless 0.0 value which you are # supposed to ignore. Call cpu_percent() with process once so that the # subsequent calls from the gauge will be meaningful. PROCESS.cpu_percent() return gauge
def get_processor_time_metric(): """ Returns a derived gauge for the processor time. Processor time is defined as a float representing the current system wide CPU utilization minus idle CPU time as a percentage. Idle CPU time is defined as the time spent doing nothing. Return values range from 0.0 to 100.0 inclusive. :rtype: :class:`opencensus.metrics.export.gauge.DerivedDoubleGauge` :return: The gauge representing the processor time metric """ gauge = DerivedDoubleGauge(PROCESSOR_TIME, 'Processor time as a percentage', 'percentage', []) gauge.create_default_time_series(get_processor_time) # From the psutil docs: the first time this method is called with interval # = None it will return a meaningless 0.0 value which you are supposed to # ignore. Call cpu_percent() once so that the subsequent calls from the # gauge will be meaningful. psutil.cpu_times_percent() return gauge
def __init__(self, options): self._options = options self._instrumentation_key = options.instrumentation_key self._feature = _StatsbeatFeature.NONE if options.enable_local_storage: self._feature |= _StatsbeatFeature.DISK_RETRY if options.credential: self._feature |= _StatsbeatFeature.AAD self._stats_lock = threading.Lock() self._vm_data = {} self._vm_retry = True self._rp = _RP_NAMES[3] self._os_type = platform.system() # Attach metrics - metrics related to rp (resource provider) self._attach_metric = LongGauge( _ATTACH_METRIC_NAME, 'Statsbeat metric related to rp integrations', 'count', _get_attach_properties(), ) # Keep track of how many iterations until long export self._long_threshold_count = 0 # Network metrics - metrics related to request calls to Breeze self._network_metrics = {} # Map of gauge function -> metric # Gauge function is the callback used to populate the metric value self._network_metrics[_get_success_count_value] = DerivedLongGauge( _REQ_SUC_COUNT_NAME, 'Statsbeat metric tracking request success count', 'count', _get_network_properties(), ) self._network_metrics[_get_failure_count_value] = DerivedLongGauge( _REQ_FAIL_COUNT_NAME, 'Statsbeat metric tracking request failure count', 'count', _get_network_properties(), ) self._network_metrics[ _get_average_duration_value] = DerivedDoubleGauge( # noqa: E501 _REQ_DURATION_NAME, 'Statsbeat metric tracking average request duration', 'count', _get_network_properties(), ) self._network_metrics[_get_retry_count_value] = DerivedLongGauge( _REQ_RETRY_NAME, 'Statsbeat metric tracking request retry count', 'count', _get_network_properties(), ) self._network_metrics[_get_throttle_count_value] = DerivedLongGauge( _REQ_THROTTLE_NAME, 'Statsbeat metric tracking request throttle count', 'count', _get_network_properties(), ) self._network_metrics[_get_exception_count_value] = DerivedLongGauge( _REQ_EXCEPTION_NAME, 'Statsbeat metric tracking request exception count', 'count', _get_network_properties(), ) # feature/instrumentation metrics # metrics related to what features and instrumentations are enabled self._feature_metric = LongGauge( _FEATURE_METRIC_NAME, 'Statsbeat metric related to features enabled', # noqa: E501 'count', _get_feature_properties(), ) # Instrumentation metric uses same name/properties as feature self._instrumentation_metric = LongGauge( _FEATURE_METRIC_NAME, 'Statsbeat metric related to instrumentations enabled', # noqa: E501 'count', _get_feature_properties(), )