# Scrapfly Documentation

## Table of Contents

### Dashboard

- [Intro](https://scrapfly.io/docs)
- [Project](https://scrapfly.io/docs/project)
- [Account](https://scrapfly.io/docs/account)
- [Workspace & Team](https://scrapfly.io/docs/workspace-and-team)
- [Billing](https://scrapfly.io/docs/billing)

### Products

#### MCP Server

- [Getting Started](https://scrapfly.io/docs/mcp/getting-started)
- [Tools & API Spec](https://scrapfly.io/docs/mcp/tools)
- [Authentication](https://scrapfly.io/docs/mcp/authentication)
- [Examples & Use Cases](https://scrapfly.io/docs/mcp/examples)
- [FAQ](https://scrapfly.io/docs/mcp/faq)
##### Integrations

- [Overview](https://scrapfly.io/docs/mcp/integrations)
- [Claude Desktop](https://scrapfly.io/docs/mcp/integrations/claude-desktop)
- [Claude Code](https://scrapfly.io/docs/mcp/integrations/claude-code)
- [Codex](https://scrapfly.io/docs/mcp/integrations/codex)
- [Gemini CLI](https://scrapfly.io/docs/mcp/integrations/gemini-cli)
- [Antigravity](https://scrapfly.io/docs/mcp/integrations/antigravity)
- [OpenCode](https://scrapfly.io/docs/mcp/integrations/opencode)
- [ChatGPT](https://scrapfly.io/docs/mcp/integrations/chatgpt)
- [Cursor](https://scrapfly.io/docs/mcp/integrations/cursor)
- [Cline](https://scrapfly.io/docs/mcp/integrations/cline)
- [Windsurf](https://scrapfly.io/docs/mcp/integrations/windsurf)
- [Zed](https://scrapfly.io/docs/mcp/integrations/zed)
- [Roo Code](https://scrapfly.io/docs/mcp/integrations/roo-code)
- [VS Code](https://scrapfly.io/docs/mcp/integrations/vscode)
- [LangChain](https://scrapfly.io/docs/mcp/integrations/langchain)
- [LlamaIndex](https://scrapfly.io/docs/mcp/integrations/llamaindex)
- [CrewAI](https://scrapfly.io/docs/mcp/integrations/crewai)
- [OpenAI](https://scrapfly.io/docs/mcp/integrations/openai)
- [n8n](https://scrapfly.io/docs/mcp/integrations/n8n)
- [Make](https://scrapfly.io/docs/mcp/integrations/make)
- [Zapier](https://scrapfly.io/docs/mcp/integrations/zapier)
- [Vapi AI](https://scrapfly.io/docs/mcp/integrations/vapi)
- [Agent Builder](https://scrapfly.io/docs/mcp/integrations/agent-builder)
- [Custom Client](https://scrapfly.io/docs/mcp/integrations/custom-client)


#### Web Scraping API

- [Getting Started](https://scrapfly.io/docs/scrape-api/getting-started)
- [API Specification]()
- [Monitoring](https://scrapfly.io/docs/monitoring)
- [Monitoring - Prometheus Metrics](https://scrapfly.io/docs/monitoring/prometheus)
- [Customize Request](https://scrapfly.io/docs/scrape-api/custom)
- [Debug](https://scrapfly.io/docs/scrape-api/debug)
- [Unblocker (formerly ASP)](https://scrapfly.io/docs/scrape-api/unblocker)
- [Proxy](https://scrapfly.io/docs/scrape-api/proxy)
- [Proxy Mode](https://scrapfly.io/docs/scrape-api/proxy-mode)
- [Proxy Mode - Screaming Frog](https://scrapfly.io/docs/scrape-api/proxy-mode/screaming-frog)
- [Proxy Mode - Apify](https://scrapfly.io/docs/scrape-api/proxy-mode/apify)
- [(Auto) Data Extraction](https://scrapfly.io/docs/scrape-api/extraction)
- [Javascript Rendering](https://scrapfly.io/docs/scrape-api/javascript-rendering)
- [Javascript Scenario](https://scrapfly.io/docs/scrape-api/javascript-scenario)
- [SSL](https://scrapfly.io/docs/scrape-api/ssl)
- [DNS](https://scrapfly.io/docs/scrape-api/dns)
- [Cache](https://scrapfly.io/docs/scrape-api/cache)
- [Batch (Multi-URL Scraping)](https://scrapfly.io/docs/scrape-api/batch)
- [Session](https://scrapfly.io/docs/scrape-api/session)
- [Webhook](https://scrapfly.io/docs/scrape-api/webhook)
- [Schedule](https://scrapfly.io/docs/scrape-api/schedule)
- [Screenshot](https://scrapfly.io/docs/scrape-api/screenshot)
- [Errors](https://scrapfly.io/docs/scrape-api/errors)
- [Timeout](https://scrapfly.io/docs/scrape-api/understand-timeout)
- [Throttling](https://scrapfly.io/docs/throttling)
- [Troubleshoot](https://scrapfly.io/docs/scrape-api/troubleshoot)
- [Billing](https://scrapfly.io/docs/scrape-api/billing)
- [FAQ](https://scrapfly.io/docs/scrape-api/faq)

#### Crawler API

- [Getting Started](https://scrapfly.io/docs/crawler-api/getting-started)
- [API Specification]()
- [Retrieving Results](https://scrapfly.io/docs/crawler-api/results)
- [WARC Format](https://scrapfly.io/docs/crawler-api/warc-format)
- [Data Extraction](https://scrapfly.io/docs/crawler-api/extraction-rules)
- [Search](https://scrapfly.io/docs/crawler-api/search)
- [Prompt & Extract](https://scrapfly.io/docs/crawler-api/prompt)
- [Auto Refresh](https://scrapfly.io/docs/crawler-api/refresh)
- [Webhook](https://scrapfly.io/docs/crawler-api/webhook)
- [Schedule](https://scrapfly.io/docs/crawler-api/schedule)
- [Billing](https://scrapfly.io/docs/crawler-api/billing)
- [Errors](https://scrapfly.io/docs/crawler-api/errors)
- [Troubleshoot](https://scrapfly.io/docs/crawler-api/troubleshoot)
- [FAQ](https://scrapfly.io/docs/crawler-api/faq)

#### Screenshot API

- [Getting Started](https://scrapfly.io/docs/screenshot-api/getting-started)
- [API Specification]()
- [Accessibility Testing](https://scrapfly.io/docs/screenshot-api/accessibility)
- [Webhook](https://scrapfly.io/docs/screenshot-api/webhook)
- [Schedule](https://scrapfly.io/docs/screenshot-api/schedule)
- [Billing](https://scrapfly.io/docs/screenshot-api/billing)
- [Errors](https://scrapfly.io/docs/screenshot-api/errors)

#### Extraction API

- [Getting Started](https://scrapfly.io/docs/extraction-api/getting-started)
- [API Specification]()
- [Rules Template](https://scrapfly.io/docs/extraction-api/rules-and-template)
- [LLM Extraction](https://scrapfly.io/docs/extraction-api/llm-prompt)
- [AI Auto Extraction](https://scrapfly.io/docs/extraction-api/automatic-ai)
- [Webhook](https://scrapfly.io/docs/extraction-api/webhook)
- [Billing](https://scrapfly.io/docs/extraction-api/billing)
- [Errors](https://scrapfly.io/docs/extraction-api/errors)
- [FAQ](https://scrapfly.io/docs/extraction-api/faq)

#### Data API


#### Proxy Saver

- [Getting Started](https://scrapfly.io/docs/proxy-saver/getting-started)
- [Fingerprints](https://scrapfly.io/docs/proxy-saver/fingerprints)
- [Optimizations](https://scrapfly.io/docs/proxy-saver/optimizations)
- [SSL Certificates](https://scrapfly.io/docs/proxy-saver/certificates)
- [Protocols](https://scrapfly.io/docs/proxy-saver/protocols)
- [Pacfile](https://scrapfly.io/docs/proxy-saver/pacfile)
- [Secure Credentials](https://scrapfly.io/docs/proxy-saver/security)
- [Billing](https://scrapfly.io/docs/proxy-saver/billing)

#### Cloud Browser API

- [Getting Started](https://scrapfly.io/docs/cloud-browser-api/getting-started)
- [Proxy & Geo-Targeting](https://scrapfly.io/docs/cloud-browser-api/proxy)
- [Unblock API](https://scrapfly.io/docs/cloud-browser-api/unblock)
- [Captcha Solver](https://scrapfly.io/docs/cloud-browser-api/captcha-solver)
- [Network Policy](https://scrapfly.io/docs/cloud-browser-api/network-policy)
- [File Downloads](https://scrapfly.io/docs/cloud-browser-api/file-downloads)
- [Session Resume](https://scrapfly.io/docs/cloud-browser-api/session-resume)
- [Human-in-the-Loop](https://scrapfly.io/docs/cloud-browser-api/human-in-the-loop)
- [Debug Mode](https://scrapfly.io/docs/cloud-browser-api/debug-mode)
- [Browser Extensions](https://scrapfly.io/docs/cloud-browser-api/extensions)
- [Credential Vault](https://scrapfly.io/docs/cloud-browser-api/credential-vault)
- [Native Browser MCP](https://scrapfly.io/docs/cloud-browser-api/mcp)
- [DevTools Protocol](https://scrapfly.io/docs/cloud-browser-api/cdp-reference)
##### Integrations

- [Puppeteer](https://scrapfly.io/docs/cloud-browser-api/puppeteer)
- [Playwright](https://scrapfly.io/docs/cloud-browser-api/playwright)
- [Selenium](https://scrapfly.io/docs/cloud-browser-api/selenium)
- [Vercel Agent Browser](https://scrapfly.io/docs/cloud-browser-api/agent-browser)
- [Browser Use](https://scrapfly.io/docs/cloud-browser-api/browser-use)
- [Stagehand](https://scrapfly.io/docs/cloud-browser-api/stagehand)
- [1Password](https://scrapfly.io/docs/cloud-browser-api/1password)

- [Billing](https://scrapfly.io/docs/cloud-browser-api/billing)
- [Errors](https://scrapfly.io/docs/cloud-browser-api/errors)


### Tools

- [Antibot Detector](https://scrapfly.io/docs/tools/antibot-detector)

### SDK

- [Golang](https://scrapfly.io/docs/sdk/golang)
- [PHP](https://scrapfly.io/docs/sdk/php)
- [Python](https://scrapfly.io/docs/sdk/python)
- [Rust](https://scrapfly.io/docs/sdk/rust)
- [TypeScript](https://scrapfly.io/docs/sdk/typescript)
- [Scrapy](https://scrapfly.io/docs/sdk/scrapy)

### Integrations

- [Getting Started](https://scrapfly.io/docs/integration/getting-started)
- [LangChain](https://scrapfly.io/docs/integration/langchain)
- [LlamaIndex](https://scrapfly.io/docs/integration/llamaindex)
- [CrewAI](https://scrapfly.io/docs/integration/crewai)
- [Zapier](https://scrapfly.io/docs/integration/zapier)
- [Make](https://scrapfly.io/docs/integration/make)
- [n8n](https://scrapfly.io/docs/integration/n8n)

### Academy

- [Overview](https://scrapfly.io/academy)
- [Web Scraping Overview](https://scrapfly.io/academy/scraping-overview)
- [Tools](https://scrapfly.io/academy/tools-overview)
- [Reverse Engineering](https://scrapfly.io/academy/reverse-engineering)
- [Static Scraping](https://scrapfly.io/academy/static-scraping)
- [HTML Parsing](https://scrapfly.io/academy/html-parsing)
- [Dynamic Scraping](https://scrapfly.io/academy/dynamic-scraping)
- [Hidden API Scraping](https://scrapfly.io/academy/hidden-api-scraping)
- [Headless Browsers](https://scrapfly.io/academy/headless-browsers)
- [Hidden Web Data](https://scrapfly.io/academy/hidden-web-data)
- [JSON Parsing](https://scrapfly.io/academy/json-parsing)
- [Data Processing](https://scrapfly.io/academy/data-processing)
- [Scaling](https://scrapfly.io/academy/scaling)
- [Walkthrough Summary](https://scrapfly.io/academy/walkthrough-summary)
- [Scraper Blocking](https://scrapfly.io/academy/scraper-blocking)
- [Proxies](https://scrapfly.io/academy/proxies)

---

# Prometheus Metrics

 Scrapfly serves the usage of your account in the Prometheus text format. Point your own Prometheus, Grafana Alloy, VictoriaMetrics or the Prometheus receiver of the OpenTelemetry Collector at `api.scrapfly.io`, then chart and alert on your calls by result and error code, their duration, bandwidth, API credits, quotas and concurrency.

 A collector signs in with a [metrics token](#token), a read-only credential that is not an API key, so no API key goes into a monitoring configuration. Scrapfly does not store a time series for you: each scrape returns the current value of cumulative counters and gauges, and your collector stores them.

> **Enterprise Plan Required**
>
>  Prometheus metrics are available on **Enterprise** and **Custom** plans. Scrapfly checks the plan at every scrape: an account on another plan, or one that leaves the plan, gets `HTTP 402 Payment Required`. See [pricing](https://scrapfly.io/pricing) to upgrade.

## Quick start

1. **Create a metrics token**

     Open [Prometheus metrics](https://scrapfly.io/dashboard/monitoring/prometheus) in your dashboard, press **Create**, choose a name and a scope, and copy the token. Scrapfly shows it once.
2. **Check the token**

    Read the metrics of your account with curl. A valid token prints series, a wrong one answers `401`.

    ```
    curl -s https://api.scrapfly.io/prometheus/metrics \
      -H "Authorization: Bearer YOUR_METRICS_TOKEN" | head -n 12
    ```
3. **Add the scrape job**

     Save the token in a file your collector reads, then add the job of [Prometheus or Grafana Alloy](#scrape-configuration). Once the target is up, the [queries below](#promql) chart your usage.

## Endpoints

Both routes answer `GET` on `https://api.scrapfly.io`.

- `GET /prometheus/metrics` with an account token or a project token: everything the token covers. An account token returns every project of the account, the gauges of each project and the account gauges. A project token returns its project and the gauges of that project, with no account-wide figure.
- `GET /prometheus/projects/{project_id}/metrics` with an account token, or the token of that project: one project. `project_id` is the UUID of the project. The [Prometheus metrics](https://scrapfly.io/dashboard/monitoring/prometheus) page lists the route of each project. A project the token does not cover answers `404`.

 Send the token in the `Authorization` header, `Authorization: Bearer YOUR_METRICS_TOKEN`, which Prometheus sends from `authorization.credentials` or `credentials_file`. Scrapfly does not read a token in the query string and answers `401`: a URL lands in access logs and on the targets page of your collector. An API key gets the same answer.

 A `200` answers `Content-Type: text/plain; version=0.0.4; charset=utf-8`. When the `Accept-Encoding` header of your collector allows gzip, as the one of Prometheus does, the body is compressed and the answer carries `Content-Encoding: gzip`. Otherwise the body is plain text. The samples carry no timestamp: your collector stamps each one at its scrape.

## The metrics token

 A metrics token reads the figures of the two routes above and nothing else. It cannot scrape, spend API credits, read logs or change a setting. It is not an API key and the routes refuse an API key.

- **Format**: `scp-metrics-` followed by 64 lowercase hexadecimal characters. An API key starts with `scp-live-` or `scp-test-`.
- **Scope**: an *account* token covers every project of the account, the projects you create later too. A *project* token covers one project.
- **Shown once**: copy the token when you create it. Scrapfly keeps a one-way hash of it, so it cannot show it again. The page lists each token with its name, scope, last four characters, creation date and last use.
- **Who manages tokens**: the owner of the account and the [team members](https://scrapfly.io/docs/workspace-and-team) with the Manager or Admin role create and revoke tokens. A member limited to some projects creates tokens for those projects only, never an account token.
- **Domains and tags**: a token created with *Show the domains and the tags of the calls* also reads the calls by target domain and by tag ([Dimensions](#dimensions)). They say which websites the account scrapes: leave it off for a token you share. The page shows the choice on each token.
- **Limit**: an account holds 20 metrics tokens at most.
- **Last use**: the page shows when each token was last used, updated at most once an hour, so that you revoke a token nobody uses.
- **Revocation**: a revoked token answers `401` within 60 seconds. A token is also deleted with its project and with your account.
- **Authorized IPs**: the [Authorized IP address or CIDR](https://scrapfly.io/docs/project#authorized-ips) list of a project applies to API keys. A metrics token is not held to it.

## Scrape configuration

 Save the token alone in a file, with no trailing newline, and make the file readable only by the user that runs your collector.

```
printf "%s" "YOUR_METRICS_TOKEN" > /etc/prometheus/secrets/scrapfly-metrics-token
```

   Prometheus   Grafana Alloy

Add the job to `scrape_configs` in `prometheus.yml`:

```
scrape_configs:
  - job_name: scrapfly
    scheme: https
    metrics_path: /prometheus/metrics
    scrape_interval: 60s
    scrape_timeout: 15s
    authorization:
      type: Bearer
      credentials_file: /etc/prometheus/secrets/scrapfly-metrics-token
    static_configs:
      - targets: ["api.scrapfly.io"]
```

 VictoriaMetrics reads the same `scrape_configs` in the configuration file of `vmagent`, and the Prometheus receiver of the OpenTelemetry Collector takes them under `config`.

 Read the token with `local.file`, which reads the file again when it changes, and add a `prometheus.scrape` component. `prometheus.remote_write.default` stands for your own `prometheus.remote_write` component.

```
local.file "scrapfly_metrics_token" {
  filename  = "/etc/alloy/secrets/scrapfly-metrics-token"
  is_secret = true
}

prometheus.scrape "scrapfly" {
  targets         = [{"__address__" = "api.scrapfly.io:443"}]
  forward_to      = [prometheus.remote_write.default.receiver]
  job_name        = "scrapfly"
  scheme          = "https"
  metrics_path    = "/prometheus/metrics"
  scrape_interval = "60s"
  scrape_timeout  = "15s"

  authorization {
    type        = "Bearer"
    credentials = local.file.scrapfly_metrics_token.content
  }
}
```

### One project

 To scrape one project, change the path to `/prometheus/projects/PROJECT_ID/metrics`. The [Prometheus metrics](https://scrapfly.io/dashboard/monitoring/prometheus) page lists the route of each project, with its configuration to copy. Use a project token, or an account token to scrape several projects with one job each. Each job needs a name of its own in `scrape_configs`: the page names a project's job `scrapfly-project-PROJECT_ID`.

### Scrape interval

 Scrapfly refreshes the figures of a scope at most every 15 seconds. A `scrape_interval` shorter than that reads the same snapshot twice. Use `60s`: the call counters move with a delay of about a minute anyway, see [Freshness](#freshness).

## Metrics

 Every metric starts with `scrapfly_`. A series exists only for a combination that saw traffic. No label holds a URL, a host, an IP address or a request ID.

### Labels

| Label | Values |
|---|---|
| `project` | The name of your project. A renamed project starts new series under its new name, and a deleted project no longer appears. |
| `env` | `live` or `test`, the environment of the API key of the call. |
| `product` | The product that served the call or spent the API credits: `web_scraping_api`, `screenshot_api`, `crawler_api`, `extraction_api`, `cloud_browser`, `data_api` or `rpa`. The calls sent from the dashboard players, by the scheduler, by the [spider](https://scrapfly.io/docs/spider) and by webhook deliveries count as `web_scraping_api`, like the calls of the Web Scraping API itself. A call from any other origin carries the name of that origin in lower case. |
| `result` | `success`: the call succeeded.  `blocked`: the website refused the call, with a status code 403, 428, 429, 444, 499, 503 or 999, or an `ERR::ASP` error code. It is the `blocked` filter of the [monitoring logs](https://scrapfly.io/docs/monitoring#api-logs-export-filters).  `failure`: any other call that did not succeed. |
| `error_code` | The [error code](https://scrapfly.io/docs/scrape-api/errors) of the call, on `scrapfly_request_errors_total` only. |
| `le` | The upper bound of a duration bucket, in seconds, on `scrapfly_request_duration_seconds_bucket` and `scrapfly_browser_session_duration_seconds_bucket` only. |

### Counters

 The request counters hold the calls of the Web Scraping API, the Screenshot API and the Crawler API, and the webhook deliveries: the calls your monitoring dashboard lists. They do not cover Extraction API calls, whose API credits are in `scrapfly_api_credits_spent_total`, nor Cloud Browser sessions, which have [counters of their own](#cloud-browser).

| Metric | Meaning |
|---|---|
| `scrapfly_requests_total` | Counter. API calls, by result. Labels: `project`, `env`, `product`, `result`. |
| `scrapfly_request_errors_total` | Counter. The calls that did not succeed, by error code. Labels: `project`, `env`, `product`, `error_code`. |
| `scrapfly_request_duration_seconds` | Histogram. The duration of the calls, in seconds, with its `_bucket`, `_sum` and `_count` series. Labels: `project`, `env`, `product`. |
| `scrapfly_bandwidth_bytes_total` | Counter. The bandwidth of the calls, in bytes, as the dashboard shows it. Labels: `project`, `env`, `product`. |
| `scrapfly_api_credits_spent_total` | Counter. The API credits spent, for every product, Cloud Browser and Extraction API included. Labels: `project`, `env`, `product`. |
| `scrapfly_captcha_api_credits_spent_total` | Counter. The part of those API credits spent on captchas, already counted in `scrapfly_api_credits_spent_total`. Labels: `project`, `env`. |
| `scrapfly_request_retries_total` | Counter. The retries Scrapfly made for the calls. Labels: `project`, `env`, `product`. |

### Dimensions

 The filters of your monitoring dashboard are counters too, one metric per filter, each with the labels `project`, `env`, `product` and `result` beside its own. A panel filters on one of them at a time.

| Metric | Its label |
|---|---|
| `scrapfly_requests_by_status_code_total` | `status_code`: the HTTP status the website answered, `none` when it answered none, `other` for a code outside 100 to 599 and 999. |
| `scrapfly_requests_by_method_total` | `method`: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS`. |
| `scrapfly_requests_by_country_total` | `country`: the country of the proxy, two lowercase letters, `none` when the call had no proxy country, `other` for a value that is not two letters. |
| `scrapfly_requests_by_proxy_pool_total` | `proxy_pool`: a public pool by its name (`public_datacenter_pool`, `public_residential_pool`), `custom` for your own proxy, `none`. |
| `scrapfly_requests_by_domain_total` | `domain`: the registered domain of the target (`example.com` for `shop.example.com`). A token made to show domains and tags only, and the 25 domains with the most calls over the last 7 days. |
| `scrapfly_requests_by_tag_total` | `tag`: a tag of the call, its first 64 characters. A call with several tags counts under each. A token made to show domains and tags only, and the 25 tags with the most calls over the last 7 days. |

 A domain or a tag outside the 25 has no series, and none is summed into an *other*: when a value enters the 25, its series starts with its count so far. The totals stay in `scrapfly_requests_total`. The URL and the correlation id of a call are never labels: there is one per call.

### Duration buckets

 The upper bounds of `scrapfly_request_duration_seconds`, in seconds, are 0.25, 0.5, 1, 2.5, 5, 10, 15, 30, 60, 90, 120, 150 and `+Inf`. The buckets are cumulative, as Prometheus defines them: a call of 3 seconds counts in the buckets from 5 up. A call longer than the last bound counts in `+Inf` only.

### Cloud Browser sessions

 A session is counted when it ends, within a minute, like the sessions of the [Cloud Browser monitoring page](https://scrapfly.io/docs/cloud-browser-api/monitoring). A session is counted once, however many times its client reconnected to it; a refused connection, a reconnection included, is a `not_started` session of its own.

| Metric | Meaning |
|---|---|
| `scrapfly_browser_sessions_total` | Counter. Sessions, by result. Labels: `project`, `env`, `result`. |
| `scrapfly_browser_session_errors_total` | Counter. The sessions that did not succeed, by error code. Labels: `project`, `env`, `error_code`. |
| `scrapfly_browser_session_duration_seconds` | Histogram. How long the sessions that started lasted, with `_sum` and `_count`. Labels: `project`, `env`. |
| `scrapfly_browser_sessions_active` | Gauge. The sessions running now, with any token, one series per project and environment the token covers. Labels: `project`, `env`. |

- `result` is `success`, `failure`, or `not_started`: a connection refused before its session began, such as a configuration error, a concurrency limit or no browser available. It is not billed and has no duration.
- `error_code` is the [error code](https://scrapfly.io/docs/cloud-browser-api/errors) a `not_started` connection was refused under, or `other` for any other end: a `not_started` connection whose upgrade or browser connection failed, or a session that started and then failed (a timeout, a crash, a lost connection). Each session that did not succeed counts under one error code.
- The upper bounds of `scrapfly_browser_session_duration_seconds`, in seconds, are 1, 5, 15, 30, 60, 120, 300, 600, 900, 1800 and `+Inf`. A connection lasts 30 minutes at most.

### Gauges

 The account gauges come with an account token only. The project gauges come with any token, one series per project the token covers.

| Metric | Meaning |
|---|---|
| `scrapfly_account_api_credits_used` | API credits used in the current billing period. |
| `scrapfly_account_api_credits_limit` | API credits of your plan for the billing period. |
| `scrapfly_account_api_credits_remaining` | API credits left in the billing period. |
| `scrapfly_account_extra_api_credits_used` | API credits used beyond your plan, with Pay As You Go. |
| `scrapfly_account_extra_usage_allowed` | `1` when your account may use API credits beyond its plan, else `0`. |
| `scrapfly_account_billing_period_start_timestamp_seconds` | The start of the billing period, in Unix seconds. |
| `scrapfly_account_billing_period_end_timestamp_seconds` | The end of the billing period, in Unix seconds. |
| `scrapfly_account_concurrency_used` | The calls in flight for your account, as Scrapfly counts them to apply your concurrency limit. |
| `scrapfly_account_concurrency_limit` | The calls your account may have in flight. |
| `scrapfly_account_concurrency_used_by_product` | The calls in flight for your account, by product. Label: `product`. |
| `scrapfly_project_api_credits_used` | The API credits the project used in the billing period. Label: `project`. |
| `scrapfly_project_api_credits_limit` | The API credits the project may use in a billing period. Absent for a project with no limit. Label: `project`. |
| `scrapfly_project_concurrency_used` | The calls in flight for the project. Label: `project`. |
| `scrapfly_project_concurrency_limit` | The calls the project may have in flight. Absent for a project with no limit. Label: `project`. |
| `scrapfly_metrics_snapshot_timestamp_seconds` | When Scrapfly read the figures of this answer, in Unix seconds, with any token. |
| `scrapfly_metrics_series_dropped` | Past 10000 series, an answer leaves out the domain and tag metrics first, then the other [dimensions](#dimensions) with the [Cloud Browser session](#cloud-browser) counters and histogram, and this gauge says how many series it left out: 0 almost always. The other metrics, `scrapfly_browser_sessions_active` among them, are never left out. |

 `time() - scrapfly_metrics_snapshot_timestamp_seconds` is the age of the figures of an answer, in seconds.

### Counters are cumulative

 A counter adds up the calls Scrapfly logged while the account held a metrics token: it starts with the first token, pauses while the account holds none, and goes on from its last value with the next one. Older calls are not added, so the absolute value means little: read a counter with `rate()` or `increase()`. A counter never goes down. It does not reset at a new billing period, when Scrapfly deploys, or when a log is deleted at the end of its retention.

## Freshness

 A call shows in the request counters, the errors, the duration and the bandwidth one to two minutes after it ends. Its API credits show sooner, about 30 seconds after Scrapfly bills the call. On top of that, each answer is up to 15 seconds old: Scrapfly keeps the figures of a scope and serves them while they are younger than 15 seconds, then reads them again for the next scrape. The gauges are part of the figures and as old as they are.

 A counter that one collector reads never goes down from one scrape to the next, so `increase()` stays right. Scrape every `60s` and chart ranges of five minutes or more.

## Answers and errors

 An error is the JSON error of the API. Prometheus shows its status on the targets page, and the target is down for that scrape.

| Status | When | What to do |
|---|---|---|
| `401` | No `Authorization: Bearer` header, a value that is not a metrics token, an unknown or revoked token, an API key, or a token sent in the query string. | Send the token in the header, and check the file holds the token alone. If you revoked the token, create another one. |
| `402` | The plan of the account is neither Enterprise nor Custom, or the account is suspended because Scrapfly could not charge it. | See [pricing](https://scrapfly.io/pricing): the metrics come back once the account is on an Enterprise or Custom plan. For a suspended account, update your payment method or contact support. |
| `403` | The account is not verified (`Unverified Account`), or it is suspended for a reason other than a failed charge (`Account Suspended`). | Finish the verification of the account in your dashboard, or contact support about a suspension. |
| `404` | The `project_id` is outside the scope of the token, or the project is deleted. Scrapfly answers the same for both. | Copy the route of the project from the [Prometheus metrics](https://scrapfly.io/dashboard/monitoring/prometheus) page. A project token covers its own project only: use an account token to scrape several projects. |
| `503` | Scrapfly could not read your figures. It never answers a page of zeros, which Prometheus would read as counter resets. | Wait for the next scrape, which asks again. If the status stays for several scrapes, contact support. |

## PromQL to start from

 Each query works with an account token or a project token, except the ones that read an account gauge.

### Success rate per project

```
sum by (project) (rate(scrapfly_requests_total{result="success"}[5m]))
  /
sum by (project) (rate(scrapfly_requests_total[5m]))
```

### Block rate per project

```
sum by (project) (rate(scrapfly_requests_total{result="blocked"}[5m]))
  /
sum by (project) (rate(scrapfly_requests_total[5m]))
```

### 95th percentile duration, in seconds

```
histogram_quantile(
  0.95,
  sum by (le, project) (rate(scrapfly_request_duration_seconds_bucket[5m]))
)
```

### API credits per hour, and hours left

The credits spent in the last hour:

```
sum(increase(scrapfly_api_credits_spent_total[1h]))
```

The hours left at that pace, with an account token:

```
scrapfly_account_api_credits_remaining
  / sum(rate(scrapfly_api_credits_spent_total[1h]))
  / 3600
```

### Concurrency saturation

 A value near `1` means calls wait for a free slot. With an account token:

```
scrapfly_account_concurrency_used / scrapfly_account_concurrency_limit
```

For a project, with any token:

```
scrapfly_project_concurrency_used / scrapfly_project_concurrency_limit
```

### Cloud Browser sessions running, and their median duration

```
sum by (project) (scrapfly_browser_sessions_active)
```

```
histogram_quantile(0.5,
  sum by (le, project) (rate(scrapfly_browser_session_duration_seconds_bucket[1h])))
```

### Top error codes

```
topk(5, sum by (error_code) (increase(scrapfly_request_errors_total[1h])))
```

## Rotate or revoke a token

Rotate a token without a gap in your metrics:

1. **Create the new token**

    Create a token with the same scope on the [Prometheus metrics](https://scrapfly.io/dashboard/monitoring/prometheus) page.
2. **Switch your collector**

    Write the new token in the token file of your collector, then check on its targets page that the target is up.
3. **Revoke the old token**

    Press **Revoke** on the old token. It answers `401` within 60 seconds.

 To stop a collector at once, for example after a leak, revoke its token and create another one.

## The deprecated Prometheus format of the Monitoring API

 The `prometheus` value of the `format` parameter of the [Monitoring API](https://scrapfly.io/docs/monitoring#api-metrics) is deprecated. It prints the figures of a time window, such as the billing period or the last 24 hours, which Prometheus cannot take a rate of. Scrape the routes of this page instead.

 Scrapfly marks every answer in the deprecated format with a `Deprecation` header and a `Link` header, `rel="deprecation"`, that points to this page.
