apache-ignite

Форк
0
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

16
from typing import NamedTuple
17

18
from ignitetest.utils.bean import Bean
19
from ignitetest.utils.version import V_2_7_6
20

21
METRICS_KEY = "metrics"
22

23
ENABLED = "enabled"
24

25
OPENCENSUS_TEMPLATE_FILE = "opencensus_metrics_beans_macro.j2"
26
OPENCENSUS_KEY_NAME = "opencensus"
27
OPENCENSUS_NAME = "OpencensusMetrics"
28

29
JMX_KEY_NAME = "jmx"
30

31

32
class OpencensusMetricsParams(NamedTuple):
33
    """
34
    Params for Opencensus metrics exporter.
35

36
    Attributes:
37
        period  period of metrics export in millisecs
38
        port    port of http server to export metrics
39
        name    params name
40
    """
41
    period: int
42
    port: int
43
    name: str
44

45

46
def is_opencensus_metrics_enabled(service):
47
    """
48
    Returns True if OpenCensus metrics exporter is enabled via globals
49

50
    :param service: Ignite service
51
    :return: bool
52
    """
53
    return service.config.version > V_2_7_6 and \
54
        METRICS_KEY in service.context.globals and \
55
        OPENCENSUS_KEY_NAME in service.context.globals[METRICS_KEY] and \
56
        service.context.globals[METRICS_KEY][OPENCENSUS_KEY_NAME].get(ENABLED, False)
57

58

59
def configure_opencensus_metrics(config, _globals, spec):
60
    """
61
    Adds 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
    """
67
    if config.metrics_update_frequency is None:
68
        config = config._replace(metrics_update_frequency=1000)
69

70
    metrics_params = __get_opencensus_metrics_params(_globals)
71
    config.metric_exporters.add(Bean("org.apache.ignite.spi.metric.opencensus.OpenCensusMetricExporterSpi",
72
                                     period=metrics_params.period,
73
                                     sendInstanceName=True))
74

75
    if not any("opencensus.metrics.port" in jvm_opt for jvm_opt in spec.jvm_opts):
76
        spec.jvm_opts.append("-Dopencensus.metrics.port=%d" % metrics_params.port)
77

78
    if not any(bean[0] == OPENCENSUS_TEMPLATE_FILE for bean in config.ext_beans):
79
        config.ext_beans.append((OPENCENSUS_TEMPLATE_FILE, metrics_params))
80

81
    return config
82

83

84
def __get_opencensus_metrics_params(_globals: dict):
85
    """
86
    Get OpenCensus metrics exporter parameters from Globals.
87

88
    :param _globals: Globals parameters
89
    :return: instance of the OpencensusMetricsParams
90
    """
91
    return OpencensusMetricsParams(period=_globals[METRICS_KEY][OPENCENSUS_KEY_NAME].get("period", 1000),
92
                                   port=_globals[METRICS_KEY][OPENCENSUS_KEY_NAME].get("port", 8082),
93
                                   name=OPENCENSUS_NAME)
94

95

96
def is_jmx_metrics_enabled(service):
97
    """
98
    Returns True if JMX metrics exporter is enabled via globals
99

100
    :param service: Ignite service
101
    :return: bool
102
    """
103
    return service.config.version > V_2_7_6 and \
104
        METRICS_KEY in service.context.globals and \
105
        JMX_KEY_NAME in service.context.globals[METRICS_KEY] and \
106
        service.context.globals[METRICS_KEY][JMX_KEY_NAME].get(ENABLED, False)
107

108

109
def configure_jmx_metrics(config):
110
    """
111
    Adds 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
    """
116
    if config.metrics_update_frequency is None:
117
        config = config._replace(metrics_update_frequency=1000)
118

119
    config.metric_exporters.add("org.apache.ignite.spi.metric.jmx.JmxMetricExporterSpi")
120

121
    return config
122

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.