# Stats

Statistics


## Get instance stats

`GET /api/v1/server/stats`

Get instance public statistics. This endpoint is cached.

Authentication: no security requirement declared for this operation.

Responses:

- 200: successful operation

Content type: application/json

Type: ServerStats

Schema: [ServerStats](https://docs.joinpeertube.org/api-rest-reference/api/models/serverstats.md)

- `totalUsers` (optional)
  Type: number

- `totalDailyActiveUsers` (optional)
  Type: number

- `totalWeeklyActiveUsers` (optional)
  Type: number

- `totalMonthlyActiveUsers` (optional)
  Type: number

- `totalModerators` (optional)
  Type: number
  
  **PeerTube >= 6.1** Value is null if the admin disabled total moderators stats

- `totalAdmins` (optional)
  Type: number
  
  **PeerTube >= 6.1** Value is null if the admin disabled total admins stats

- `totalLocalVideos` (optional)
  Type: number

- `totalLocalVideoViews` (optional)
  Type: number
  
  Total video views made on the instance

- `totalLocalVideoDownloads` (optional)
  Type: number
  
  Total video downloads made on the instance

- `totalLocalVideoComments` (optional)
  Type: number
  
  Total comments made by local users

- `totalLocalVideoFilesSize` (optional)
  Type: number

- `totalVideos` (optional)
  Type: number

- `totalVideoComments` (optional)
  Type: number

- `totalLocalVideoChannels` (optional)
  Type: number

- `totalLocalDailyActiveVideoChannels` (optional)
  Type: number

- `totalLocalWeeklyActiveVideoChannels` (optional)
  Type: number

- `totalLocalMonthlyActiveVideoChannels` (optional)
  Type: number

- `totalLocalPlaylists` (optional)
  Type: number

- `totalInstanceFollowers` (optional)
  Type: number

- `totalInstanceFollowing` (optional)
  Type: number

- `videosRedundancy` (optional)
  Type: Array<object>
  
  Items:
    Type: object
    
    - `strategy` (optional)
      Type: string
    
    - `totalSize` (optional)
      Type: number
    
    - `totalUsed` (optional)
      Type: number
    
    - `totalVideoFiles` (optional)
      Type: number
    
    - `totalVideos` (optional)
      Type: number

- `totalActivityPubMessagesProcessed` (optional)
  Type: number

- `totalActivityPubMessagesSuccesses` (optional)
  Type: number

- `totalActivityPubMessagesErrors` (optional)
  Type: number

- `activityPubMessagesProcessedPerSecond` (optional)
  Type: number

- `totalActivityPubMessagesWaiting` (optional)
  Type: number

- `averageRegistrationRequestResponseTimeMs` (optional)
  Type: number
  
  **PeerTube >= 6.1** Value is null if the admin disabled registration requests stats

- `totalRegistrationRequestsProcessed` (optional)
  Type: number
  
  **PeerTube >= 6.1** Value is null if the admin disabled registration requests stats

- `totalRegistrationRequests` (optional)
  Type: number
  
  **PeerTube >= 6.1** Value is null if the admin disabled registration requests stats

- `averageAbuseResponseTimeMs` (optional)
  Type: number
  
  **PeerTube >= 6.1** Value is null if the admin disabled abuses stats

- `totalAbusesProcessed` (optional)
  Type: number
  
  **PeerTube >= 6.1** Value is null if the admin disabled abuses stats

- `totalAbuses` (optional)
  Type: number
  
  **PeerTube >= 6.1** Value is null if the admin disabled abuses stats

## Examples

### cURL

```bash
curl -X GET 'https://peertube2.cpy.re/api/v1/server/stats'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/server/stats', {
  method: 'GET',
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.get('https://peertube2.cpy.re/api/v1/server/stats')
print(response.text)
```


## Create playback metrics

`POST /api/v1/metrics/playback`

These metrics are exposed by OpenTelemetry metrics exporter if enabled.

Authentication: no security requirement declared for this operation.

Request body: application/json

Type: PlaybackMetricCreate

Schema: [PlaybackMetricCreate](https://docs.joinpeertube.org/api-rest-reference/api/models/playbackmetriccreate.md)

- `playerMode` (required)
  Type: string
  
  enum: ["p2p-media-loader","web-video"]

- `resolution` (optional)
  Type: number
  
  Current player video resolution

- `fps` (optional)
  Type: number
  
  Current player video fps

- `p2pEnabled` (required)
  Type: boolean

- `p2pPeers` (optional)
  Type: number
  
  P2P peers connected (doesn't include WebSeed peers)

- `resolutionChanges` (required)
  Type: number
  
  How many resolution changes occurred since the last metric creation

- `bufferStalled` (optional)
  Type: number
  
  How many times buffer has been stalled since the last metric creation

- `errors` (required)
  Type: number
  
  How many errors occurred since the last metric creation

- `downloadedBytesP2P` (required)
  Type: number
  
  How many bytes were downloaded with P2P since the last metric creation

- `downloadedBytesHTTP` (required)
  Type: number
  
  How many bytes were downloaded with HTTP since the last metric creation

- `uploadedBytesP2P` (required)
  Type: number
  
  How many bytes were uploaded with P2P since the last metric creation

- `videoId` (required)
  Type: id | UUIDv4 | shortUUID
  
  oneOf:
    Reference: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md); Type: id
    
    minimum: 1
    
    Example:
    
    ```json
    42
    ```
  
    Reference: [UUIDv4](https://docs.joinpeertube.org/api-rest-reference/api/models/uuidv4.md); Type: UUIDv4, uuid
    
    minLength: 36
    
    maxLength: 36
    
    pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    
    Example:
    
    ```json
    "9c9de5e8-0a1e-484a-b099-e80766180a6d"
    ```
  
    Reference: [shortUUID](https://docs.joinpeertube.org/api-rest-reference/api/models/shortuuid.md); Type: shortUUID
    
    translation of a uuid v4 with a bigger alphabet to have a shorter uuid
    
    Example:
    
    ```json
    "2y84q2MQUMWPbiEcxNXMgC"
    ```

Responses:

- 204: successful operation

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/metrics/playback' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "playerMode": "p2p-media-loader",
  "resolution": 0,
  "fps": 0,
  "p2pEnabled": true,
  "p2pPeers": 0,
  "resolutionChanges": 0,
  "bufferStalled": 0,
  "errors": 0,
  "downloadedBytesP2P": 0,
  "downloadedBytesHTTP": 0,
  "uploadedBytesP2P": 0,
  "videoId": 42
}'
```

### JavaScript

```javascript
const body = `{
  "playerMode": "p2p-media-loader",
  "resolution": 0,
  "fps": 0,
  "p2pEnabled": true,
  "p2pPeers": 0,
  "resolutionChanges": 0,
  "bufferStalled": 0,
  "errors": 0,
  "downloadedBytesP2P": 0,
  "downloadedBytesHTTP": 0,
  "uploadedBytesP2P": 0,
  "videoId": 42
}`;

const response = await fetch('https://peertube2.cpy.re/api/v1/metrics/playback', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "playerMode": "p2p-media-loader",
  "resolution": 0,
  "fps": 0,
  "p2pEnabled": true,
  "p2pPeers": 0,
  "resolutionChanges": 0,
  "bufferStalled": 0,
  "errors": 0,
  "downloadedBytesP2P": 0,
  "downloadedBytesHTTP": 0,
  "uploadedBytesP2P": 0,
  "videoId": 42
}'''

response = requests.post(
    'https://peertube2.cpy.re/api/v1/metrics/playback',
    data=body.encode('utf-8'),
    headers={
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
