Skip to content

Commit

Permalink
[receiver/elasticsearch]: add document count metrics on index level (#…
Browse files Browse the repository at this point in the history
…14874)

feat: add document count metrics on index level
  • Loading branch information
aboguszewski-sumo authored Nov 17, 2022
1 parent cd1fc02 commit f67ff81
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .chloggen/elasticsearch-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: elasticsearchreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: add document count metrics on index level

# One or more tracking issues related to the change
issues: [14635]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
1 change: 1 addition & 0 deletions receiver/elasticsearchreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ These are the metrics available for this scraper.
| elasticsearch.index.cache.evictions | The number of evictions from the cache for an index. | {evictions} | Sum(Int) | <ul> <li>cache_name</li> <li>index_aggregation_type</li> </ul> |
| elasticsearch.index.cache.memory.usage | The size in bytes of the cache for an index. | By | Sum(Int) | <ul> <li>cache_name</li> <li>index_aggregation_type</li> </ul> |
| elasticsearch.index.cache.size | The number of elements of the query cache for an index. | 1 | Sum(Int) | <ul> <li>index_aggregation_type</li> </ul> |
| elasticsearch.index.documents | The number of documents for an index. | {documents} | Sum(Int) | <ul> <li>document_state</li> <li>index_aggregation_type</li> </ul> |
| **elasticsearch.index.operations.completed** | The number of operations completed for an index. | {operations} | Sum(Int) | <ul> <li>operation</li> <li>index_aggregation_type</li> </ul> |
| elasticsearch.index.operations.merge.docs_count | The total number of documents in merge operations for an index. | {documents} | Sum(Int) | <ul> <li>index_aggregation_type</li> </ul> |
| elasticsearch.index.operations.merge.size | The total size of merged segments for an index. | By | Sum(Int) | <ul> <li>index_aggregation_type</li> </ul> |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions receiver/elasticsearchreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -905,3 +905,12 @@ metrics:
value_type: int
attributes: [cache_name, index_aggregation_type]
enabled: false
elasticsearch.index.documents:
description: The number of documents for an index.
unit: "{documents}"
sum:
monotonic: false
aggregation: cumulative
value_type: int
attributes: [document_state, index_aggregation_type]
enabled: false
9 changes: 8 additions & 1 deletion receiver/elasticsearchreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (r *elasticsearchScraper) scrapeIndicesMetrics(ctx context.Context, now pco
indexStats, err := r.client.IndexStats(ctx, r.cfg.Indices)

if err != nil {
errs.AddPartial(22, err)
errs.AddPartial(24, err)
return
}

Expand Down Expand Up @@ -492,5 +492,12 @@ func (r *elasticsearchScraper) scrapeOneIndexMetrics(now pcommon.Timestamp, name
now, stats.Total.QueryCache.Evictions, metadata.AttributeCacheNameQuery, metadata.AttributeIndexAggregationTypeTotal,
)

r.mb.RecordElasticsearchIndexDocumentsDataPoint(
now, stats.Primaries.DocumentStats.ActiveCount, metadata.AttributeDocumentStateActive, metadata.AttributeIndexAggregationTypePrimaryShards,
)
r.mb.RecordElasticsearchIndexDocumentsDataPoint(
now, stats.Total.DocumentStats.ActiveCount, metadata.AttributeDocumentStateActive, metadata.AttributeIndexAggregationTypeTotal,
)

r.mb.EmitForResource(metadata.WithElasticsearchIndexName(name), metadata.WithElasticsearchClusterName(r.clusterName))
}
1 change: 1 addition & 0 deletions receiver/elasticsearchreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestScraper(t *testing.T) {
config.Metrics.ElasticsearchIndexCacheMemoryUsage.Enabled = true
config.Metrics.ElasticsearchIndexCacheSize.Enabled = true
config.Metrics.ElasticsearchIndexCacheEvictions.Enabled = true
config.Metrics.ElasticsearchIndexDocuments.Enabled = true

sc := newElasticSearchScraper(componenttest.NewNopReceiverCreateSettings(), config)

Expand Down
98 changes: 98 additions & 0 deletions receiver/elasticsearchreceiver/testdata/expected_metrics/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -3194,6 +3194,55 @@
]
},
"unit": "{evictions}"
},
{
"description": "The number of documents for an index.",
"name": "elasticsearch.index.documents",
"sum": {
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"isMonotonic": false,
"dataPoints": [
{
"asInt": "40",
"attributes": [
{
"key": "state",
"value": {
"stringValue": "active"
}
},
{
"key": "aggregation",
"value": {
"stringValue": "total"
}
}
],
"startTimeUnixNano": "1661811689941624000",
"timeUnixNano": "1661811689943245000"
},
{
"asInt": "40",
"attributes": [
{
"key": "state",
"value": {
"stringValue": "active"
}
},
{
"key": "aggregation",
"value": {
"stringValue": "primary_shards"
}
}
],
"startTimeUnixNano": "1661811689941624000",
"timeUnixNano": "1661811689943245000"
}
]
},
"unit": "{documents}"
}
],
"scope": {
Expand Down Expand Up @@ -3869,6 +3918,55 @@
]
},
"unit": "{evictions}"
},
{
"description": "The number of documents for an index.",
"name": "elasticsearch.index.documents",
"sum": {
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"isMonotonic": false,
"dataPoints": [
{
"asInt": "40",
"attributes": [
{
"key": "state",
"value": {
"stringValue": "active"
}
},
{
"key": "aggregation",
"value": {
"stringValue": "total"
}
}
],
"startTimeUnixNano": "1661811689941624000",
"timeUnixNano": "1661811689943245000"
},
{
"asInt": "40",
"attributes": [
{
"key": "state",
"value": {
"stringValue": "active"
}
},
{
"key": "aggregation",
"value": {
"stringValue": "primary_shards"
}
}
],
"startTimeUnixNano": "1661811689941624000",
"timeUnixNano": "1661811689943245000"
}
]
},
"unit": "{documents}"
}
],
"scope": {
Expand Down

0 comments on commit f67ff81

Please sign in to comment.