Skip to content

Commit c5cbb48

Browse files
author
黄振明
committed
feat: add indexing pressure
Signed-off-by: 黄振明 <[email protected]>
1 parent ed8a758 commit c5cbb48

File tree

2 files changed

+238
-17
lines changed

2 files changed

+238
-17
lines changed

collector/nodes.go

+194
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ type filesystemIODeviceMetric struct {
171171
Labels func(cluster string, node NodeStatsNodeResponse, device string) []string
172172
}
173173

174+
type indexingPressureMetric struct {
175+
Type prometheus.ValueType
176+
Desc *prometheus.Desc
177+
Value func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64
178+
Labels func(cluster string, node NodeStatsNodeResponse) []string
179+
}
180+
174181
// Nodes information struct
175182
type Nodes struct {
176183
logger log.Logger
@@ -188,6 +195,7 @@ type Nodes struct {
188195
threadPoolMetrics []*threadPoolMetric
189196
filesystemDataMetrics []*filesystemDataMetric
190197
filesystemIODeviceMetrics []*filesystemIODeviceMetric
198+
indexingPressureMetrics []*indexingPressureMetric
191199
}
192200

193201
// NewNodes defines Nodes Prometheus metrics
@@ -1781,6 +1789,176 @@ func NewNodes(logger log.Logger, client *http.Client, url *url.URL, all bool, no
17811789
Labels: defaultFilesystemIODeviceLabelValues,
17821790
},
17831791
},
1792+
indexingPressureMetrics: []*indexingPressureMetric{
1793+
{
1794+
Type: prometheus.GaugeValue,
1795+
Desc: prometheus.NewDesc(
1796+
prometheus.BuildFQName(namespace, "indexing_pressure", "current_combined_coordinating_and_primary_in_bytes"),
1797+
"Memory consumed, in bytes, by indexing requests in the coordinating or primary stage.",
1798+
defaultNodeLabels, nil,
1799+
),
1800+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1801+
return float64(indexingPressureMem.Current.CombinedCoordinatingAndPrimaryInBytes)
1802+
},
1803+
Labels: defaultNodeLabelValues,
1804+
},
1805+
{
1806+
Type: prometheus.GaugeValue,
1807+
Desc: prometheus.NewDesc(
1808+
prometheus.BuildFQName(namespace, "indexing_pressure", "current_coordinating_in_bytes"),
1809+
"Memory consumed, in bytes, by indexing requests in the coordinating stage.",
1810+
defaultNodeLabels, nil,
1811+
),
1812+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1813+
return float64(indexingPressureMem.Current.CoordinatingInBytes)
1814+
},
1815+
Labels: defaultNodeLabelValues,
1816+
},
1817+
{
1818+
Type: prometheus.GaugeValue,
1819+
Desc: prometheus.NewDesc(
1820+
prometheus.BuildFQName(namespace, "indexing_pressure", "current_primary_in_bytes"),
1821+
"Memory consumed, in bytes, by indexing requests in the primary stage.",
1822+
defaultNodeLabels, nil,
1823+
),
1824+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1825+
return float64(indexingPressureMem.Current.PrimaryInBytes)
1826+
},
1827+
Labels: defaultNodeLabelValues,
1828+
},
1829+
{
1830+
Type: prometheus.GaugeValue,
1831+
Desc: prometheus.NewDesc(
1832+
prometheus.BuildFQName(namespace, "indexing_pressure", "current_replica_in_bytes"),
1833+
"Memory consumed, in bytes, by indexing requests in the replica stage.",
1834+
defaultNodeLabels, nil,
1835+
),
1836+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1837+
return float64(indexingPressureMem.Current.ReplicaInBytes)
1838+
},
1839+
Labels: defaultNodeLabelValues,
1840+
},
1841+
{
1842+
Type: prometheus.GaugeValue,
1843+
Desc: prometheus.NewDesc(
1844+
prometheus.BuildFQName(namespace, "indexing_pressure", "current_all_in_bytes"),
1845+
"Memory consumed, in bytes, by indexing requests in the coordinating, primary, or replica stage.",
1846+
defaultNodeLabels, nil,
1847+
),
1848+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1849+
return float64(indexingPressureMem.Current.ReplicaInBytes)
1850+
},
1851+
Labels: defaultNodeLabelValues,
1852+
},
1853+
{
1854+
Type: prometheus.CounterValue,
1855+
Desc: prometheus.NewDesc(
1856+
prometheus.BuildFQName(namespace, "indexing_pressure", "total_combined_coordinating_and_primary_in_bytes"),
1857+
"Memory consumed, in bytes, by indexing requests in the coordinating or primary stage.",
1858+
defaultNodeLabels, nil,
1859+
),
1860+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1861+
return float64(indexingPressureMem.Total.CombinedCoordinatingAndPrimaryInBytes)
1862+
},
1863+
Labels: defaultNodeLabelValues,
1864+
},
1865+
{
1866+
Type: prometheus.CounterValue,
1867+
Desc: prometheus.NewDesc(
1868+
prometheus.BuildFQName(namespace, "indexing_pressure", "total_coordinating_in_bytes"),
1869+
"Memory consumed, in bytes, by indexing requests in the coordinating stage.",
1870+
defaultNodeLabels, nil,
1871+
),
1872+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1873+
return float64(indexingPressureMem.Total.CoordinatingInBytes)
1874+
},
1875+
Labels: defaultNodeLabelValues,
1876+
},
1877+
{
1878+
Type: prometheus.CounterValue,
1879+
Desc: prometheus.NewDesc(
1880+
prometheus.BuildFQName(namespace, "indexing_pressure", "total_primary_in_bytes"),
1881+
"Memory consumed, in bytes, by indexing requests in the primary stage.",
1882+
defaultNodeLabels, nil,
1883+
),
1884+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1885+
return float64(indexingPressureMem.Total.PrimaryInBytes)
1886+
},
1887+
Labels: defaultNodeLabelValues,
1888+
},
1889+
{
1890+
Type: prometheus.CounterValue,
1891+
Desc: prometheus.NewDesc(
1892+
prometheus.BuildFQName(namespace, "indexing_pressure", "total_replica_in_bytes"),
1893+
"Memory consumed, in bytes, by indexing requests in the replica stage.",
1894+
defaultNodeLabels, nil,
1895+
),
1896+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1897+
return float64(indexingPressureMem.Total.ReplicaInBytes)
1898+
},
1899+
Labels: defaultNodeLabelValues,
1900+
},
1901+
{
1902+
Type: prometheus.CounterValue,
1903+
Desc: prometheus.NewDesc(
1904+
prometheus.BuildFQName(namespace, "indexing_pressure", "total_all_in_bytes"),
1905+
"Memory consumed, in bytes, by indexing requests in the coordinating, primary, or replica stage.",
1906+
defaultNodeLabels, nil,
1907+
),
1908+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1909+
return float64(indexingPressureMem.Total.AllInBytes)
1910+
},
1911+
Labels: defaultNodeLabelValues,
1912+
},
1913+
{
1914+
Type: prometheus.CounterValue,
1915+
Desc: prometheus.NewDesc(
1916+
prometheus.BuildFQName(namespace, "indexing_pressure", "total_coordinating_rejections"),
1917+
"Number of indexing requests rejected in the coordinating stage.",
1918+
defaultNodeLabels, nil,
1919+
),
1920+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1921+
return float64(indexingPressureMem.Total.CoordinatingRejections)
1922+
},
1923+
Labels: defaultNodeLabelValues,
1924+
},
1925+
{
1926+
Type: prometheus.CounterValue,
1927+
Desc: prometheus.NewDesc(
1928+
prometheus.BuildFQName(namespace, "indexing_pressure", "total_primary_rejections"),
1929+
"Number of indexing requests rejected in the primary stage.",
1930+
defaultNodeLabels, nil,
1931+
),
1932+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1933+
return float64(indexingPressureMem.Total.PrimaryRejections)
1934+
},
1935+
Labels: defaultNodeLabelValues,
1936+
},
1937+
{
1938+
Type: prometheus.CounterValue,
1939+
Desc: prometheus.NewDesc(
1940+
prometheus.BuildFQName(namespace, "indexing_pressure", "total_replica_rejections"),
1941+
"Number of indexing requests rejected in the replica stage.",
1942+
defaultNodeLabels, nil,
1943+
),
1944+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1945+
return float64(indexingPressureMem.Total.ReplicaRejections)
1946+
},
1947+
Labels: defaultNodeLabelValues,
1948+
},
1949+
{
1950+
Type: prometheus.CounterValue,
1951+
Desc: prometheus.NewDesc(
1952+
prometheus.BuildFQName(namespace, "indexing_pressure", "limit_in_bytes"),
1953+
"Configured memory limit, in bytes, for the indexing requests. Replica requests have an automatic limit that is 1.5x this value.",
1954+
defaultNodeLabels, nil,
1955+
),
1956+
Value: func(indexingPressureMem NodestatsIndexingPressureMemoryResponse) float64 {
1957+
return float64(indexingPressureMem.LimitInBytes)
1958+
},
1959+
Labels: defaultNodeLabelValues,
1960+
},
1961+
},
17841962
}
17851963
}
17861964

