Skip to content

Commit

Permalink
allow using filter_path for /_cat/shards
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasr committed Jul 14, 2023
1 parent 4a69537 commit ec90148
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ Scraping `/stats` for `total.indexing` and `total.search` metrics only
$ docker run --network=host -it vinted/elasticsearch_exporter --elasticsearch_url=http://IP:PORT --exporter_metrics_enabled="stats=true" --elasticsearch_query_filter_path="stats=indices.*.total.indexing,indices.*.total.search"
```

Scraping `/_cat/shards` for `search.fetch*` metrics only. In this case `elasticsearch_query_filter_path` must always include `index,shard`, and dotted format is not supported. Example:

```
$ docker run --network=host -it vinted/elasticsearch_exporter --elasticsearch_url=http://IP:PORT --exporter_metrics_enabled="cat_shards=true" --elasticsearch_query_filter_path="cat_shards=index,shard,search*fetch*"
```

```shell
$ curl -s http://127.0.0.1:9222
Vinted Elasticsearch exporter
Expand Down
18 changes: 12 additions & 6 deletions src/metrics/_cat/shards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ use super::responses::CatResponse;
pub(crate) const SUBSYSTEM: &str = "cat_shards";

async fn metrics(exporter: &Exporter) -> Result<Vec<Metrics>, elasticsearch::Error> {
let response = exporter
.client()
.cat()
let filter_path = exporter.options().query_filter_path_for_subsystem(SUBSYSTEM);

let cat = exporter.client().cat();

let mut shards_stats = cat
.shards(CatShardsParts::Index(&["*"]))
.format("json")
.h(&["*"])
.bytes(Bytes::B)
.request_timeout(exporter.options().timeout_for_subsystem(SUBSYSTEM))
.time(Time::Ms)
.send()
.await?;
.time(Time::Ms);

if !filter_path.is_empty() {
shards_stats = shards_stats.filter_path(&filter_path)
}

let response = shards_stats.send().await?;

let values = response.json::<CatResponse>().await?.into_values(|map| {
if map
Expand Down

0 comments on commit ec90148

Please sign in to comment.