Skip to content

Commit 79cd2f1

Browse files
author
zhangning3
committed
add elasticsearch_indices_settings_shards metric doc (prometheus-community#806)
1 parent b0f63df commit 79cd2f1

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ Further Information
190190
| elasticsearch_indices_settings_stats_read_only_indices | gauge | 1 | Count of indices that have read_only_allow_delete=true |
191191
| elasticsearch_indices_settings_total_fields | gauge | | Index setting value for index.mapping.total_fields.limit (total allowable mapped fields in a index) |
192192
| elasticsearch_indices_settings_replicas | gauge | | Index setting value for index.replicas |
193+
| elasticsearch_indices_settings_shards | gauge | | Index setting value for index.shards |
193194
| elasticsearch_indices_shards_docs | gauge | 3 | Count of documents on this shard |
194195
| elasticsearch_indices_shards_docs_deleted | gauge | 3 | Count of deleted documents on each shard |
195196
| elasticsearch_indices_store_size_bytes | gauge | 1 | Current size of stored index data in bytes |

collector/indices_settings.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ func NewIndicesSettings(logger log.Logger, client *http.Client, url *url.URL) *I
105105
return val
106106
},
107107
},
108+
{
109+
Type: prometheus.GaugeValue,
110+
Desc: prometheus.NewDesc(
111+
prometheus.BuildFQName(namespace, "indices_settings", "shards"),
112+
"index setting number_of_shards",
113+
defaultIndicesTotalFieldsLabels, nil,
114+
),
115+
Value: func(indexSettings Settings) float64 {
116+
val, err := strconv.ParseFloat(indexSettings.IndexInfo.NumberOfShard, 64)
117+
if err != nil {
118+
return float64(defaultTotalFieldsValue)
119+
}
120+
return val
121+
},
122+
},
108123
},
109124
}
110125
}

collector/indices_settings_response.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type IndexInfo struct {
3131
Blocks Blocks `json:"blocks"`
3232
Mapping Mapping `json:"mapping"`
3333
NumberOfReplicas string `json:"number_of_replicas"`
34+
NumberOfShard string `json:"number_of_shards"`
3435
}
3536

3637
// Blocks defines whether current index has read_only_allow_delete enabled

collector/indices_settings_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestIndicesSettings(t *testing.T) {
5555
// curl http://localhost:9200/_all/_settings
5656

5757
tcs := map[string]string{
58-
"6.5.4": `{"viber":{"settings":{"index":{"creation_date":"1618593207186","number_of_shards":"5","number_of_replicas":"1","uuid":"lWg86KTARzO3r7lELytT1Q","version":{"created":"6050499"},"provided_name":"viber"}}},"instagram":{"settings":{"index":{"mapping":{"total_fields":{"limit":"10000"}},"number_of_shards":"5","blocks":{"read_only_allow_delete":"true"},"provided_name":"instagram","creation_date":"1618593203353","number_of_replicas":"1","uuid":"msb6eG7aT8GmNe-a4oyVtQ","version":{"created":"6050499"}}}},"twitter":{"settings":{"index":{"number_of_shards":"5","blocks":{"read_only_allow_delete":"true"},"provided_name":"twitter","creation_date":"1618593193641","number_of_replicas":"1","uuid":"YRUT8t4aSkKsNmGl7K3y4Q","version":{"created":"6050499"}}}},"facebook":{"settings":{"index":{"creation_date":"1618593199101","number_of_shards":"5","number_of_replicas":"1","uuid":"trZhb_YOTV-RWKitTYw81A","version":{"created":"6050499"},"provided_name":"facebook"}}}}`,
58+
"6.5.4": `{"viber":{"settings":{"index":{"creation_date":"1618593207186","number_of_shards":"3","number_of_replicas":"1","uuid":"lWg86KTARzO3r7lELytT1Q","version":{"created":"6050499"},"provided_name":"viber"}}},"instagram":{"settings":{"index":{"mapping":{"total_fields":{"limit":"10000"}},"number_of_shards":"5","blocks":{"read_only_allow_delete":"true"},"provided_name":"instagram","creation_date":"1618593203353","number_of_replicas":"1","uuid":"msb6eG7aT8GmNe-a4oyVtQ","version":{"created":"6050499"}}}},"twitter":{"settings":{"index":{"number_of_shards":"5","blocks":{"read_only_allow_delete":"true"},"provided_name":"twitter","creation_date":"1618593193641","number_of_replicas":"1","uuid":"YRUT8t4aSkKsNmGl7K3y4Q","version":{"created":"6050499"}}}},"facebook":{"settings":{"index":{"creation_date":"1618593199101","number_of_shards":"5","number_of_replicas":"1","uuid":"trZhb_YOTV-RWKitTYw81A","version":{"created":"6050499"},"provided_name":"facebook"}}}}`,
5959
}
6060
for ver, out := range tcs {
6161
for hn, handler := range map[string]http.Handler{
@@ -81,6 +81,7 @@ func TestIndicesSettings(t *testing.T) {
8181
// }
8282
var counter int
8383
var totalFields int
84+
var shards int
8485
for key, value := range nsr {
8586
if value.Settings.IndexInfo.Blocks.ReadOnly == "true" {
8687
counter++
@@ -94,13 +95,22 @@ func TestIndicesSettings(t *testing.T) {
9495
t.Errorf("Expected 10000 total_fields only for instagram")
9596
}
9697
}
98+
if value.Settings.IndexInfo.NumberOfShard == "3" {
99+
shards++
100+
if key != "viber" {
101+
t.Errorf("Expected 3 shard only for shards")
102+
}
103+
}
97104
}
98105
if counter != 2 {
99106
t.Errorf("Wrong number of read_only indexes")
100107
}
101108
if totalFields != 1 {
102109
t.Errorf(("Wrong number of total_fields found"))
103110
}
111+
if shards != 1 {
112+
t.Errorf(("Wrong number of shards found"))
113+
}
104114
}
105115
}
106116
}

0 commit comments

Comments
 (0)