File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
core/src/main/scala/app/softnetwork/elastic/client/monitoring Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ package app .softnetwork .elastic .client .monitoring
2+
3+ import app .softnetwork .elastic .client .metrics .MetricsElasticClient
4+
5+ trait PrometheusExporter { self : MetricsElasticClient =>
6+
7+ def exportPrometheusMetrics : String = {
8+ val aggregated = getAggregatedMetrics
9+ val sb = new StringBuilder ()
10+
11+ // Global metrics
12+ sb.append(s " elasticsearch_operations_total ${aggregated.totalOperations}\n " )
13+ sb.append(s " elasticsearch_operations_success ${aggregated.successCount}\n " )
14+ sb.append(s " elasticsearch_operations_failure ${aggregated.failureCount}\n " )
15+ sb.append(s " elasticsearch_operations_duration_ms ${aggregated.totalDuration}\n " )
16+
17+ // Per-operation metrics
18+ aggregated.operationMetrics.foreach { case (op, m) =>
19+ sb.append(s """ elasticsearch_operation_total{operation=" $op"} ${m.totalOperations}""" + " \n " )
20+ sb.append(s """ elasticsearch_operation_duration_ms{operation=" $op"} ${m.totalDuration}""" + " \n " )
21+ sb.append(s """ elasticsearch_operation_success_rate{operation=" $op"} ${m.successRate}""" + " \n " )
22+ }
23+
24+ // Per-index metrics
25+ aggregated.indexMetrics.foreach { case (idx, m) =>
26+ sb.append(s """ elasticsearch_index_operations{index=" $idx"} ${m.totalOperations}""" + " \n " )
27+ sb.append(s """ elasticsearch_index_duration_ms{index=" $idx"} ${m.totalDuration}""" + " \n " )
28+ }
29+
30+ sb.toString()
31+ }
32+ }
33+
You can’t perform that action at this time.
0 commit comments