- Notifications
You must be signed in to change notification settings - Fork165
1st version - need review#1369
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
104 changes: 104 additions & 0 deletions_docs/kb/articles/retrieve-usage-data-api.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| --- | ||
| title: "How To: Retrieve Usage Data via the Analytics API" | ||
| description: | ||
| group: kb | ||
| sub-group: articles | ||
| toc: true | ||
| kb: false | ||
| ht: true | ||
| common: false | ||
| categories: [API] | ||
| support-reviewed: | ||
| --- | ||
| ## Overview | ||
| This guide shows how to programmatically access usage-related analytics through the **Codefresh Analytics API**. You'll learn the key endpoints, available reports, supported query parameters, and see a script you can adapt for your own reporting needs. | ||
| > **Goal:** Pull usage metrics (e.g., credit consumption, pipeline credit consumption, active committers) for monitoring or reporting. | ||
| ## Prerequisites | ||
| - A Codefresh **API key** with permission to access Analytics. | ||
| - Date range values in `YYYY-MM-DD` format for queries. | ||
| - Optional: `jq` for pretty-printing JSON responses when using shell examples. | ||
| ## Details | ||
| ### Endpoints | ||
| **Reports** | ||
| ``` | ||
| GET https://g.codefresh.io/api/analytics/reports/{reportName} | ||
| ``` | ||
| Replace `{reportName}` with the specific report you want to query. Examples: | ||
| ``` | ||
| GET https://g.codefresh.io/api/analytics/reports/creditConsumption | ||
| GET https://g.codefresh.io/api/analytics/reports/pipelineCreditConsumption | ||
| GET https://g.codefresh.io/api/analytics/reports/activeCommiters | ||
| ``` | ||
| **Discover reports and parameters** | ||
| ``` | ||
| GET https://g.codefresh.io/api/analytics/metadata | ||
| ``` | ||
| > **Notes** | ||
| > - Not all reports and query parameters are publicly documented. | ||
| > - Different reports support different time ranges and granularities. | ||
| > - Use the **metadata** endpoint to discover available reports and their parameters. | ||
| ### Query parameters & time dimensions | ||
| **creditConsumption** and **pipelineCreditConsumption** support: | ||
| - **No granularity (aggregated):** 1 day – 1 year | ||
| `?dateRange=YYYY-MM-DD&dateRange=YYYY-MM-DD` | ||
| - **Monthly granularity:** 1 day – 1 year | ||
| `?granularity=month&dateRange=YYYY-MM-DD&dateRange=YYYY-MM-DD` | ||
| - **Daily granularity:** 2 days – 45 days | ||
| `?granularity=day&dateRange=YYYY-MM-DD&dateRange=YYYY-MM-DD` | ||
| **activeCommiters** supports: | ||
| - **Monthly granularity:** 3 months – 1 year | ||
| `?granularity=month&dateRange=YYYY-MM-DD&dateRange=YYYY-MM-DD` | ||
| ### Examples | ||
| **Credit consumption (monthly)** | ||
| ``` | ||
| curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/creditConsumption?granularity=month&dateRange=${START_DATE}&dateRange=${END_DATE}" | jq . | ||
| ``` | ||
| **Pipeline credit consumption (daily within 45 days)** | ||
| ``` | ||
| curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/pipelineCreditConsumption?granularity=day&dateRange=${START_DATE}&dateRange=${END_DATE}" | jq . | ||
| ``` | ||
| **Active committers (monthly)** | ||
| ``` | ||
| curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/activeCommiters?granularity=month&dateRange=${START_DATE}&dateRange=${END_DATE}" | jq . | ||
| ``` | ||
| ### Suggested script | ||
| ``` | ||
| #!/bin/bash | ||
| # Expects these env vars: | ||
| # API_KEY -> Codefresh API key | ||
| # START_DATE -> "YYYY-MM-DD" | ||
| # END_DATE -> "YYYY-MM-DD" | ||
| : "${API_KEY:?Set API_KEY}" | ||
| : "${START_DATE:?Set START_DATE}" | ||
| : "${END_DATE:?Set END_DATE}" | ||
| # Example: fetch credit consumption (monthly) | ||
| curl -s -H "Authorization: $API_KEY" "https://g.codefresh.io/api/analytics/reports/creditConsumption?granularity=month&dateRange=${START_DATE}&dateRange=${END_DATE}" | jq . | ||
| # Adapt the endpoint for pipelineCreditConsumption or activeCommiters as needed. | ||
| ``` | ||
| ## Best practices | ||
| - Use the **metadata** endpoint to confirm available reports and supported query parameters. | ||
| - Select a date range and **granularity** appropriate for your reporting needs. | ||
| - Automate data collection (cron, pipeline) to regularly sync usage data into your BI/monitoring systems. |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.