1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
---
stage: Monitor
group: Analytics Instrumentation
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://handbook.gitlab.com/handbook/product/ux/technical-writing/#assignments
---
# Service Ping API
DETAILS:
**Tier:** Free, Premium, Ultimate
**Offering:** Self-managed, GitLab Dedicated
The Service Ping API is associated with [Service Ping](../development/internal_analytics/service_ping/index.md).
## Export Service Ping data
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/141446) in GitLab 16.9.
Requires a personal access token with `read_service_ping` scope.
Returns the JSON payload collected in Service Ping. If no payload data is available in the application cache, it returns empty response.
If payload data is empty, make sure the [Service Ping feature is enabled](../administration/settings/usage_statistics.md#enable-or-disable-service-ping) and
wait for the cron job to be executed, or [generate payload data manually](../development/internal_analytics/service_ping/troubleshooting.md#generate-service-ping).
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/usage_data/service_ping"
```
Example response:
```json
"recorded_at": "2024-01-15T23:33:50.387Z",
"license": {},
"counts": {
"assignee_lists": 0,
"ci_builds": 463,
"ci_external_pipelines": 0,
"ci_pipeline_config_auto_devops": 0,
"ci_pipeline_config_repository": 0,
"ci_triggers": 0,
"ci_pipeline_schedules": 0
...
```
## Export metric definitions as a single YAML file
Export all metric definitions as a single YAML file, similar to the [Metrics Dictionary](https://metrics.gitlab.com/), for easier importing.
```plaintext
GET /usage_data/metric_definitions
```
Example request:
```shell
curl "https://gitlab.example.com/api/v4/usage_data/metric_definitions"
```
Example response:
```yaml
---
- key_path: redis_hll_counters.search.i_search_paid_monthly
description: Calculated unique users to perform a search with a paid license enabled
by month
product_group: global_search
value_type: number
status: active
time_frame: 28d
data_source: redis_hll
distribution:
- ee
tier:
- premium
- ultimate
...
```
## Export Service Ping SQL queries
This action is behind the `usage_data_queries_api` feature flag and is available only for the GitLab instance [Administrator](../user/permissions.md) users.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57016) in GitLab 13.11.
> - [Deployed behind a feature flag](../user/feature_flags.md) named `usage_data_queries_api`, disabled by default.
Return all of the raw SQL queries used to compute Service Ping.
```plaintext
GET /usage_data/queries
```
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/usage_data/queries"
```
Example response:
```json
{
"recorded_at": "2021-03-23T06:31:21.267Z",
"uuid": null,
"hostname": "localhost",
"version": "13.11.0-pre",
"installation_type": "gitlab-development-kit",
"active_user_count": "SELECT COUNT(\"users\".\"id\") FROM \"users\" WHERE (\"users\".\"state\" IN ('active')) AND (\"users\".\"user_type\" IS NULL OR \"users\".\"user_type\" IN (NULL, 6, 4))",
"edition": "EE",
"license_md5": "c701acc03844c45366dd175ef7a4e19c",
"license_sha256": "366dd175ef7a4e19cc701acc03844c45366dd175ef7a4e19cc701acc03844c45",
"license_id": null,
"historical_max_users": 0,
"licensee": {
"Name": "John Doe1"
},
"license_user_count": null,
"license_starts_at": "1970-01-01",
"license_expires_at": "2022-02-23",
"license_plan": "starter",
"license_add_ons": {
"GitLab_FileLocks": 1,
"GitLab_Auditor_User": 1
},
"license_trial": null,
"license_subscription_id": "0000",
"license": {},
"settings": {
"ldap_encrypted_secrets_enabled": false,
"operating_system": "mac_os_x-11.2.2"
},
"counts": {
"assignee_lists": "SELECT COUNT(\"lists\".\"id\") FROM \"lists\" WHERE \"lists\".\"list_type\" = 3",
"boards": "SELECT COUNT(\"boards\".\"id\") FROM \"boards\"",
"ci_builds": "SELECT COUNT(\"ci_builds\".\"id\") FROM \"ci_builds\" WHERE \"ci_builds\".\"type\" = 'Ci::Build'",
"ci_internal_pipelines": "SELECT COUNT(\"ci_pipelines\".\"id\") FROM \"ci_pipelines\" WHERE (\"ci_pipelines\".\"source\" IN (1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13) OR \"ci_pipelines\".\"source\" IS NULL)",
"ci_external_pipelines": "SELECT COUNT(\"ci_pipelines\".\"id\") FROM \"ci_pipelines\" WHERE \"ci_pipelines\".\"source\" = 6",
"ci_pipeline_config_auto_devops": "SELECT COUNT(\"ci_pipelines\".\"id\") FROM \"ci_pipelines\" WHERE \"ci_pipelines\".\"config_source\" = 2",
"ci_pipeline_config_repository": "SELECT COUNT(\"ci_pipelines\".\"id\") FROM \"ci_pipelines\" WHERE \"ci_pipelines\".\"config_source\" = 1",
"ci_runners": "SELECT COUNT(\"ci_runners\".\"id\") FROM \"ci_runners\"",
...
```
## UsageDataNonSqlMetrics API
This action is behind the `usage_data_non_sql_metrics` feature flag and is available only for the GitLab instance [Administrator](../user/permissions.md) users.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57050) in GitLab 13.11.
> - [Deployed behind a feature flag](../user/feature_flags.md), named `usage_data_non_sql_metrics`, disabled by default.
Return all non-SQL metrics data used in the Service ping.
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/usage_data/non_sql_metrics"
```
Sample response:
```json
{
"recorded_at": "2021-03-26T07:04:03.724Z",
"uuid": null,
"hostname": "localhost",
"version": "13.11.0-pre",
"installation_type": "gitlab-development-kit",
"active_user_count": -3,
"edition": "EE",
"license_md5": "bb8cd0d8a6d9569ff3f70b8927a1f949",
"license_sha256": "366dd175ef7a4e19cc701acc03844c45366dd175ef7a4e19cc701acc03844c45",
"license_id": null,
"historical_max_users": 0,
"licensee": {
"Name": "John Doe1"
},
"license_user_count": null,
"license_starts_at": "1970-01-01",
"license_expires_at": "2022-02-26",
"license_plan": "starter",
"license_add_ons": {
"GitLab_FileLocks": 1,
"GitLab_Auditor_User": 1
},
"license_trial": null,
"license_subscription_id": "0000",
"license": {},
"settings": {
"ldap_encrypted_secrets_enabled": false,
"operating_system": "mac_os_x-11.2.2"
},
...
```
## Events Tracking API
Tracks internal events in GitLab. Requires a personal access token with the `api` or `ai_workflows` scope.
To track events to Snowplow, set the `send_to_snowplow` parameter to `true`.
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--request POST \
--data '{
"event": "mr_name_changed",
"send_to_snowplow": true,
"namespace_id": 1,
"project_id": 1,
"additional_properties": {
"lang": "eng"
}
}' \
"https://gitlab.example.com/api/v4/usage_data/track_event"
```
If multiple events tracking is required, send an array of events to the `/track_events` endpoint:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--request POST \
--data '{
"events": [
{
"event": "mr_name_changed",
"namespace_id": 1,
"project_id": 1,
"additional_properties": {
"lang": "eng"
}
},
{
"event": "mr_name_changed",
"namespace_id": 2,
"project_id": 2,
"additional_properties": {
"lang": "eng"
}
}
]
}' \
"https://gitlab.example.com/api/v4/usage_data/track_events"
```
|