mirror of https://github.com/TriliumNext/Notes
feat(server/metrics): add documentation around the new metrics endpoint
parent
3479f5016d
commit
ab2f27180d
File diff suppressed because one or more lines are too long
@ -0,0 +1,88 @@
|
|||||||
|
<p> </p>
|
||||||
|
<h1><strong>Trilium Metrics API</strong></h1>
|
||||||
|
<p>The Trilium metrics API provides comprehensive monitoring data about your
|
||||||
|
Trilium instance, designed for external monitoring systems like Prometheus.</p>
|
||||||
|
<h2><strong>Endpoint</strong></h2>
|
||||||
|
<ul>
|
||||||
|
<li><strong>URL</strong>: <code>/etapi/metrics</code>
|
||||||
|
</li>
|
||||||
|
<li><strong>Method</strong>: <code>GET</code>
|
||||||
|
</li>
|
||||||
|
<li><strong>Authentication</strong>: ETAPI token required</li>
|
||||||
|
<li><strong>Default Format</strong>: Prometheus text format</li>
|
||||||
|
</ul>
|
||||||
|
<h2><strong>Authentication</strong></h2>
|
||||||
|
<p>You need an ETAPI token to access the metrics endpoint. Get one by:</p><pre><code class="language-text-x-trilium-auto"># Get an ETAPI token
|
||||||
|
curl -X POST http://localhost:8080/etapi/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"password": "your_password"}'
|
||||||
|
</code></pre>
|
||||||
|
<h2><strong>Usage</strong></h2>
|
||||||
|
<h3><strong>Prometheus Format (Default)</strong></h3><pre><code class="language-text-x-trilium-auto">curl -H "Authorization: YOUR_ETAPI_TOKEN" \
|
||||||
|
http://localhost:8080/etapi/metrics
|
||||||
|
</code></pre>
|
||||||
|
<p>Returns metrics in Prometheus text format:</p><pre><code class="language-text-x-trilium-auto"># HELP trilium_info Trilium instance information
|
||||||
|
# TYPE trilium_info gauge
|
||||||
|
trilium_info{version="0.91.6",db_version="231",node_version="v18.17.0"} 1 1701432000
|
||||||
|
|
||||||
|
# HELP trilium_notes_total Total number of notes including deleted
|
||||||
|
# TYPE trilium_notes_total gauge
|
||||||
|
trilium_notes_total 1234 1701432000
|
||||||
|
</code></pre>
|
||||||
|
<h3><strong>JSON Format</strong></h3><pre><code class="language-text-x-trilium-auto">curl -H "Authorization: YOUR_ETAPI_TOKEN" \
|
||||||
|
"http://localhost:8080/etapi/metrics?format=json"
|
||||||
|
</code></pre>
|
||||||
|
<p>Returns detailed metrics in JSON format for debugging or custom integrations.</p>
|
||||||
|
<h2><strong>Available Metrics</strong></h2>
|
||||||
|
<h3><strong>Instance Information</strong></h3>
|
||||||
|
<ul>
|
||||||
|
<li><code>trilium_info</code> - Version and build information with labels</li>
|
||||||
|
</ul>
|
||||||
|
<h3><strong>Database Metrics</strong></h3>
|
||||||
|
<ul>
|
||||||
|
<li><code>trilium_notes_total</code> - Total notes (including deleted)</li>
|
||||||
|
<li><code>trilium_notes_deleted</code> - Number of deleted notes</li>
|
||||||
|
<li><code>trilium_notes_active</code> - Number of active notes</li>
|
||||||
|
<li><code>trilium_notes_protected</code> - Number of protected notes</li>
|
||||||
|
<li><code>trilium_attachments_total</code> - Total attachments</li>
|
||||||
|
<li><code>trilium_attachments_active</code> - Active attachments</li>
|
||||||
|
<li><code>trilium_revisions_total</code> - Total note revisions</li>
|
||||||
|
<li><code>trilium_branches_total</code> - Active branches</li>
|
||||||
|
<li><code>trilium_attributes_total</code> - Active attributes</li>
|
||||||
|
<li><code>trilium_blobs_total</code> - Total blob records</li>
|
||||||
|
<li><code>trilium_etapi_tokens_total</code> - Active ETAPI tokens</li>
|
||||||
|
<li><code>trilium_embeddings_total</code> - Note embeddings (if available)</li>
|
||||||
|
</ul>
|
||||||
|
<h3><strong>Categorized Metrics</strong></h3>
|
||||||
|
<ul>
|
||||||
|
<li><code>trilium_notes_by_type{type="text|code|image|file"}</code> - Notes
|
||||||
|
by type</li>
|
||||||
|
<li><code>trilium_attachments_by_type{mime_type="..."}</code> - Attachments
|
||||||
|
by MIME type</li>
|
||||||
|
</ul>
|
||||||
|
<h3><strong>Statistics</strong></h3>
|
||||||
|
<ul>
|
||||||
|
<li><code>trilium_database_size_bytes</code> - Database size in bytes</li>
|
||||||
|
<li><code>trilium_oldest_note_timestamp</code> - Timestamp of oldest note</li>
|
||||||
|
<li><code>trilium_newest_note_timestamp</code> - Timestamp of newest note</li>
|
||||||
|
<li><code>trilium_last_modified_timestamp</code> - Last modification timestamp</li>
|
||||||
|
</ul>
|
||||||
|
<h2><strong>Prometheus Configuration</strong></h2>
|
||||||
|
<p>Add to your <code>prometheus.yml</code>:</p><pre><code class="language-text-x-trilium-auto">scrape_configs:
|
||||||
|
- job_name: 'trilium'
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost:8080']
|
||||||
|
metrics_path: '/etapi/metrics'
|
||||||
|
headers:
|
||||||
|
Authorization: 'YOUR_ETAPI_TOKEN'
|
||||||
|
scrape_interval: 30s
|
||||||
|
</code></pre>
|
||||||
|
<h2><strong>Error Responses</strong></h2>
|
||||||
|
<ul>
|
||||||
|
<li><code>400</code> - Invalid format parameter</li>
|
||||||
|
<li><code>401</code> - Missing or invalid ETAPI token</li>
|
||||||
|
<li><code>500</code> - Internal server error</li>
|
||||||
|
</ul>
|
||||||
|
<p> </p>
|
||||||
|
<p> </p>
|
||||||
|
<p> </p>
|
||||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,110 @@
|
|||||||
|
# **Trilium Metrics API**
|
||||||
|
|
||||||
|
The Trilium metrics API provides comprehensive monitoring data about your Trilium instance, designed for external monitoring systems like Prometheus.
|
||||||
|
|
||||||
|
## **Endpoint**
|
||||||
|
|
||||||
|
* **URL**: `/etapi/metrics`
|
||||||
|
* **Method**: `GET`
|
||||||
|
* **Authentication**: ETAPI token required
|
||||||
|
* **Default Format**: Prometheus text format
|
||||||
|
|
||||||
|
## **Authentication**
|
||||||
|
|
||||||
|
You need an ETAPI token to access the metrics endpoint. Get one by:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Get an ETAPI token
|
||||||
|
curl -X POST http://localhost:8080/etapi/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"password": "your_password"}'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## **Usage**
|
||||||
|
|
||||||
|
### **Prometheus Format (Default)**
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -H "Authorization: YOUR_ETAPI_TOKEN" \
|
||||||
|
http://localhost:8080/etapi/metrics
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns metrics in Prometheus text format:
|
||||||
|
|
||||||
|
```
|
||||||
|
# HELP trilium_info Trilium instance information
|
||||||
|
# TYPE trilium_info gauge
|
||||||
|
trilium_info{version="0.91.6",db_version="231",node_version="v18.17.0"} 1 1701432000
|
||||||
|
|
||||||
|
# HELP trilium_notes_total Total number of notes including deleted
|
||||||
|
# TYPE trilium_notes_total gauge
|
||||||
|
trilium_notes_total 1234 1701432000
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### **JSON Format**
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -H "Authorization: YOUR_ETAPI_TOKEN" \
|
||||||
|
"http://localhost:8080/etapi/metrics?format=json"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns detailed metrics in JSON format for debugging or custom integrations.
|
||||||
|
|
||||||
|
## **Available Metrics**
|
||||||
|
|
||||||
|
### **Instance Information**
|
||||||
|
|
||||||
|
* `trilium_info` - Version and build information with labels
|
||||||
|
|
||||||
|
### **Database Metrics**
|
||||||
|
|
||||||
|
* `trilium_notes_total` - Total notes (including deleted)
|
||||||
|
* `trilium_notes_deleted` - Number of deleted notes
|
||||||
|
* `trilium_notes_active` - Number of active notes
|
||||||
|
* `trilium_notes_protected` - Number of protected notes
|
||||||
|
* `trilium_attachments_total` - Total attachments
|
||||||
|
* `trilium_attachments_active` - Active attachments
|
||||||
|
* `trilium_revisions_total` - Total note revisions
|
||||||
|
* `trilium_branches_total` - Active branches
|
||||||
|
* `trilium_attributes_total` - Active attributes
|
||||||
|
* `trilium_blobs_total` - Total blob records
|
||||||
|
* `trilium_etapi_tokens_total` - Active ETAPI tokens
|
||||||
|
* `trilium_embeddings_total` - Note embeddings (if available)
|
||||||
|
|
||||||
|
### **Categorized Metrics**
|
||||||
|
|
||||||
|
* `trilium_notes_by_type{type="text|code|image|file"}` - Notes by type
|
||||||
|
* `trilium_attachments_by_type{mime_type="..."}` - Attachments by MIME type
|
||||||
|
|
||||||
|
### **Statistics**
|
||||||
|
|
||||||
|
* `trilium_database_size_bytes` - Database size in bytes
|
||||||
|
* `trilium_oldest_note_timestamp` - Timestamp of oldest note
|
||||||
|
* `trilium_newest_note_timestamp` - Timestamp of newest note
|
||||||
|
* `trilium_last_modified_timestamp` - Last modification timestamp
|
||||||
|
|
||||||
|
## **Prometheus Configuration**
|
||||||
|
|
||||||
|
Add to your `prometheus.yml`:
|
||||||
|
|
||||||
|
```
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: 'trilium'
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost:8080']
|
||||||
|
metrics_path: '/etapi/metrics'
|
||||||
|
headers:
|
||||||
|
Authorization: 'YOUR_ETAPI_TOKEN'
|
||||||
|
scrape_interval: 30s
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## **Error Responses**
|
||||||
|
|
||||||
|
* `400` - Invalid format parameter
|
||||||
|
* `401` - Missing or invalid ETAPI token
|
||||||
|
* `500` - Internal server error
|
||||||
Loading…
Reference in New Issue