CKAN API Tracking Extension
This extension allows CKAN portals to monitor the use of API tokens by users or service accounts.
Developed by Norwegian Refugee Council (NRC) and Open Knowledge Foundation (OKFN).
Use-cases
- Track API usage by dataset and organization
- Track API usage by users
- Track API usage by API token
How it works
This extension adds a new middleware to the CKAN application that intercepts all API requests and logs them into the CKAN database. A new database table was created to store this information.
This extension also includes a series of dashboards with a summary of the available data. All data from this extension is only accessible by sysadmins.
Requirements
| CKAN Version |
Compatible |
| 2.10 |
Yes |
| 2.11 |
Yes |
Installation
pip install -e "git+https://github.com/NorwegianRefugeeCouncil/ckanext-api-tracking.git@main#egg=ckanext-api-tracking"
pip install -r https://raw.githubusercontent.com/NorwegianRefugeeCouncil/ckanext-api-tracking/main/requirements.txt
Add api_tracking to the ckan.plugins setting. From CKAN >= 2.11 it’s also required to add the core extension tracking.
API Endpoints
/api/action/all_token_usage - All API requests with a user token
/api/action/most_accessed_dataset_with_token - Most accessed datasets
/api/action/most_accessed_token - Most accessed user tokens
/api/action/users_active_metrics - Most active users
CSV Endpoints
/tracking-csv/most-accessed-dataset-with-token.csv
/tracking-csv/most-accessed-token.csv
/tracking-csv/all-token-usage.csv
/tracking-csv/users-active-metrics.csv
Config Settings
ckanext.api_tracking.track_login = true # default is false
ckanext.api_tracking.track_logout = true # default is false