Danna Castro
Danna Castro

Reputation: 299

Monitoring django rest framework api on production server

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.

Upvotes: 12

Views: 8050

Answers (5)

Simon Gurcke
Simon Gurcke

Reputation: 501

Apitally may also be a good fit here.

It's an API monitoring & analytics tool with an integration for Django REST Framework (DRF). It captures request and response metadata and provides a simple dashboard with various API metrics & insights, including number of requests, error rates, response times, payload sizes, etc.

There is a specific setup guide for Django REST Framework that you can follow to get started. The basic steps are:

  1. Create app in Apitally dashboard to get a client ID
  2. Install client library in your DRF project:
pip install "apitally[django_rest_framework]"
  1. Add Apitally middleware in your Django settings:
MIDDLEWARE = [
   "apitally.django.ApitallyMiddleware",
   # Other middleware ...
]
APITALLY_MIDDLEWARE = {
   "client_id": "your-client-id",
   "env": "dev",  # or "prod" etc.
}
  1. Deploy your application and Apitally starts tracking your API stats.

The dashboard looks like this:

Apitally traffic dashboard

Disclaimer: I'm the author of Apitally.

Upvotes: 1

Hujaakbar
Hujaakbar

Reputation: 1080

DRF Tracking library on the accepted answer is dead.

Its fork is available here drf-api-tracking.

Another library that is maintained by Jazzband is django-silk.

It defines itself as

Silky smooth profiling for Django: a live profiling and inspection tool for the Django framework. Silk intercepts and stores HTTP requests and database queries before presenting them in a user interface for further inspection

silk image

image source: jazzband/django-silk github repository

Upvotes: 0

marco carminati
marco carminati

Reputation: 54

maybe you could use drf-tracking

Upvotes: 2

Dhia
Dhia

Reputation: 10609

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

install: pip install drf-tracking

apply migrations: python manage.py migrate

add the following to you API views:

 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.

Upvotes: 15

mmcclannahan
mmcclannahan

Reputation: 1748

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.

Upvotes: 5

Related Questions