8.2. 使用 API 查看使用日志
可以使用 API 查看机构或存储库的日志。它们也可以聚合(分组),或者列出包含更详细的信息。也可以由用户、特定日期范围或页面查看日志。
8.2.1. 查看聚合的日志
聚合的日志可由机构、存储库、特定用户或当前用户查看。您还可以传递可选命令,如 execute er
、starttime/endtime
和 next_page
来过滤结果。
先决条件
- 您已创建了 OAuth 访问令牌。
-
您已在
config.yaml
文件中设置了BROWSER_API_CALLS_XHR_ONLY: false
。
流程
使用
GET /api/v1/user/aggregatelogs
API 端点为当前用户返回聚合(或分组)日志:$ curl -X GET \ -H "Authorization: Bearer <bearer_token>" \ -H "Accept: application/json" \ "https://<quay-server.example.com>/api/v1/user/aggregatelogs"
输出示例
{"aggregated": [{"kind": "create_tag", "count": 1, "datetime": "Tue, 18 Jun 2024 00:00:00 -0000"}, {"kind": "manifest_label_add", "count": 1, "datetime": "Tue, 18 Jun 2024 00:00:00 -0000"}, {"kind": "push_repo", "count": 2, "datetime": "Tue, 18 Jun 2024 00:00:00 -0000"}, {"kind": "revert_tag", "count": 1, "datetime": "Tue, 18 Jun 2024 00:00:00 -0000"}]}
您还可以传递执行者和
starttime/endtime
查询,以便在特定时间段内获取特定用户的聚合日志。例如:
$ curl -X GET \ -H "Authorization: Bearer <bearer_token>" \ -H "Accept: application/json" \ "<quay-server.example.com>/api/v1/user/aggregatelogs?performer=<username>&starttime=<MM/DD/YYYY>&endtime=<MM/DD/YYYY>"
机构也可以使用
GET /api/v1/organization/{orgname}/aggregatelogs
来查看聚合的日志。例如:$ curl -X GET \ -H "Authorization: Bearer <bearer_token>" \ -H "Accept: application/json" \ "<quay-server.example.com>/api/v1/organization/{orgname}/aggregatelogs"
存储库也可以使用
GET /api/v1/repository/{repository}/aggregatelogs
命令查看聚合的日志。以下示例包括starttime/endtime
字段:$ curl -X GET \ -H "Authorization: Bearer <bearer_token>" \ -H "Accept: application/json" \ "<quay-server.example.com>/api/v1/repository/<repository_name>/<namespace>/aggregatelogs?starttime=2024-01-01&endtime=2024-06-18""
8.2.2. 查看详细日志
详细日志可由机构、存储库、特定用户或当前用户查看。您还可以传递可选字段,如 executeer、starttime/endtime
和 next_page
来过滤结果。
流程
使用
GET /api/v1/user/logs
API 端点返回用户的日志条目列表。例如:$ curl -X GET -H "Authorization: Bearer <bearer_token>" -H "Accept: application/json" "<quay-server.example.com>/api/v1/user/logs"
您还可以传递执行者和
startime/endtime
查询,以便在特定时间段内获取特定用户的日志。例如:
$ curl -X GET -H "Authorization: Bearer <bearer_token>" -H "Accept: application/json" "http://quay-server.example.com/api/v1/user/logs?performer=quayuser&starttime=01/01/2024&endtime=06/18/2024"
输出示例
--- {"start_time": "Mon, 01 Jan 2024 00:00:00 -0000", "end_time": "Wed, 19 Jun 2024 00:00:00 -0000", "logs": [{"kind": "revert_tag", "metadata": {"username": "quayuser", "repo": "busybox", "tag": "test-two", "manifest_digest": "sha256:57583a1b9c0a7509d3417387b4f43acf80d08cdcf5266ac87987be3f8f919d5d"}, "ip": "192.168.1.131", "datetime": "Tue, 18 Jun 2024 18:59:13 -0000", "performer": {"kind": "user", "name": "quayuser", "is_robot": false, "avatar": {"name": "quayuser", "hash": "b28d563a6dc76b4431fc7b0524bbff6b810387dac86d9303874871839859c7cc", "color": "#17becf", "kind": "user"}}}, {"kind": "push_repo", "metadata": {"repo": "busybox", "namespace": "quayuser", "user-agent": "containers/5.30.1 (github.com/containers/image)", "tag": "test-two", "username": "quayuser", } ---
使用
GET /api/v1/organization/{orgname}/logs
端点返回指定机构的日志:$ curl -X GET \ -H "Authorization: Bearer <bearer_token>" \ -H "Accept: application/json" \ "http://<quay-server.example.com>/api/v1/organization/{orgname}/logs"
使用
GET /api/v1/repository/{repository}/logs
端点返回指定存储库的日志:$ curl -X GET \ -H "Authorization: Bearer <bearer_token>" \ -H "Accept: application/json" \ "http://<quay-server.example.com>/api/v1/repository/{repository}/logs"