apache-ignite
121 строка · 4.2 Кб
1# Licensed to the Apache Software Foundation (ASF) under one or more
2# contributor license agreements. See the NOTICE file distributed with
3# this work for additional information regarding copyright ownership.
4# The ASF licenses this file to You under the Apache License, Version 2.0
5# (the "License"); you may not use this file except in compliance with
6# the License. You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License
15
16from typing import NamedTuple17
18from ignitetest.utils.bean import Bean19from ignitetest.utils.version import V_2_7_620
21METRICS_KEY = "metrics"22
23ENABLED = "enabled"24
25OPENCENSUS_TEMPLATE_FILE = "opencensus_metrics_beans_macro.j2"26OPENCENSUS_KEY_NAME = "opencensus"27OPENCENSUS_NAME = "OpencensusMetrics"28
29JMX_KEY_NAME = "jmx"30
31
32class OpencensusMetricsParams(NamedTuple):33"""34Params for Opencensus metrics exporter.
35
36Attributes:
37period period of metrics export in millisecs
38port port of http server to export metrics
39name params name
40"""
41period: int42port: int43name: str44
45
46def is_opencensus_metrics_enabled(service):47"""48Returns True if OpenCensus metrics exporter is enabled via globals
49
50:param service: Ignite service
51:return: bool
52"""
53return service.config.version > V_2_7_6 and \54METRICS_KEY in service.context.globals and \55OPENCENSUS_KEY_NAME in service.context.globals[METRICS_KEY] and \56service.context.globals[METRICS_KEY][OPENCENSUS_KEY_NAME].get(ENABLED, False)57
58
59def configure_opencensus_metrics(config, _globals, spec):60"""61Adds OpenCensus metrics exporter beans into the Ignite node configuration
62
63:param config: config object to be modified
64:param _globals: Globals parameters
65:return: the updated configuration object
66"""
67if config.metrics_update_frequency is None:68config = config._replace(metrics_update_frequency=1000)69
70metrics_params = __get_opencensus_metrics_params(_globals)71config.metric_exporters.add(Bean("org.apache.ignite.spi.metric.opencensus.OpenCensusMetricExporterSpi",72period=metrics_params.period,73sendInstanceName=True))74
75if not any("opencensus.metrics.port" in jvm_opt for jvm_opt in spec.jvm_opts):76spec.jvm_opts.append("-Dopencensus.metrics.port=%d" % metrics_params.port)77
78if not any(bean[0] == OPENCENSUS_TEMPLATE_FILE for bean in config.ext_beans):79config.ext_beans.append((OPENCENSUS_TEMPLATE_FILE, metrics_params))80
81return config82
83
84def __get_opencensus_metrics_params(_globals: dict):85"""86Get OpenCensus metrics exporter parameters from Globals.
87
88:param _globals: Globals parameters
89:return: instance of the OpencensusMetricsParams
90"""
91return OpencensusMetricsParams(period=_globals[METRICS_KEY][OPENCENSUS_KEY_NAME].get("period", 1000),92port=_globals[METRICS_KEY][OPENCENSUS_KEY_NAME].get("port", 8082),93name=OPENCENSUS_NAME)94
95
96def is_jmx_metrics_enabled(service):97"""98Returns True if JMX metrics exporter is enabled via globals
99
100:param service: Ignite service
101:return: bool
102"""
103return service.config.version > V_2_7_6 and \104METRICS_KEY in service.context.globals and \105JMX_KEY_NAME in service.context.globals[METRICS_KEY] and \106service.context.globals[METRICS_KEY][JMX_KEY_NAME].get(ENABLED, False)107
108
109def configure_jmx_metrics(config):110"""111Adds JMX metrics exporter bean into the Ignite node configuration
112
113:param config: configuration object to be modified
114:return: the updated configuration object
115"""
116if config.metrics_update_frequency is None:117config = config._replace(metrics_update_frequency=1000)118
119config.metric_exporters.add("org.apache.ignite.spi.metric.jmx.JmxMetricExporterSpi")120
121return config122