@@ -1801,6 +1979,9 @@ func (c *Nodes) Describe(ch chan<- *prometheus.Desc) {
18011979
for _, metric := range c.filesystemIODeviceMetrics {
18021980
ch <- metric.Desc
18031981
}
1982+
for _, metric := range c.indexingPressureMetrics {
1983+
ch <- metric.Desc
1984+
}
18041985
ch <- c.up.Desc()
18051986
ch <- c.totalScrapes.Desc()
18061987
ch <- c.jsonParseFailures.Desc()
@@ -1955,5 +2136,18 @@ func (c *Nodes) Collect(ch chan<- prometheus.Metric) {
19552136
}
19562137
}
19572138

2139+
// indexing_pressure Stats https://github.com/prometheus-community/elasticsearch_exporter/issues/638
2140+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-indexing-pressure.html
2141+
for _, indexingPressureMem := range node.IndexingPressure {
2142+
for _, metric := range c.indexingPressureMetrics {
2143+
ch <- prometheus.MustNewConstMetric(
2144+
metric.Desc,
2145+
metric.Type,
2146+
metric.Value(indexingPressureMem),
2147+
metric.Labels(nodeStatsResp.ClusterName, node)...,
2148+
)
2149+
}
2150+
}
2151+
19582152
}
19592153
}

