/metrics API
info
Currently, Browserless V2 is available in production via two domains: production-sfo.browserless.io
and production-lon.browserless.io
The metrics API allows you to retrieve an array of session statistics. The data returned will have a maximum date of 1 week.
You can check the full Open API schema here.
Gathering metrics from your workers
To see statistics regarding your workers, simply issue a GET
request to /metrics
:
- cURL
- Javascript
- Python
- Java
- C#
curl -X GET \
https://production-sfo.browserless.io/metrics?token=YOUR_API_TOKEN_HERE
const TOKEN = "YOUR_API_TOKEN_HERE";
const url = `https://production-sfo.browserless.io/metrics?token=${TOKEN}`;
const fetchMetrics = async () => {
const response = await fetch(url, {
method: 'GET'
});
const result = await response.json();
console.log(result);
};
fetchMetrics();
import requests
TOKEN = "YOUR_API_TOKEN_HERE"
url = f"https://production-sfo.browserless.io/metrics?token={TOKEN}"
response = requests.get(url)
result = response.json()
print(result)
import java.io.*;
import java.net.URI;
import java.net.http.*;
public class FetchMetrics {
public static void main(String[] args) {
String TOKEN = "YOUR_API_TOKEN_HERE";
String url = "https://production-sfo.browserless.io/metrics?token=" + TOKEN;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.GET()
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Response: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program {
static async Task Main(string[] args) {
string TOKEN = "YOUR_API_TOKEN_HERE";
string url = $"https://production-sfo.browserless.io/metrics?token={TOKEN}";
using var client = new HttpClient();
try {
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response: " + result);
} catch (Exception ex) {
Console.WriteLine($"Error: {ex.Message}");
}
}
}
warning
Remember that running this in the browser will expose your API key!
Running this request will result in an output like:
[
{
"error": 3,
"maxConcurrent": 4,
"queued": 0,
"rejected": 0,
"running": 3,
"sessionTimes": [992, 1041, 802],
"successful": 0,
"timedout": 0,
"unauthorized": 0,
"unhealthy": 0,
"maxTime": 1041,
"meanTime": 945,
"minTime": 802,
"totalTime": 2835,
"units": 3,
"date": 1709134233732,
"cpu": 0.024877870173220466,
"memory": 0.7784158564199399
},
// ...
]
/metrics/total
This route will output a similar payload, but with the total stats of all sessions.