Artifactory Query Language allows us to retrieve any artifact and/or build data from Artifactory. In this example we will use AQL together with jq to retrieve and sort file statistics for all the items in a repository.
The AQL query below can be used against Docker Local, Virtual, and Remote Cache repositories and will sort the output by the number of downloads.
However, this query can be modified to retrieve file statistics for different package types by changing the string in the $match operator. For example, to retrieve file statistics for an NPM repository we can use the following:
Sample response:
Recommendations:
1. How to start using AQL
2. How can I get count of downloaded artifacts in specified time period
3. How to Use Artifactory Query Language (AQL) to Obtain Data from an Archive
4. Aql
5. File Statistics API
6. How to search old docker tags using AQL or CLI
The AQL query below can be used against Docker Local, Virtual, and Remote Cache repositories and will sort the output by the number of downloads.
curl -s -k -XPOST "<ARTIFACTORY_URL>/artifactory/api/search/aql" -d 'items.find({"repo":"<REPOSITORY_NAME>"},{"name": {"$match" : "*manifest.*"}}).include("stat")' -H "Content-Type: text/plain" -u <USER>:<PASSWORD> | jq '[.results[] | {repo: .repo, path: .path, name: .name, type: .type, size: .size, created: .created, created_by: .created_by, modified: .modified, modified_by: .modified_by, updated: .updated, stats: .stats}] | sort_by(.stats[].downloads)| reverse'
However, this query can be modified to retrieve file statistics for different package types by changing the string in the $match operator. For example, to retrieve file statistics for an NPM repository we can use the following:
curl -s -k -XPOST "<ARTIFACTORY_URL>/artifactory/api/search/aql" -d 'items.find({"repo":"<REPOSITORY_NAME>"},{"name": {"$match" : "*.tgz"}}).include("stat")' -H "Content-Type: text/plain" -u <USER>:<PASSWORD> | jq '[.results[] | {repo: .repo, path: .path, name: .name, type: .type, size: .size, created: .created, created_by: .created_by, modified: .modified, modified_by: .modified_by, updated: .updated, stats: .stats}] | sort_by(.stats[].downloads)| reverse'
Sample response:
[ { "repo": "v1-npm-remote-cache", "path": "array-flatten/-", "name": "array-flatten-1.1.1.tgz", "type": "file", "size": 1992, "created": "2023-06-19T17:40:25.238Z", "created_by": "admin", "modified": "2018-05-26T17:22:05.000Z", "modified_by": "admin", "updated": "2023-06-19T17:40:25.366Z", "stats": [ { "downloaded": "2023-06-22T20:58:59.359Z", "downloaded_by": "admin", "downloads": 7, "remote_downloads": 0 } ] }, { "repo": "v1-npm-remote-cache", "path": "call-bind/-", "name": "call-bind-1.0.2.tgz", "type": "file", "size": 5365, "created": "2023-06-19T17:40:22.648Z", "created_by": "admin", "modified": "2021-01-11T22:36:47.000Z", "modified_by": "admin", "updated": "2023-06-19T17:40:22.649Z", "stats": [ { "downloaded": "2023-06-22T20:53:24.283Z", "downloaded_by": "admin", "downloads": 3, "remote_downloads": 0 } ] } ]
Recommendations:
1. How to start using AQL
2. How can I get count of downloaded artifacts in specified time period
3. How to Use Artifactory Query Language (AQL) to Obtain Data from an Archive
4. Aql
5. File Statistics API
6. How to search old docker tags using AQL or CLI