Django中间件能够可视化应用程序的流量在Kibana中

网友投稿 986 2022-10-28

Django中间件能够可视化应用程序的流量在Kibana中

Django中间件能够可视化应用程序的流量在Kibana中

django-traffic

A Django middleware that helps visualize your APP's traffic in Kibana

In a nutshell, by using this middleware you need no more effort to stream your app's traffic in your ElasticSearch host(s) and use Kibana for visualizations around it.

Request information transmitted to ElasticSearch:

timestamp | type: datelocation | type: geo_pointmethod | type: stringbody | type: stringpath | type: stringpath_info | type: stringscheme | type: stringencoding | type: stringencoding_type | type: string, supported only in Django 1.10 and laterip | type: ip

Geolocation is achieved by using django.contrib.gis.geoip2.GeoIP2 wrapper, included in Django 1.9 and latter.

Quick Start

1. Install using pip:

pip install django-traffic

To install the latest version directly from GitHub:

pip install git+https://github.com/koslibpro/django-traffic

2. Include "django-traffic" in your INSTALLED_APPS:

INSTALLED_APPS = [ ... 'django_traffic',]

3. Include "ESTrafficInfoMiddleware" to your MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = ( ... 'django_traffic.middleware.ESTrafficInfoMiddleware',)

The middleware is created in a way that supports both MIDDLEWARE_CLASSES on Django older versions and MIDDLEWARE in latest Django versions.

Configuration

There are some variables required in your settings.py file to function normally.

TRAFFIC_INDEX_NAME: this is the name of the index that will be used in ElasticSearch. If you leave this empty or do not define it, the default index name will be applied: django-traffic. ES_CLIENT: if you already have an ElasticSearch() client instance ready in your app, we'll use this one be default. ES_HOST: this is required only if you don't have an ES_CLIENT defined. Here the lib expects to find a hostname (including the port) of your ElasticSearch instance. GEO_DB_PATH: if you don't have GEOIP_PATH already defined, you need to define the path where django can find your geolocation database. LOG_WITHOUT_LOCATION: (default False) log data even when ip cannot be translated to location

After you deploy your project or locally run your django server, requests and traffic to your web app will be sent to the ElasticSearch hosts defined. Practically you are ready to create a Kibana map-tile visualization and start watching where traffic is flooding you in.

Contributing - Error Reporting

This lib was made with my own needs in mind, so it's uncommon to fit everyone's project out there. For Error Reporting, open an issue in Github and I will try to take care of it as soon as possible. If you are able to contribute to this lib and make it better, feel free to fork it and adjust it to your use-case.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SSM框架(spring+springmvc+mybatis)+Mysql实现的高校运动会管理系统(角色分为管理员和普通用户 功能包含普通学生老师参赛、开幕广播信息查看、管理员广播器材用户赛事管理等)
下一篇:SSH框架(spring+struts2+hibernate)+Mysql实现的会议管理系统(功能包含会议室管理、会议管理、用户管理、部门管理、设备管理、个人资料编辑等)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~