Esempio n. 1
0
    def instantiate_wavefront_stats_reporter(self, wf_span_reporter,
                                             application_tags):
        """Instantiate WavefrontReporter and Heartbeater Service."""
        # pylint: disable=fixme
        # TODO: this helper method should go in Tier 1 SDK
        wf_internal_reporter = wavefront_reporter.WavefrontReporter(
            prefix="~sdk.python.opentracing.",
            source=wf_span_reporter.source,
            registry=tagged_registry.TaggedRegistry(),
            reporting_interval=60,
            tags=dict(application_tags.get_as_list())
        ).report_minute_distribution()
        wf_internal_reporter.wavefront_client = (
            wf_span_reporter.get_wavefront_sender())
        wf_internal_reporter.start()

        wf_derived_reporter = wavefront_reporter.WavefrontReporter(
            source=wf_span_reporter.source,
            registry=tagged_registry.TaggedRegistry(),
            reporting_interval=self.report_frequency_millis / 1000,
            tags=dict(application_tags.get_as_list())
        ).report_minute_distribution()
        wf_derived_reporter.wavefront_client = (
            wf_span_reporter.get_wavefront_sender())
        wf_derived_reporter.start()

        heartbeater_service = wavefront_sdk.common.HeartbeaterService(
            wavefront_client=wf_span_reporter.get_wavefront_sender(),
            application_tags=application_tags,
            components=[self.WAVEFRONT_GENERATED_COMPONENT,
                        self.OPENTRACING_COMPONENT,
                        self.PYTHON_COMPONENT],
            source=wf_span_reporter.source)
        return wf_internal_reporter, wf_derived_reporter, heartbeater_service
 def test_wavefront_histogram(self):
     """Test Wavefront Histogram."""
     reg = tagged_registry.TaggedRegistry()
     _ = reg.histogram('pyformance_hist').add(1.0)
     wavefront_hist = wavefront_histogram.wavefront_histogram(
         reg, 'wavefront_hist').add(2.0)
     assert (isinstance(wavefront_hist,
                        wavefront_histogram.WavefrontHistogram))
Esempio n. 3
0
def report_metrics(host, server, token):
    """Metrics Reporting Function Example."""
    reg = tagged_registry.TaggedRegistry()

    wf_proxy_reporter = wavefront_reporter.WavefrontProxyReporter(
        host=host, port=2878, registry=reg,
        source='wavefront-pyformance-example',
        tags={'key1': 'val1', 'key2': 'val2'},
        prefix='python.proxy.').report_minute_distribution()
    wf_direct_reporter = wavefront_reporter.WavefrontDirectReporter(
        server=server, token=token, registry=reg,
        source='wavefront-pyformance-exmaple',
        tags={'key1': 'val1', 'key2': 'val2'},
        prefix='python.direct.').report_minute_distribution()

    # counter
    c_1 = reg.counter('foo_count', tags={'counter_key': 'counter_val'})
    c_1.inc()

    # delta counter
    d_1 = delta.delta_counter(reg, 'foo_delta_count',
                              tags={'delta_key': 'delta_val'})
    d_1.inc()
    d_1.inc()

    # gauge
    g_1 = reg.gauge('foo_gauge', tags={'gauge_key': 'gauge_val'})
    g_1.set_value(2)

    # meter
    m_1 = reg.meter('foo_meter', tags={'meter_key': 'meter_val'})
    m_1.mark()

    # timer
    t_1 = reg.timer('foo_timer', tags={'timer_key': 'timer_val'})
    timer_ctx = t_1.time()
    time.sleep(3)
    timer_ctx.stop()

    # histogram
    h_1 = reg.histogram('foo_histogram', tags={'hist_key': 'hist_val'})
    h_1.add(1.0)
    h_1.add(1.5)

    # Wavefront Histogram
    h_2 = wavefront_histogram.wavefront_histogram(reg, 'wf_histogram')
    h_2.add(1.0)
    h_2.add(2.0)

    wf_direct_reporter.report_now()
    wf_direct_reporter.stop()
    wf_proxy_reporter.report_now()
    wf_proxy_reporter.stop()
    def test_delta_counter(self):
        """Test Delta Counter."""
        reg = tagged_registry.TaggedRegistry()
        counter = delta.delta_counter(reg, 'foo')
        assert (isinstance(counter, delta.DeltaCounter))

        # test duplicate (should return previously registered counter)
        duplicate_counter = delta.delta_counter(reg, 'foo')
        assert (counter == duplicate_counter)
        assert (delta.is_delta_counter(delta.DeltaCounter.DELTA_PREFIX + 'foo',
                                       reg))
        different_counter = delta.delta_counter(reg, 'foobar')
        assert (counter != different_counter)
Esempio n. 5
0
def report_metrics(host, server='', token=''):
    """Runtime Metric Reporting Function Example."""
    reg = tagged_registry.TaggedRegistry()

    wf_proxy_reporter = wavefront_reporter.WavefrontProxyReporter(
        host=host, port=2878, registry=reg,
        source='runtime-metric-test',
        tags={'global_tag1': 'val1', 'global_tag2': 'val2'},
        prefix='python.proxy.',
        enable_runtime_metrics=True).report_minute_distribution()
    wf_direct_reporter = wavefront_reporter.WavefrontDirectReporter(
        server=server, token=token, registry=reg,
        source='runtime-metric-test',
        tags={'global_tag1': 'val1', 'global_tag2': 'val2'},
        prefix='python.direct.',
        enable_runtime_metrics=True).report_minute_distribution()

    wf_proxy_reporter.report_now()
    wf_proxy_reporter.stop()
    wf_direct_reporter.report_now()
    wf_direct_reporter.stop()
    direct_reporter.report_now()
    direct_reporter.stop()
    proxy_reporter.report_now()
    proxy_reporter.stop()


if __name__ == '__main__':
    # python example.py proxy_host server_url server_token
    _ = argparse.ArgumentParser()
    _.add_argument('host', help='Wavefront proxy host name.')
    _.add_argument('server', help='Wavefront server for direct ingestion.')
    _.add_argument('token', help='Wavefront API token.')
    ARGS = _.parse_args()

    reg = tagged_registry.TaggedRegistry()

    wf_proxy_reporter = wavefront_reporter.WavefrontProxyReporter(
        host=ARGS.host,
        port=2878,
        registry=reg,
        source='wavefront-pyformance-example',
        tags={
            'key1': 'val1',
            'key2': 'val2'
        },
        prefix='python.proxy.').report_minute_distribution()

    wf_direct_reporter = wavefront_reporter.WavefrontDirectReporter(
        server=ARGS.server,
        token=ARGS.token,