• The scrape config for Prometheus:

    scrape_configs:
      - job_name: 'a10-poc'
        scrape_interval: 5s
        metrics_path: '/'
        static_configs:
          - targets: ['10.10.10.10:8000']
    Edited by Tyler Christiansen
  • This time async!

    from aiohttp import ClientSession
    from aioprometheus import Gauge, render, Registry
    from vibora import Vibora, Request, Response
    
    
    app = Vibora(__name__)
    app.registry = Registry()
    app.sessions = Gauge('sessions', 'Number of current sessions')
    app.registry.register(app.sessions)
    app.known_targets = set()
    
    
    class A10(object):
        def __init__(self, device):
            self.device = device
            self.base_url = f'https://{device}'
            self.connected = False
    
        async def connect(self, session):
            auth_headers = {'content-type': 'application/json'}
            auth_payload = {'credentials': {'username': 'user', 'password': 'pass'}}
            auth_endpoint = 'axapi/v3/auth'
            auth_url = f'{self.base_url}/{auth_endpoint}'
            token = None
            async with session.post(auth_url, json=auth_payload, headers=auth_headers, ssl=False) as response:
                token = await response.json()
                token = token['authresponse']['signature']
            self.common_headers = {'Content-type' : 'application/json', 'Authorization' : 'A10 {}'.format(token)}
    
        async def collect(self):
            endpoint = 'axapi/v3/sessions/oper?total=true'
            sessions = 0
            async with ClientSession() as session:
                if not self.connected:
                    await self.connect(session)
                async with session.get(f'{self.base_url}/{endpoint}', headers=self.common_headers, ssl=False) as response:
                    sessions = await response.json()
                    app.sessions.set({}, sessions['total-count'])
    
    
    @app.route('/metrics')
    async def handle_metrics(request: Request):
        target = request.args.values[b'target'][0].decode('utf-8')
        known_target = [x for x in app.known_targets if x.device == target]
        if known_target:
            a10 = known_target[0]
        else:
            a10 = A10(request.args.values[b'target'][0].decode('utf-8'))
            app.known_targets.add(a10)
        await a10.collect()
        content, http_headers = render(app.registry, [request.headers.get("accept")])
        return Response(content, headers=http_headers)
    
    
    app.run(host="0.0.0.0")
    Edited by Tyler Christiansen
  •   - job_name: 'a10-poc'
        scrape_interval: 5s
        static_configs:
          - targets: ['a10-a.example.com', 'a10-b.example.com']
        relabel_configs:
          - source_labels: [__address__]
            target_label: __param_target
          - source_labels: [__param_target]
            target_label: instance
          - target_label: __address__
            replacement: '1.2.3.4:5000'
  • Note: you will probably have to install vibora from the v0.1.0 or master branch instead of from pip. There are some fixes for query strings that haven't been cut to a new release yet.

  • Packages you need to pip install for the async version:

    aiohttp
    aioprometheus

    As mentioned previously, you'll likely need to install vibora from the master branch. This is the project link. The reason is because of this issue.

    In order to properly install vibora from the master branch, follow these steps:

    pip install Cython
    git clone https://github.com/vibora-io/vibora
    cd vibora
    git checkout v0.1.0
    python build.py
    python setup.py install
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment