Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GET /api/stats/summary -> .gravity.last_update #2048

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/api/docs/content/specs/stats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ components:
type: integer
description: Number of domain on your Pi-hole's gravity list
example: 104756
last_update:
type: integer
description: Unix timestamp of last gravity update (may be `0` if unknown)
example: 1725194639
upstreams:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions src/api/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ int api_stats_summary(struct ftl_conn *api)

cJSON *gravity = JSON_NEW_OBJECT();
JSON_ADD_NUMBER_TO_OBJECT(gravity, "domains_being_blocked", num_gravity);
JSON_ADD_NUMBER_TO_OBJECT(gravity, "last_update", gravity_last_updated());

cJSON *json = JSON_NEW_OBJECT();
JSON_ADD_ITEM_TO_OBJECT(json, "queries", queries);
Expand Down
5 changes: 5 additions & 0 deletions src/database/gravity-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -2796,3 +2796,8 @@ bool gravity_updated(void)

return changed;
}

time_t __attribute__((pure)) gravity_last_updated(void)
{
return last_updated > 0 ? (time_t)last_updated : 0;
}
2 changes: 2 additions & 0 deletions src/database/gravity-db.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ bool gravityDB_delFromTable(const enum gravity_list_type listtype, const cJSON*
bool gravityDB_edit_groups(const enum gravity_list_type listtype, cJSON *groups,
const tablerow *row, const char **message);

time_t gravity_last_updated(void) __attribute__((pure));

#endif //GRAVITY_H
Loading