Skip to content

sapi-metrics: update remediation metrics #761

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions crowdsec-docs/unversioned/service_api/quickstart/metrics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,83 @@ print(response.model_dump_json())

</details>

### Get Remediation Metrics by Engine IDs or Tags

:::info
- You can filter the metrics by specifying security engine IDs or tags.
:::


<Tabs
defaultValue="curl"
groupId="service-api-selection"
values={[
{ label: 'cURL', value: 'curl' ,},
{ label: 'Python', value: 'python', },
]
}>
<TabItem value="curl">

```bash
curl -i -H "x-api-key: ${KEY}" -X GET -H "Content-Type: application/json" \
https://admin.api.crowdsec.net/v1/metrics/remediation?start_date=2025-03-19T00:00:00Z&end_date=2025-03-27T00:00:00Z&engine_ids=a1b2c3d4e5f6g7h8i9j0&engine_ids=0j9i8h7g6f5e4d3c2b1a
```

</TabItem>
<TabItem value="python">

```python
import os

KEY = os.getenv('KEY')

from crowdsec_service_api import (
Metrics,
Server,
ApiKeyAuth,
)

auth = ApiKeyAuth(api_key=KEY)

client = Metrics(base_url=Server.production_server.value, auth=auth)
# Get remediation metrics
response = metrics_client.get_metrics_remediation(
start_date=datetime.datetime.now() - datetime.timedelta(days=1),
end_date=datetime.datetime.now(),
engine_ids=["a1b2c3d4e5f6g7h8i9j0", "0j9i8h7g6f5e4d3c2b1a"],
tags=["tag1", "tag2"],
)
print(response.model_dump_json())
```

</TabItem>
</Tabs>

- [Swagger method link](https://admin.api.crowdsec.net/v1/docs#/Metrics/getMetricsRemediation)

<details>
<summary>answer on success</summary>

```json
{
"raw": {
"dropped": [],
"processed": []
},
"computed": {
"saved": {
"log_lines": [],
"storage": [],
"egress_traffic": []
},
"dropped": [],
"prevented": []
}
}
```

</details>

### Metrics definitions

- `raw`: Raw metrics are the metrics that are directly collected from the crowdsec engine.
Expand Down