@@ -70,26 +70,13 @@ func getRoles(node NodeStatsNodeResponse) map[string]bool {
70
70
return roles
71
71
}
72
72
73
- func createRoleMetric (role string ) * nodeMetric {
74
- return & nodeMetric {
75
- Type : prometheus .GaugeValue ,
76
- Desc : prometheus .NewDesc (
77
- prometheus .BuildFQName (namespace , "nodes" , "roles" ),
78
- "Node roles" ,
79
- defaultRoleLabels , prometheus.Labels {"role" : role },
80
- ),
81
- Value : func (node NodeStatsNodeResponse ) float64 {
82
- return 1.0
83
- },
84
- Labels : func (cluster string , node NodeStatsNodeResponse ) []string {
85
- return []string {
86
- cluster ,
87
- node .Host ,
88
- node .Name ,
89
- }
90
- },
91
- }
92
- }
73
+ var (
74
+ nodesRolesMetric = prometheus .NewDesc (
75
+ prometheus .BuildFQName (namespace , "nodes" , "roles" ),
76
+ "Node roles" ,
77
+ append (defaultRoleLabels , "role" ), nil ,
78
+ )
79
+ )
93
80
94
81
var (
95
82
defaultNodeLabels = []string {"cluster" , "host" , "name" , "es_master_node" , "es_data_node" , "es_ingest_node" , "es_client_node" }
@@ -187,9 +174,6 @@ type Nodes struct {
187
174
all bool
188
175
node string
189
176
190
- up prometheus.Gauge
191
- totalScrapes , jsonParseFailures prometheus.Counter
192
-
193
177
nodeMetrics []* nodeMetric
194
178
gcCollectionMetrics []* gcCollectionMetric
195
179
breakerMetrics []* breakerMetric
@@ -208,19 +192,6 @@ func NewNodes(logger log.Logger, client *http.Client, url *url.URL, all bool, no
208
192
all : all ,
209
193
node : node ,
210
194
211
- up : prometheus .NewGauge (prometheus.GaugeOpts {
212
- Name : prometheus .BuildFQName (namespace , "node_stats" , "up" ),
213
- Help : "Was the last scrape of the Elasticsearch nodes endpoint successful." ,
214
- }),
215
- totalScrapes : prometheus .NewCounter (prometheus.CounterOpts {
216
- Name : prometheus .BuildFQName (namespace , "node_stats" , "total_scrapes" ),
217
- Help : "Current total Elasticsearch node scrapes." ,
218
- }),
219
- jsonParseFailures : prometheus .NewCounter (prometheus.CounterOpts {
220
- Name : prometheus .BuildFQName (namespace , "node_stats" , "json_parse_failures" ),
221
- Help : "Number of errors while parsing JSON." ,
222
- }),
223
-
224
195
nodeMetrics : []* nodeMetric {
225
196
{
226
197
Type : prometheus .GaugeValue ,
@@ -1859,12 +1830,20 @@ func NewNodes(logger log.Logger, client *http.Client, url *url.URL, all bool, no
1859
1830
1860
1831
// Describe add metrics descriptions
1861
1832
func (c * Nodes ) Describe (ch chan <- * prometheus.Desc ) {
1833
+ ch <- nodesRolesMetric
1834
+
1862
1835
for _ , metric := range c .nodeMetrics {
1863
1836
ch <- metric .Desc
1864
1837
}
1865
1838
for _ , metric := range c .gcCollectionMetrics {
1866
1839
ch <- metric .Desc
1867
1840
}
1841
+ for _ , metric := range c .breakerMetrics {
1842
+ ch <- metric .Desc
1843
+ }
1844
+ for _ , metric := range c .indexingPressureMetrics {
1845
+ ch <- metric .Desc
1846
+ }
1868
1847
for _ , metric := range c .threadPoolMetrics {
1869
1848
ch <- metric .Desc
1870
1849
}
@@ -1874,9 +1853,6 @@ func (c *Nodes) Describe(ch chan<- *prometheus.Desc) {
1874
1853
for _ , metric := range c .filesystemIODeviceMetrics {
1875
1854
ch <- metric .Desc
1876
1855
}
1877
- ch <- c .up .Desc ()
1878
- ch <- c .totalScrapes .Desc ()
1879
- ch <- c .jsonParseFailures .Desc ()
1880
1856
}
1881
1857
1882
1858
func (c * Nodes ) fetchAndDecodeNodeStats () (nodeStatsResponse , error ) {
@@ -1912,51 +1888,49 @@ func (c *Nodes) fetchAndDecodeNodeStats() (nodeStatsResponse, error) {
1912
1888
1913
1889
bts , err := io .ReadAll (res .Body )
1914
1890
if err != nil {
1915
- c .jsonParseFailures .Inc ()
1916
1891
return nsr , err
1917
1892
}
1918
1893
1919
1894
if err := json .Unmarshal (bts , & nsr ); err != nil {
1920
- c .jsonParseFailures .Inc ()
1921
1895
return nsr , err
1922
1896
}
1923
1897
return nsr , nil
1924
1898
}
1925
1899
1926
1900
// Collect gets nodes metric values
1927
1901
func (c * Nodes ) Collect (ch chan <- prometheus.Metric ) {
1928
- c .totalScrapes .Inc ()
1929
- defer func () {
1930
- ch <- c .up
1931
- ch <- c .totalScrapes
1932
- ch <- c .jsonParseFailures
1933
- }()
1934
-
1935
1902
nodeStatsResp , err := c .fetchAndDecodeNodeStats ()
1936
1903
if err != nil {
1937
- c .up .Set (0 )
1938
1904
level .Warn (c .logger ).Log (
1939
1905
"msg" , "failed to fetch and decode node stats" ,
1940
1906
"err" , err ,
1941
1907
)
1942
1908
return
1943
1909
}
1944
- c .up .Set (1 )
1945
1910
1946
1911
for _ , node := range nodeStatsResp .Nodes {
1947
1912
// Handle the node labels metric
1948
1913
roles := getRoles (node )
1949
1914
1950
1915
for role , roleEnabled := range roles {
1916
+ val := 0.0
1951
1917
if roleEnabled {
1952
- metric := createRoleMetric (role )
1953
- ch <- prometheus .MustNewConstMetric (
1954
- metric .Desc ,
1955
- metric .Type ,
1956
- metric .Value (node ),
1957
- metric .Labels (nodeStatsResp .ClusterName , node )... ,
1958
- )
1918
+ val = 1.0
1959
1919
}
1920
+
1921
+ labels := []string {
1922
+ nodeStatsResp .ClusterName ,
1923
+ node .Host ,
1924
+ node .Name ,
1925
+ role ,
1926
+ }
1927
+
1928
+ ch <- prometheus .MustNewConstMetric (
1929
+ nodesRolesMetric ,
1930
+ prometheus .GaugeValue ,
1931
+ val ,
1932
+ labels ... ,
1933
+ )
1960
1934
}
1961
1935
1962
1936
for _ , metric := range c .nodeMetrics {
0 commit comments