How to use the amplify.agent.common.context.context.plus_cache function in amplify

To help you get started, we’ve selected a few amplify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nginxinc / nginx-amplify-agent / test / unit / agent / collectors / plus / util / api / http_cache.py View on Github external
def test_gather_data(self):
        cache_obj = NginxApiHttpCacheObject(local_name='http_cache', parent_local_id='nginx123', root_uuid='root123')
        # Do a quick override of api_internal_url_cache
        cache_obj.api_internal_url_cache = 'test_api'

        # Get the cache collector
        cache_collector = cache_obj.collectors[-1]

        # Insert some dummy data
        context.plus_cache.put('test_api', (
            {
                "http" : {
                    "caches": {
                        "http_cache": {
                            "size": 537366528,
                            "max_size": 536870912,
                            "cold": False,
                            "hit": {
                                "responses": 2096882,
                                "bytes": 43493401813
                            },
                            "stale": {
                                "responses": 0,
                                "bytes": 0
                            },
                            "updating": {
github nginxinc / nginx-amplify-agent / test / unit / agent / collectors / plus / util / status / slab.py View on Github external
def test_collect(self):
        slab_obj = NginxSlabObject(local_name=u'h1u', parent_local_id='nginx123', root_uuid='root123')
        # Do a quick override of plus_status_internal_url_cache
        slab_obj.plus_status_internal_url_cache = 'test_status'

        # Get the slab collector
        slab_collector = slab_obj.collectors[-1]
        assert_that(slab_collector.last_collect, equal_to(None))

        # Insert some dummy data
        context.plus_cache.put('test_status', (
            {
                u'slabs': {
                    u'h1u': {
                        u'pages': {u'free': 2, u'used': 4},
                        u'slots': {
                            u'1024': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'128': {u'fails': 0, u'free': 26, u'reqs': 6, u'used': 6},
                            u'16': {u'fails': 0, u'free': 251, u'reqs': 3, u'used': 3},
                            u'2048': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'256': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'32': {u'fails': 0, u'free': 124, u'reqs': 3, u'used': 3},
                            u'512': {u'fails': 0, u'free': 6, u'reqs': 2, u'used': 2},
                            u'64': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'8': {u'fails': 0, u'free': 502, u'reqs': 2, u'used': 2}
                        }
                    }
github nginxinc / nginx-amplify-agent / test / unit / agent / collectors / plus / util / status / upstream.py View on Github external
def setup_method(self, method):
        super(UpstreamCollectorTestCase, self).setup_method(method)
        context.plus_cache = None
        context._setup_plus_cache()
github nginxinc / nginx-amplify-agent / test / unit / agent / collectors / plus / cache.py View on Github external
def setup_method(self, method):
        super(CacheCollectorTestCase, self).setup_method(method)
        context.plus_cache = None
        context._setup_plus_cache()
github nginxinc / nginx-amplify-agent / test / unit / agent / tanks / plus_cache.py View on Github external
def teardown_method(self, method):
        self.plus_cache = None
        context.plus_cache = PlusCache()

        super(PlusCacheTestCase, self).teardown_method(method)
github nginxinc / nginx-amplify-agent / test / unit / agent / collectors / plus / util / api / slab.py View on Github external
u'128': {u'fails': 0, u'free': 26, u'reqs': 6, u'used': 6},
                            u'16': {u'fails': 0, u'free': 251, u'reqs': 3, u'used': 3},
                            u'2048': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'256': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'32': {u'fails': 0, u'free': 124, u'reqs': 3, u'used': 3},
                            u'512': {u'fails': 0, u'free': 6, u'reqs': 2, u'used': 2},
                            u'64': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'8': {u'fails': 0, u'free': 502, u'reqs': 2, u'used': 2}
                        }
                    }
                },
            },
            1
        ))

        context.plus_cache.put('test_api', (
            {
                u'slabs': {
                    u'h1u': {
                        u'pages': {u'free': 5, u'used': 30},
                        u'slots': {
                            u'1024': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'128': {u'fails': 0, u'free': 26, u'reqs': 6, u'used': 6},
                            u'16': {u'fails': 0, u'free': 251, u'reqs': 3, u'used': 3},
                            u'2048': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'256': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'32': {u'fails': 0, u'free': 124, u'reqs': 3, u'used': 3},
                            u'512': {u'fails': 0, u'free': 6, u'reqs': 2, u'used': 2},
                            u'64': {u'fails': 0, u'free': 0, u'reqs': 0, u'used': 0},
                            u'8': {u'fails': 0, u'free': 502, u'reqs': 2, u'used': 2}
                        }
                    }
github nginxinc / nginx-amplify-agent / test / unit / agent / collectors / plus / util / status / slab.py View on Github external
def setup_method(self, method):
        super(SlabCollectorTestCase, self).setup_method(method)
        context.plus_cache = None
        context._setup_plus_cache()
github nginxinc / nginx-amplify-agent / test / unit / agent / collectors / plus / util / api / http_upstream.py View on Github external
def setup_method(self, method):
        super(ApiHttpUpstreamCollectorTestCase, self).setup_method(method)
        context.plus_cache = None
        context._setup_plus_cache()
github nginxinc / nginx-amplify-agent / test / unit / agent / collectors / plus / abstract.py View on Github external
def test_old_dummy_data(self):
        plus_obj = PlusObject(local_name='test_obj', parent_local_id='nginx123', root_uuid='root123')
        # Do a quick override of plus_status_internal_url_cache
        plus_obj.plus_status_internal_url_cache = 'test_status'

        # Insert some dummy data
        context.plus_cache.put('test_status', ({'pluss': {'test_obj': {}}}, 0))
        context.plus_cache.put('test_status', ({'pluss': {'test_obj': {'proper': 'data'}}}, 2))

        status_collector = PlusStatusCollector(object=plus_obj)
        status_collector.last_collect = 1  # Hard set timestamp
        data = status_collector.gather_data()

        assert_that(data, has_length(1))
        assert_that(data, equal_to([({'proper': 'data'}, 2)]))
        assert_that(status_collector.last_collect, equal_to(2))
github nginxinc / nginx-amplify-agent / amplify / agent / collectors / nginx / metrics.py View on Github external
try:
            aggregated_api_payload = traverse_plus_api(
                location_prefix=self.object.api_internal_url,
                root_endpoints_to_skip=self.object.api_endpoints_to_skip
            )
        except GreenletExit:
            raise
        except:
            context.log.error('failed to check plus_api url %s' % self.object.api_internal_url)
            context.log.debug('additional info', exc_info=True)
            aggregated_api_payload = None

        if not aggregated_api_payload:
            return

        context.plus_cache.put(self.object.api_internal_url, (aggregated_api_payload, stamp))

        connections = aggregated_api_payload.get('connections', {})
        http = aggregated_api_payload.get('http', {})
        requests = http.get('requests', {})
        ssl = aggregated_api_payload.get('ssl', {})
        processes = aggregated_api_payload.get('processes', {})
        stream = aggregated_api_payload.get('stream', {})

        # gauges
        self.object.statsd.gauge('nginx.http.conn.active', connections.get('active'))
        self.object.statsd.gauge('nginx.http.conn.idle', connections.get('idle'))
        self.object.statsd.gauge('nginx.http.conn.current', connections.get('active') + connections.get('idle'))
        self.object.statsd.gauge('nginx.http.request.current', requests.get('current'))

        # counters
        counted_vars = {