github.com/netdata/go.d.plugin@v0.58.1/modules/elasticsearch/metrics.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package elasticsearch
     4  
     5  // https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
     6  
     7  type esMetrics struct {
     8  	// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html
     9  	NodesStats *esNodesStats
    10  	// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html
    11  	ClusterHealth *esClusterHealth
    12  	// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html
    13  	ClusterStats *esClusterStats
    14  	// https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html
    15  	LocalIndicesStats []esIndexStats
    16  }
    17  
    18  func (m esMetrics) empty() bool {
    19  	switch {
    20  	case m.hasNodesStats(), m.hasClusterHealth(), m.hasClusterStats(), m.hasLocalIndicesStats():
    21  		return false
    22  	}
    23  	return true
    24  }
    25  
    26  func (m esMetrics) hasNodesStats() bool        { return m.NodesStats != nil && len(m.NodesStats.Nodes) > 0 }
    27  func (m esMetrics) hasClusterHealth() bool     { return m.ClusterHealth != nil }
    28  func (m esMetrics) hasClusterStats() bool      { return m.ClusterStats != nil }
    29  func (m esMetrics) hasLocalIndicesStats() bool { return len(m.LocalIndicesStats) > 0 }
    30  
    31  type (
    32  	esNodesStats struct {
    33  		ClusterName string                  `json:"cluster_name"`
    34  		Nodes       map[string]*esNodeStats `json:"nodes"`
    35  	}
    36  	esNodeStats struct {
    37  		Name    string
    38  		Host    string
    39  		Indices struct {
    40  			Indexing struct {
    41  				IndexTotal        float64 `stm:"index_total" json:"index_total"`
    42  				IndexCurrent      float64 `stm:"index_current" json:"index_current"`
    43  				IndexTimeInMillis float64 `stm:"index_time_in_millis" json:"index_time_in_millis"`
    44  			} `stm:"indexing"`
    45  			Search struct {
    46  				FetchTotal        float64 `stm:"fetch_total" json:"fetch_total"`
    47  				FetchCurrent      float64 `stm:"fetch_current" json:"fetch_current"`
    48  				FetchTimeInMillis float64 `stm:"fetch_time_in_millis" json:"fetch_time_in_millis"`
    49  				QueryTotal        float64 `stm:"query_total" json:"query_total"`
    50  				QueryCurrent      float64 `stm:"query_current" json:"query_current"`
    51  				QueryTimeInMillis float64 `stm:"query_time_in_millis" json:"query_time_in_millis"`
    52  			} `stm:"search"`
    53  			Refresh struct {
    54  				Total        float64 `stm:"total"`
    55  				TimeInMillis float64 `stm:"total_time_in_millis" json:"total_time_in_millis"`
    56  			} `stm:"refresh"`
    57  			Flush struct {
    58  				Total        float64 `stm:"total"`
    59  				TimeInMillis float64 `stm:"total_time_in_millis" json:"total_time_in_millis"`
    60  			} `stm:"flush"`
    61  			FieldData struct {
    62  				MemorySizeInBytes float64 `stm:"memory_size_in_bytes" json:"memory_size_in_bytes"`
    63  				Evictions         float64 `stm:"evictions"`
    64  			} `stm:"fielddata"`
    65  			Segments struct {
    66  				Count                     float64 `stm:"count" json:"count"`
    67  				MemoryInBytes             float64 `stm:"memory_in_bytes" json:"memory_in_bytes"`
    68  				TermsMemoryInBytes        float64 `stm:"terms_memory_in_bytes" json:"terms_memory_in_bytes"`
    69  				StoredFieldsMemoryInBytes float64 `stm:"stored_fields_memory_in_bytes" json:"stored_fields_memory_in_bytes"`
    70  				TermVectorsMemoryInBytes  float64 `stm:"term_vectors_memory_in_bytes" json:"term_vectors_memory_in_bytes"`
    71  				NormsMemoryInBytes        float64 `stm:"norms_memory_in_bytes" json:"norms_memory_in_bytes"`
    72  				PointsMemoryInBytes       float64 `stm:"points_memory_in_bytes" json:"points_memory_in_bytes"`
    73  				DocValuesMemoryInBytes    float64 `stm:"doc_values_memory_in_bytes" json:"doc_values_memory_in_bytes"`
    74  				IndexWriterMemoryInBytes  float64 `stm:"index_writer_memory_in_bytes" json:"index_writer_memory_in_bytes"`
    75  				VersionMapMemoryInBytes   float64 `stm:"version_map_memory_in_bytes" json:"version_map_memory_in_bytes"`
    76  				FixedBitSetMemoryInBytes  float64 `stm:"fixed_bit_set_memory_in_bytes" json:"fixed_bit_set_memory_in_bytes"`
    77  			} `stm:"segments"`
    78  			Translog struct {
    79  				Operations             float64 `stm:"operations"`
    80  				SizeInBytes            float64 `stm:"size_in_bytes" json:"size_in_bytes"`
    81  				UncommittedOperations  float64 `stm:"uncommitted_operations" json:"uncommitted_operations"`
    82  				UncommittedSizeInBytes float64 `stm:"uncommitted_size_in_bytes" json:"uncommitted_size_in_bytes"`
    83  			} `stm:"translog"`
    84  		} `stm:"indices"`
    85  		Process struct {
    86  			OpenFileDescriptors float64 `stm:"open_file_descriptors" json:"open_file_descriptors"`
    87  			MaxFileDescriptors  float64 `stm:"max_file_descriptors" json:"max_file_descriptors"`
    88  		} `stm:"process"`
    89  		JVM struct {
    90  			Mem struct {
    91  				HeapUsedPercent      float64 `stm:"heap_used_percent" json:"heap_used_percent"`
    92  				HeapUsedInBytes      float64 `stm:"heap_used_in_bytes" json:"heap_used_in_bytes"`
    93  				HeapCommittedInBytes float64 `stm:"heap_committed_in_bytes" json:"heap_committed_in_bytes"`
    94  			} `stm:"mem"`
    95  			GC struct {
    96  				Collectors struct {
    97  					Young struct {
    98  						CollectionCount        float64 `stm:"collection_count" json:"collection_count"`
    99  						CollectionTimeInMillis float64 `stm:"collection_time_in_millis" json:"collection_time_in_millis"`
   100  					} `stm:"young"`
   101  					Old struct {
   102  						CollectionCount        float64 `stm:"collection_count" json:"collection_count"`
   103  						CollectionTimeInMillis float64 `stm:"collection_time_in_millis" json:"collection_time_in_millis"`
   104  					} `stm:"old"`
   105  				} `stm:"collectors"`
   106  			} `stm:"gc"`
   107  			BufferPools struct {
   108  				Mapped struct {
   109  					Count                float64 `stm:"count"`
   110  					UsedInBytes          float64 `stm:"used_in_bytes" json:"used_in_bytes"`
   111  					TotalCapacityInBytes float64 `stm:"total_capacity_in_bytes" json:"total_capacity_in_bytes"`
   112  				} `stm:"mapped"`
   113  				Direct struct {
   114  					Count                float64 `stm:"count"`
   115  					UsedInBytes          float64 `stm:"used_in_bytes" json:"used_in_bytes"`
   116  					TotalCapacityInBytes float64 `stm:"total_capacity_in_bytes" json:"total_capacity_in_bytes"`
   117  				} `stm:"direct"`
   118  			} `stm:"buffer_pools" json:"buffer_pools"`
   119  		} `stm:"jvm"`
   120  		// https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-threadpool.html
   121  		ThreadPool struct {
   122  			Generic struct {
   123  				Queue    float64 `stm:"queue"`
   124  				Rejected float64 `stm:"rejected"`
   125  			} `stm:"generic"`
   126  			Search struct {
   127  				Queue    float64 `stm:"queue"`
   128  				Rejected float64 `stm:"rejected"`
   129  			} `stm:"search"`
   130  			SearchThrottled struct {
   131  				Queue    float64 `stm:"queue"`
   132  				Rejected float64 `stm:"rejected"`
   133  			} `stm:"search_throttled" json:"search_throttled"`
   134  			Get struct {
   135  				Queue    float64 `stm:"queue"`
   136  				Rejected float64 `stm:"rejected"`
   137  			} `stm:"get"`
   138  			Analyze struct {
   139  				Queue    float64 `stm:"queue"`
   140  				Rejected float64 `stm:"rejected"`
   141  			} `stm:"analyze"`
   142  			Write struct {
   143  				Queue    float64 `stm:"queue"`
   144  				Rejected float64 `stm:"rejected"`
   145  			} `stm:"write"`
   146  			Snapshot struct {
   147  				Queue    float64 `stm:"queue"`
   148  				Rejected float64 `stm:"rejected"`
   149  			} `stm:"snapshot"`
   150  			Warmer struct {
   151  				Queue    float64 `stm:"queue"`
   152  				Rejected float64 `stm:"rejected"`
   153  			} `stm:"warmer"`
   154  			Refresh struct {
   155  				Queue    float64 `stm:"queue"`
   156  				Rejected float64 `stm:"rejected"`
   157  			} `stm:"refresh"`
   158  			Listener struct {
   159  				Queue    float64 `stm:"queue"`
   160  				Rejected float64 `stm:"rejected"`
   161  			} `stm:"listener"`
   162  			FetchShardStarted struct {
   163  				Queue    float64 `stm:"queue"`
   164  				Rejected float64 `stm:"rejected"`
   165  			} `stm:"fetch_shard_started" json:"fetch_shard_started"`
   166  			FetchShardStore struct {
   167  				Queue    float64 `stm:"queue"`
   168  				Rejected float64 `stm:"rejected"`
   169  			} `stm:"fetch_shard_store" json:"fetch_shard_store"`
   170  			Flush struct {
   171  				Queue    float64 `stm:"queue"`
   172  				Rejected float64 `stm:"rejected"`
   173  			} `stm:"flush"`
   174  			ForceMerge struct {
   175  				Queue    float64 `stm:"queue"`
   176  				Rejected float64 `stm:"rejected"`
   177  			} `stm:"force_merge" json:"force_merge"`
   178  			Management struct {
   179  				Queue    float64 `stm:"queue"`
   180  				Rejected float64 `stm:"rejected"`
   181  			} `stm:"management"`
   182  		} `stm:"thread_pool" json:"thread_pool"`
   183  		Transport struct {
   184  			RxCount       float64 `stm:"rx_count" json:"rx_count"`
   185  			RxSizeInBytes float64 `stm:"rx_size_in_bytes" json:"rx_size_in_bytes"`
   186  			TxCount       float64 `stm:"tx_count" json:"tx_count"`
   187  			TxSizeInBytes float64 `stm:"tx_size_in_bytes" json:"tx_size_in_bytes"`
   188  		} `stm:"transport"`
   189  		HTTP struct {
   190  			CurrentOpen float64 `stm:"current_open" json:"current_open"`
   191  		} `stm:"http"`
   192  		Breakers struct {
   193  			Request struct {
   194  				Tripped float64 `stm:"tripped"`
   195  			} `stm:"request"`
   196  			FieldData struct {
   197  				Tripped float64 `stm:"tripped"`
   198  			} `stm:"fielddata"`
   199  			InFlightRequests struct {
   200  				Tripped float64 `stm:"tripped"`
   201  			} `stm:"in_flight_requests" json:"in_flight_requests"`
   202  			ModelInference struct {
   203  				Tripped float64 `stm:"tripped"`
   204  			} `stm:"model_inference" json:"model_inference"`
   205  			Accounting struct {
   206  				Tripped float64 `stm:"tripped"`
   207  			} `stm:"accounting"`
   208  			Parent struct {
   209  				Tripped float64 `stm:"tripped"`
   210  			} `stm:"parent"`
   211  		} `stm:"breakers"`
   212  	}
   213  )
   214  
   215  type esClusterHealth struct {
   216  	ClusterName                 string `json:"cluster_name"`
   217  	Status                      string
   218  	NumOfNodes                  float64 `stm:"number_of_nodes" json:"number_of_nodes"`
   219  	NumOfDataNodes              float64 `stm:"number_of_data_nodes" json:"number_of_data_nodes"`
   220  	ActivePrimaryShards         float64 `stm:"active_primary_shards" json:"active_primary_shards"`
   221  	ActiveShards                float64 `stm:"active_shards" json:"active_shards"`
   222  	RelocatingShards            float64 `stm:"relocating_shards" json:"relocating_shards"`
   223  	InitializingShards          float64 `stm:"initializing_shards" json:"initializing_shards"`
   224  	UnassignedShards            float64 `stm:"unassigned_shards" json:"unassigned_shards"`
   225  	DelayedUnassignedShards     float64 `stm:"delayed_unassigned_shards" json:"delayed_unassigned_shards"`
   226  	NumOfPendingTasks           float64 `stm:"number_of_pending_tasks" json:"number_of_pending_tasks"`
   227  	NumOfInFlightFetch          float64 `stm:"number_of_in_flight_fetch" json:"number_of_in_flight_fetch"`
   228  	ActiveShardsPercentAsNumber float64 `stm:"active_shards_percent_as_number" json:"active_shards_percent_as_number"`
   229  }
   230  
   231  type esClusterStats struct {
   232  	ClusterName string `json:"cluster_name"`
   233  	Nodes       struct {
   234  		Count struct {
   235  			Total               float64 `stm:"total"`
   236  			CoordinatingOnly    float64 `stm:"coordinating_only" json:"coordinating_only"`
   237  			Data                float64 `stm:"data"`
   238  			DataCold            float64 `stm:"data_cold" json:"data_cold"`
   239  			DataContent         float64 `stm:"data_content" json:"data_content"`
   240  			DataFrozen          float64 `stm:"data_frozen" json:"data_frozen"`
   241  			DataHot             float64 `stm:"data_hot" json:"data_hot"`
   242  			DataWarm            float64 `stm:"data_warm" json:"data_warm"`
   243  			Ingest              float64 `stm:"ingest"`
   244  			Master              float64 `stm:"master"`
   245  			ML                  float64 `stm:"ml"`
   246  			RemoteClusterClient float64 `stm:"remote_cluster_client" json:"remote_cluster_client"`
   247  			Transform           float64 `stm:"transform"`
   248  			VotingOnly          float64 `stm:"voting_only" json:"voting_only"`
   249  		} `stm:"count"`
   250  	} `stm:"nodes"`
   251  	Indices struct {
   252  		Count  float64 `stm:"count"`
   253  		Shards struct {
   254  			Total       float64 `stm:"total"`
   255  			Primaries   float64 `stm:"primaries"`
   256  			Replication float64 `stm:"replication"`
   257  		} `stm:"shards"`
   258  		Docs struct {
   259  			Count float64 `stm:"count"`
   260  		} `stm:"docs"`
   261  		Store struct {
   262  			SizeInBytes float64 `stm:"size_in_bytes" json:"size_in_bytes"`
   263  		} `stm:"store"`
   264  		QueryCache struct {
   265  			HitCount  float64 `stm:"hit_count" json:"hit_count"`
   266  			MissCount float64 `stm:"miss_count" json:"miss_count"`
   267  		} `stm:"query_cache" json:"query_cache"`
   268  	} `stm:"indices"`
   269  }
   270  
   271  type esIndexStats struct {
   272  	Index     string
   273  	Health    string
   274  	Rep       string
   275  	DocsCount string `json:"docs.count"`
   276  	StoreSize string `json:"store.size"`
   277  }