简体   繁体   English

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

[英]Monitoring django rest framework api on production server

I have an API created using django rest framework in a Linode server. 我在Linode服务器中使用django rest框架创建了一个API。 Now, I want to check the number and the response code of each request, I want to get stats for my api. 现在,我想查看每个请求的编号和响应代码,我想获取我的api的统计信息。 How can I do it? 我该怎么做? thankyou so much. 非常感谢。

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

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. 如果您想要更多功能完整的统计信息以及监控和警报,您可能需要查看类似NewRelic的内容。

也许你可以使用drf-tracking

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM