监视生产服务器上的django rest framework api

时间:2022-10-17 15:51:23

I have an API created using django rest framework in a Linode server. Now, I want to check the number and the response code of each request, I want to get stats for my api. How can I do it? thankyou so much.

我在Linode服务器中使用django rest框架创建了一个API。现在,我想查看每个请求的编号和响应代码,我想获取我的api的统计信息。我该怎么做?非常感谢。

3 个解决方案

#1


11  

DRF Tracking is utilities to track requests to DRF API views, it may be good fit for you:

DRF跟踪是跟踪DRF API视图请求的实用程序,它可能适合您:

install: pip install drf-tracking

安装:pip install drf-tracking

apply migrations: python manage.py migrate

应用迁移:python manage.py migrate

add the following to you API views:

将以下内容添加到API视图中:

 from rest_framework import generics
 from rest_framework_tracking.mixins import LoggingMixin

 class LoggingView(LoggingMixin, generics.GenericAPIView):
    def get(self, request):
        return Response('with logging')

There is also an other alternative Django Analytics if you want to have more than choice.

如果您想要的不仅仅是选择,还有另一种替代Django Analytics。

#2


5  

So the simplest way to get started is to check your webserver's access logs. That should give you the number of requests in and responses out, including status code. If you want more feature-full statistics as well as monitoring and alerting, you may want to look into something like NewRelic.

因此,最简单的入门方法是检查您的Web服务器的访问日志。这应该为您提供请求和响应的数量,包括状态代码。如果您想要更多功能完整的统计信息以及监控和警报,您可能需要查看类似NewRelic的内容。

#3


2  

maybe you could use drf-tracking

也许你可以使用drf-tracking

#1


11  

DRF Tracking is utilities to track requests to DRF API views, it may be good fit for you:

DRF跟踪是跟踪DRF API视图请求的实用程序,它可能适合您:

install: pip install drf-tracking

安装:pip install drf-tracking

apply migrations: python manage.py migrate

应用迁移:python manage.py migrate

add the following to you API views:

将以下内容添加到API视图中:

 from rest_framework import generics
 from rest_framework_tracking.mixins import LoggingMixin

 class LoggingView(LoggingMixin, generics.GenericAPIView):
    def get(self, request):
        return Response('with logging')

There is also an other alternative Django Analytics if you want to have more than choice.

如果您想要的不仅仅是选择,还有另一种替代Django Analytics。

#2


5  

So the simplest way to get started is to check your webserver's access logs. That should give you the number of requests in and responses out, including status code. If you want more feature-full statistics as well as monitoring and alerting, you may want to look into something like NewRelic.

因此,最简单的入门方法是检查您的Web服务器的访问日志。这应该为您提供请求和响应的数量,包括状态代码。如果您想要更多功能完整的统计信息以及监控和警报,您可能需要查看类似NewRelic的内容。

#3


2  

maybe you could use drf-tracking

也许你可以使用drf-tracking