<commit_before>"""Prometheus for Gauge."""

# Copyright (C) 2015 Research and Education Advanced Network New Zealand Ltd.
# Copyright (C) 2015--2017 The Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from prometheus_client import Gauge as PromGauge # avoid collision

from faucet.gauge_pollers import GaugePortStatsPoller
from faucet.prom_client import PromClient


PROM_PREFIX_DELIM = '_'
PROM_PORT_PREFIX = 'of_port'
PROM_PORT_VARS = (
    'tx_packets',
    'rx_packets',
    'tx_bytes',
    'rx_bytes',
    'tx_dropped',
    'rx_dropped',
    'rx_errors')


class GaugePrometheusClient(PromClient):
    """Wrapper for Prometheus client that is shared between all pollers."""

    metrics = {}

    def __init__(self):
        super(GaugePrometheusClient, self).__init__()
        self.dp_status = PromGauge(
            'dp_status',
            'status of datapaths',
            self.REQUIRED_LABELS)
        for prom_var in PROM_PORT_VARS:
            exported_prom_var = PROM_PREFIX_DELIM.join(
                (PROM_PORT_PREFIX, prom_var))
            self.metrics[exported_prom_var] = PromGauge(
                exported_prom_var, '', self.REQUIRED_LABELS + ['port_name'])<commit_msg>Add flow counters for Gauge Prometheus.<commit_after>"""Prometheus for Gauge."""

# Copyright (C) 2015 Research and Education Advanced Network New Zealand Ltd.
# Copyright (C) 2015--2017 The Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from prometheus_client import Gauge as PromGauge # avoid collision

from faucet.valve_of import MATCH_FIELDS
from faucet.gauge_pollers import GaugePortStatsPoller
from faucet.prom_client import PromClient


PROM_PREFIX_DELIM = '_'
PROM_PORT_PREFIX = 'of_port'
PROM_PORT_VARS = (
    'tx_packets',
    'rx_packets',
    'tx_bytes',
    'rx_bytes',
    'tx_dropped',
    'rx_dropped',
    'rx_errors')
PROM_FLOW_VARS = (
    'flow_byte_count',
    'flow_packet_count'
)


class GaugePrometheusClient(PromClient):
    """Wrapper for Prometheus client that is shared between all pollers."""

    metrics = {}

    def __init__(self):
        super(GaugePrometheusClient, self).__init__()
        self.dp_status = PromGauge(
            'dp_status',
            'status of datapaths',
            self.REQUIRED_LABELS)
        for prom_var in PROM_PORT_VARS:
            exported_prom_var = PROM_PREFIX_DELIM.join(
                (PROM_PORT_PREFIX, prom_var))
            self.metrics[exported_prom_var] = PromGauge(
                exported_prom_var, '', self.REQUIRED_LABELS + ['port_name'])
        flow_labels = (
            self.REQUIRED_LABELS +
            ['table_id', 'priority', 'inst_count'] +
            list(MATCH_FIELDS.keys()))
        for prom_var in PROM_FLOW_VARS:
            self.metrics[prom_var] = PromGauge(
                prom_var, '', flow_labels)
{'fraction_non_alphanumeric': 0.08670671193523113, 'fraction_numerical': 0.00835727343954035, 'mean_word_length': 3.298540965207632, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1960131', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1137, 'n_words': 347}