collector/nodes_response.go

+44-17
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,24 @@ type nodeStatsResponse struct {
2323

2424
// NodeStatsNodeResponse defines node stats information structure for nodes
2525
type NodeStatsNodeResponse struct {
26-
Name string `json:"name"`
27-
Host string `json:"host"`
28-
Timestamp int64 `json:"timestamp"`
29-
TransportAddress string `json:"transport_address"`
30-
Hostname string `json:"hostname"`
31-
Roles []string `json:"roles"`
32-
Attributes map[string]string `json:"attributes"`
33-
Indices NodeStatsIndicesResponse `json:"indices"`
34-
OS NodeStatsOSResponse `json:"os"`
35-
Network NodeStatsNetworkResponse `json:"network"`
36-
FS NodeStatsFSResponse `json:"fs"`
37-
ThreadPool map[string]NodeStatsThreadPoolPoolResponse `json:"thread_pool"`
38-
JVM NodeStatsJVMResponse `json:"jvm"`
39-
Breakers map[string]NodeStatsBreakersResponse `json:"breakers"`
40-
HTTP map[string]interface{} `json:"http"`
41-
Transport NodeStatsTransportResponse `json:"transport"`
42-
Process NodeStatsProcessResponse `json:"process"`
26+
Name string `json:"name"`
27+
Host string `json:"host"`
28+
Timestamp int64 `json:"timestamp"`
29+
TransportAddress string `json:"transport_address"`
30+
Hostname string `json:"hostname"`
31+
Roles []string `json:"roles"`
32+
Attributes map[string]string `json:"attributes"`
33+
Indices NodeStatsIndicesResponse `json:"indices"`
34+
OS NodeStatsOSResponse `json:"os"`
35+
Network NodeStatsNetworkResponse `json:"network"`
36+
FS NodeStatsFSResponse `json:"fs"`
37+
ThreadPool map[string]NodeStatsThreadPoolPoolResponse `json:"thread_pool"`
38+
JVM NodeStatsJVMResponse `json:"jvm"`
39+
Breakers map[string]NodeStatsBreakersResponse `json:"breakers"`
40+
HTTP map[string]interface{} `json:"http"`
41+
Transport NodeStatsTransportResponse `json:"transport"`
42+
Process NodeStatsProcessResponse `json:"process"`
43+
IndexingPressure map[string]NodestatsIndexingPressureMemoryResponse `json:"indexing_pressure"`
4344
}
4445

4546
// NodeStatsBreakersResponse is a representation of a statistics about the field data circuit breaker
@@ -317,6 +318,32 @@ type NodeStatsProcessResponse struct {
317318
Memory NodeStatsProcessMemResponse `json:"mem"`
318319
}
319320

321+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html#cluster-nodes-stats-api-response-body-indexing-pressure
322+
type NodestatsIndexingPressureMemoryResponse struct {
323+
Current NodestatsIndexingPressureMemoryCurrentResponse `json:"current"`
324+
Total NodestatsIndexingPressureMemoryTotalResponse `json:"total"`
325+
LimitInBytes int64 `json:"limit_in_bytes"`
326+
}
327+
328+
type NodestatsIndexingPressureMemoryCurrentResponse struct {
329+
CombinedCoordinatingAndPrimaryInBytes int64 `json:"combined_coordinating_and_primary_in_bytes"`
330+
CoordinatingInBytes int64 `json:"coordinating_in_bytes"`
331+
PrimaryInBytes int64 `json:"primary_in_bytes"`
332+
ReplicaInBytes int64 `json:"replica_in_bytes"`
333+
AllInBytes int64 `json:"all_in_bytes"`
334+
}
335+
336+
type NodestatsIndexingPressureMemoryTotalResponse struct {
337+
CombinedCoordinatingAndPrimaryInBytes int64 `json:"combined_coordinating_and_primary_in_bytes"`
338+
CoordinatingInBytes int64 `json:"coordinating_in_bytes"`
339+
PrimaryInBytes int64 `json:"primary_in_bytes"`
340+
ReplicaInBytes int64 `json:"replica_in_bytes"`
341+
AllInBytes int64 `json:"all_in_bytes"`
342+
CoordinatingRejections int64 `json:"coordinating_rejections"`
343+
PrimaryRejections int64 `json:"primary_rejections"`
344+
ReplicaRejections int64 `json:"replica_rejections"`
345+
}
346+
320347
// NodeStatsProcessMemResponse defines node stats process memory usage structure
321348
type NodeStatsProcessMemResponse struct {
322349
Resident int64 `json:"resident_in_bytes"`

0 commit comments

Comments
 (0)