Пример #1
0
    def metrics(self):
        metrics = {
            "rtt":
            GaugeMetricFamily(
                "sockpuppet_tcp_rtt",
                "The smooth round trip time of delays between sent packets "
                "and received ACK",
                labels=self.metric_definitions["rtt"].label_names),
            "rcv_rtt":
            GaugeMetricFamily(
                "sockpuppet_tcp_rcv_rtt",
                "Time to receive one full window",
                labels=self.metric_definitions["rcv_rtt"].label_names),
            "bytes_acked":
            CounterMetricFamily(
                "sockpuppet_tcp_bytes_acked",
                "Number of bytes that have been sent and acknowledged",
                labels=self.metric_definitions["bytes_acked"].label_names),
            "bytes_received":
            CounterMetricFamily(
                "sockpuppet_tcp_bytes_received",
                "Number of bytes that have been received",
                labels=self.metric_definitions["bytes_received"].label_names),

            # https://github.com/torvalds/linux/commit/cd9b266095f422267bddbec88f9098b48ea548fc,  # noqa
            "notsent_bytes":
            GaugeMetricFamily(
                "sockpuppet_tcp_notsent_bytes",
                "the amount of bytes in the write queue that were not yet "
                "sent. This is only likely to work with a linux >= 4.6.",
                labels=self.metric_definitions["notsent_bytes"].label_names),

            # idiag_tmem, see: man sock_diag
            "tmem":
            GaugeMetricFamily(
                "sockpuppet_tcp_tmem_bytes",
                "The amount of data in send queue",
                labels=self.metric_definitions["tmem"].label_names),

            # idiag_wmem
            "wmem":
            GaugeMetricFamily(
                "sockpuppet_tcp_wmem_bytes",
                "The amount of data that is queued by TCP"
                "but not yet sent.",
                labels=self.metric_definitions["wmem"].label_names),
        }
        return metrics
    def collect(self):
        """
        collect method collects the command output from device and
        return the metrics
        """
        self._device.enable_test_commands()
        output = self._device.exec('vppctl "show errors verbose"')
        rows = self._parser.ParseText(output)

        if not rows:
            return []

        metrics = [
            CounterMetricFamily(
                "epc_vppctl_thread_errors_count",
                "vppctl error counts by thread.",
                labels=["thread", "function", "node", "reason", "index"]),
            CounterMetricFamily("epc_vppctl_total_errors_count",
                                "vppctl total error counts.",
                                labels=["node", "reason", "index"])
        ]

        thread_err_count_metrics = metrics[0]
        for row in rows[:-1]:
            thread_id = row[FIELD_THREAD_ID]
            thread_name = row[FIELD_THREAD_NAME]
            for node, reason, index, count in zip(row[FIELD_NODE],
                                                  row[FIELD_ERROR_REASON],
                                                  row[FIELD_INDEX],
                                                  row[FIELD_ERROR_COUNT]):
                add_gauge_metrics(
                    thread_err_count_metrics,
                    [thread_id, thread_name, node, reason, index],
                    float(count))

        total_err_count_metrics = metrics[1]
        row = rows[-1]
        for node, reason, index, count in zip(row[FIELD_NODE],
                                              row[FIELD_ERROR_REASON],
                                              row[FIELD_INDEX],
                                              row[FIELD_ERROR_COUNT]):
            add_gauge_metrics(total_err_count_metrics, [node, reason, index],
                              float(count))
        return metrics
Пример #3
0
 def channel_metric(self, channel: ChannelValue, meter_id: str,
                    meter_name: str,
                    epochtime: float) -> tp.Iterator[Metric]:
     # Create metrics based on OBIS codes
     if channel.unit is not None:
         if "W" in channel.unit and "1-0:16.7.0*255" in channel.channel_name:
             power_consumption = GaugeMetricFamily(
                 METRICS_PREFIX + "power_consumption_watts",
                 "Momentary power consumption in watts.",
                 labels=["meter_id", "meter_name"],
             )
             power_consumption.add_metric([meter_id, meter_name],
                                          channel.value,
                                          timestamp=epochtime)
             yield power_consumption
         elif "Wh" in channel.unit:
             match = re.fullmatch(
                 r"1-0:(?P<type_id>1|2)\.8\.(?P<tariff_id>0|1|2)\*255",
                 channel.channel_name)
             if match is not None:
                 # Adhere to Prometheus unit convention
                 # Watt Hours * 3600 Seconds/Hour == Watt Seconds == Joules
                 joules = channel.value * 3600
                 if match.groupdict()["type_id"] == "1":
                     energy_type = "consumption"
                 else:
                     energy_type = "export"
                 if match.groupdict()["tariff_id"] == 1:
                     tariff_id = "1"
                 elif match.groupdict()["tariff_id"] == 2:
                     tariff_id = "2"
                 else:
                     tariff_id = "aggregated"
                 energy = CounterMetricFamily(
                     METRICS_PREFIX + f"energy_{energy_type}_joules_total",
                     f"Energy {energy_type} in joules",
                     labels=["meter_id", "meter_name", "tariff"],
                 )
                 energy.add_metric([meter_id, meter_name, tariff_id],
                                   joules,
                                   timestamp=epochtime)
                 yield energy
     yield from ()
def collect_metrics_from_page(driver):
    result = parse_page(driver)

    for key, value in result.items():
        metric = MAP_METRICS.get(key)
        if metric is not None:
            name = 'wemportal_' + metric['name']
            t = metric.get('type', 'gauge')
            if t is 'gauge':
                value = parse_value(value, metric.get('strip'))
                yield GaugeMetricFamily(name, key, value=value)
            if t is 'counter':
                value = parse_value(value, metric.get('strip'))
                yield CounterMetricFamily(name, key, value=value)
            if t is 'info':
                yield InfoMetricFamily(name, key, value={'value': value})
Пример #5
0
    def extract(self, raw_xmls: Dict[int, bytes]) -> Iterable[Metric]:
        assert len(raw_xmls) == 1

        CHANNEL_ID = "channel_id"
        TIMEOUT_TYPE = "timeout_type"

        us_frequency = GaugeMetricFamily(
            "connectbox_upstream_frequency",
            "Upstream channel frequency",
            unit="hz",
            labels=[CHANNEL_ID],
        )
        us_power_level = GaugeMetricFamily(
            "connectbox_upstream_power_level",
            "Upstream channel power level",
            unit="dbmv",
            labels=[CHANNEL_ID],
        )
        us_symbol_rate = GaugeMetricFamily(
            "connectbox_upstream_symbol_rate",
            "Upstream channel symbol rate",
            unit="ksps",
            labels=[CHANNEL_ID],
        )
        us_timeouts = CounterMetricFamily(
            "connectbox_upstream_timeouts",
            "Upstream channel timeout occurrences",
            labels=[CHANNEL_ID, TIMEOUT_TYPE],
        )
        root = etree.fromstring(raw_xmls[GET.UPSTREAM_TABLE],
                                parser=self._parsers[GET.UPSTREAM_TABLE])
        for channel in root.findall("upstream"):
            channel_id = channel.find("usid").text

            frequency = int(channel.find("freq").text)
            power_level = float(channel.find("power").text)
            symbol_rate = float(channel.find("srate").text)
            t1_timeouts = int(channel.find("t1Timeouts").text)
            t2_timeouts = int(channel.find("t2Timeouts").text)
            t3_timeouts = int(channel.find("t3Timeouts").text)
            t4_timeouts = int(channel.find("t4Timeouts").text)

            labels = [channel_id.zfill(2)]
            us_frequency.add_metric(labels, frequency)
            us_power_level.add_metric(labels, power_level)
            us_symbol_rate.add_metric(labels, symbol_rate)
            us_timeouts.add_metric(labels + ["T1"], t1_timeouts)
            us_timeouts.add_metric(labels + ["T2"], t2_timeouts)
            us_timeouts.add_metric(labels + ["T3"], t3_timeouts)
            us_timeouts.add_metric(labels + ["T4"], t4_timeouts)
        yield from [us_frequency, us_power_level, us_symbol_rate, us_timeouts]
Пример #6
0
 def channel_metric(self, channel: ChannelValue, meter_id: str, meter_name: str, epochtime: float) -> tp.Iterator[
     Metric]:
     if channel.unit is not None:
         if "kWh" in channel.unit and "6.8" in channel.channel_name:
             # Adhere to Prometheus unit convention
             # Watt Hours * 3600 Seconds/Hour == Watt Seconds == Joules
             joules = channel.value * 3600
             energy = CounterMetricFamily(
                 METRICS_PREFIX + "energy_consumption_joules",
                 "Energy consumption in joules",
                 labels=["meter_id", "meter_name"],
             )
             energy.add_metric([meter_id, meter_name], joules, timestamp=epochtime)
             yield energy
         if "m3" in channel.unit and "6.26" in channel.channel_name:
             volume = CounterMetricFamily(
                 METRICS_PREFIX + "flow_volume_cubic_meters",
                 "Flow volume in cubic meters",
                 labels=["meter_id", "meter_name"],
             )
             volume.add_metric([meter_id, meter_name], channel.value, timestamp=epochtime)
             yield volume
     yield from ()
Пример #7
0
    def collect(self):
        #metric_desc = (config["metrics"][k]).get("description", "no Description for query")
        a = CounterMetricFamily(name="failed_calls",
                                documentation="number of failed tasks",
                                labels=[])
        a.add_metric(value=str(EXECUTE_COMMAND.failed_task_starts), labels=[])
        f = CounterMetricFamily(name="am_alert_failed_calls",
                                documentation="all failed calls",
                                labels=["command_name"])
        for key, value in EXECUTE_COMMAND.failed_calls.items():
            f.add_metric(value=str(value), labels=[key])
        yield f

        g = CounterMetricFamily(name="am_alert_calls",
                                documentation="all successful calls",
                                labels=["command_name"])
        for key, value in EXECUTE_COMMAND.calls.items():
            g.add_metric(value=str(value), labels=[key])
        yield g
Пример #8
0
    def extract(self, raw_xmls: Dict[int, bytes]) -> Iterable[Metric]:
        assert len(raw_xmls) == 2

        # DOWNSTREAM_TABLE gives us frequency, power level, SNR and RxMER per channel
        root = etree.fromstring(raw_xmls[GET.DOWNSTREAM_TABLE],
                                parser=self._parsers[GET.DOWNSTREAM_TABLE])

        CHANNEL_ID = "channel_id"
        ds_frequency = GaugeMetricFamily(
            "connectbox_downstream_frequency",
            "Downstream channel frequency",
            unit="hz",
            labels=[CHANNEL_ID],
        )
        ds_power_level = GaugeMetricFamily(
            "connectbox_downstream_power_level",
            "Downstream channel power level",
            unit="dbmv",
            labels=[CHANNEL_ID],
        )
        ds_snr = GaugeMetricFamily(
            "connectbox_downstream_snr",
            "Downstream channel signal-to-noise ratio (SNR)",
            unit="db",
            labels=[CHANNEL_ID],
        )
        ds_rxmer = GaugeMetricFamily(
            "connectbox_downstream_rxmer",
            "Downstream channel receive modulation error ratio (RxMER)",
            unit="db",
            labels=[CHANNEL_ID],
        )
        for channel in root.findall("downstream"):
            channel_id = channel.find("chid").text
            frequency = int(channel.find("freq").text)
            power_level = int(channel.find("pow").text)
            snr = int(channel.find("snr").text)
            rxmer = float(channel.find("RxMER").text)

            labels = [channel_id.zfill(2)]
            ds_frequency.add_metric(labels, frequency)
            ds_power_level.add_metric(labels, power_level)
            ds_snr.add_metric(labels, snr)
            ds_rxmer.add_metric(labels, rxmer)
        yield from [ds_frequency, ds_power_level, ds_snr, ds_rxmer]

        # SIGNAL_TABLE gives us unerrored, corrected and uncorrectable errors per channel
        root = etree.fromstring(raw_xmls[GET.SIGNAL_TABLE],
                                parser=self._parsers[GET.SIGNAL_TABLE])

        ds_unerrored_codewords = CounterMetricFamily(
            "connectbox_downstream_codewords_unerrored",
            "Unerrored downstream codewords",
            labels=[CHANNEL_ID],
        )
        ds_correctable_codewords = CounterMetricFamily(
            "connectbox_downstream_codewords_corrected",
            "Corrected downstream codewords",
            labels=[CHANNEL_ID],
        )
        ds_uncorrectable_codewords = CounterMetricFamily(
            "connectbox_downstream_codewords_uncorrectable",
            "Uncorrectable downstream codewords",
            labels=[CHANNEL_ID],
        )
        for channel in root.findall("signal"):
            channel_id = channel.find("dsid").text
            unerrored = int(channel.find("unerrored").text)
            correctable = int(channel.find("correctable").text)
            uncorrectable = int(channel.find("uncorrectable").text)

            labels = [channel_id.zfill(2)]
            ds_unerrored_codewords.add_metric(labels, unerrored)
            ds_correctable_codewords.add_metric(labels, correctable)
            ds_uncorrectable_codewords.add_metric(labels, uncorrectable)
        yield from [
            ds_unerrored_codewords,
            ds_correctable_codewords,
            ds_uncorrectable_codewords,
        ]
Пример #9
0
import time

from prometheus_client import start_wsgi_server, Counter
from prometheus_client.metrics_core import CounterMetricFamily

counter = Counter('demo', 'demo')

if __name__ == '__main__':
    start_wsgi_server(8087, '0.0.0.0')
    i = 0
    while 1:
        i += 1
        time.sleep(1)
        print(f'i = {i}')
        CounterMetricFamily('demo', 'demo', i)
Пример #10
0
    def collect(self):
        collected = CounterMetricFamily(
            f"{self.namespace}python_gc_objects_collected",
            "Objects collected during gc",
            labels=["generation"],
        )
        uncollectable = CounterMetricFamily(
            f"{self.namespace}python_gc_objects_uncollectable",
            "Uncollectable object found during GC",
            labels=["generation"],
        )

        collections = CounterMetricFamily(
            f"{self.namespace}python_gc_collections",
            "Number of times this generation was collected",
            labels=["generation"],
        )

        for generation, stat in enumerate(gc.get_stats()):
            generation = str(generation)
            collected.add_metric([generation], value=stat["collected"])
            uncollectable.add_metric([generation], value=stat["uncollectable"])
            collections.add_metric([generation], value=stat["collections"])

        return [collected, uncollectable, collections]
 def counter(self, name, value, help):
     c = CounterMetricFamily(name, help, labels=self._labels)
     c.add_metric(self._labels_values, value)
     return c        
Пример #12
0
def _player_stats_metrics() -> Dict[str, CounterMetricFamily]:
    return {
        "mined":
        CounterMetricFamily(
            name="mc_player_mined",
            documentation="The number of times the player mined an item",
            labels=("player", "mod", "item"),
        ),
        "broken":
        CounterMetricFamily(
            name="mc_player_broken",
            documentation="The number of times the player broke an item",
            labels=("player", "mod", "item"),
        ),
        "crafted":
        CounterMetricFamily(
            name="mc_player_crafted",
            documentation="The number of times the player crafted an item",
            labels=("player", "mod", "item"),
        ),
        "used":
        CounterMetricFamily(
            name="mc_player_used",
            documentation="The number of times the player used an item",
            labels=("player", "mod", "item"),
        ),
        "picked_up":
        CounterMetricFamily(
            name="mc_player_picked_up",
            documentation="The number of times the player picked up an item",
            labels=("player", "mod", "item"),
        ),
        "dropped":
        CounterMetricFamily(
            name="mc_player_dropped",
            documentation="The number of times the player dropped an item",
            labels=("player", "mod", "item"),
        ),
        "killed":
        CounterMetricFamily(
            name="mc_player_entity_killed",
            documentation="The number of times the player killed an entity",
            labels=("player", "mod", "entity"),
        ),
        "mob_kills":
        CounterMetricFamily(
            name="mc_player_mob_kills",
            documentation="The number of mobs the player killed",
            labels=("player", ),
        ),
        "killed_by":
        CounterMetricFamily(
            name="mc_player_killed_by",
            documentation=
            "The number of times the player being killed by entities",
            labels=("player", "mod", "entity"),
        ),
        "animals_bred":
        CounterMetricFamily(
            name="mc_player_animals_bred",
            documentation="The number of times the player bred two mobs",
            labels=("player", ),
        ),
        "clean":
        CounterMetricFamily(
            name="mc_player_item_cleaned",
            documentation="	The number of item washed with a cauldron",
            labels=("player", "item"),
        ),
        "interact":
        CounterMetricFamily(
            name="mc_player_interacted",
            documentation=
            "The number of times the player interact with something (barrel, chest, table, villager, etc...)",
            labels=("player", "with"),
        ),
        "fill_cauldron":
        CounterMetricFamily(
            name="mc_player_cauldron_filled",
            documentation=
            "The number of times the player filled cauldrons with water buckets",
            labels=("player", ),
        ),
        "damage_absorbed":
        CounterMetricFamily(
            name="mc_player_damage_absorbed",
            documentation=
            "The amount of damage the player has absorbed in tenths of 1",
            labels=("player", ),
        ),
        "damage_blocked_by_shield":
        CounterMetricFamily(
            name="mc_player_damage_blocked_by_shield",
            documentation=
            "The amount of damage the player has blocked with a shield in tenths of 1",
            labels=("player", ),
        ),
        "damage_dealt":
        CounterMetricFamily(
            name="mc_player_damage_dealt",
            documentation=
            "The amount of damage the player has dealt in tenths 1. Includes only melee attacks",
            labels=("player", ),
        ),
        "damage_dealt_absorbed":
        CounterMetricFamily(
            name="mc_player_damage_dealt_absorbed",
            documentation=
            "The amount of damage the player has dealt that were absorbed, in tenths of 1",
            labels=("player", ),
        ),
        "damage_dealt_resisted":
        CounterMetricFamily(
            name="mc_player_damage_dealt_resisted",
            documentation=
            "The amount of damage the player has dealt that were resisted, in tenths of 1",
            labels=("player", ),
        ),
        "damage_resisted":
        CounterMetricFamily(
            name="mc_player_damage_resisted",
            documentation=
            "The amount of damage the player has resisted in tenths of 1",
            labels=("player", ),
        ),
        "damage_taken":
        CounterMetricFamily(
            name="mc_player_damage_taken",
            documentation=
            "The amount of damage the player has taken in tenths of 1",
            labels=("player", ),
        ),
        "distance":
        CounterMetricFamily(
            name="mc_player_distance",
            documentation=
            "The total distance traveled (walk, fall, swim, pig, etc...)",
            labels=("player", "by"),
        ),
        "fish_caught":
        CounterMetricFamily(
            name="mc_player_fish_caught",
            documentation="The number of fish caught",
            labels=("player", ),
        ),
        "leave_game":
        CounterMetricFamily(
            name="mc_player_leave_game",
            documentation=
            "The number of times 'Save and quit to title' has been clicked",
            labels=("player", ),
        ),
        "enchant_item":
        CounterMetricFamily(
            name="mc_player_item_enchanted",
            documentation="The number of items enchanted",
            labels=("player", ),
        ),
        "jump":
        CounterMetricFamily(
            name="mc_player_jump",
            documentation="The total number of jumps performed",
            labels=("player", ),
        ),
        "play_record":
        CounterMetricFamily(
            name="mc_player_record_played",
            documentation="The number of music discs played on a jukebox",
            labels=("player", ),
        ),
        "play_noteblock":
        CounterMetricFamily(
            name="mc_player_noteblock_played",
            documentation="The number of note blocks hit",
            labels=("player", ),
        ),
        "tune_noteblock":
        CounterMetricFamily(
            name="mc_player_noteblock_tuned",
            documentation="The number of times interacted with note blocks",
            labels=("player", ),
        ),
        "deaths":
        CounterMetricFamily(
            name="mc_player_deaths",
            documentation="The number of times the player died",
            labels=("player", ),
        ),
        "pot_flower":
        CounterMetricFamily(
            name="mc_player_plants_potted",
            documentation="The number of plants potted onto flower pots",
            labels=("player", ),
        ),
        "player_kills":
        CounterMetricFamily(
            name="mc_player_killed_players",
            documentation=
            "The number of players the player killed (on PvP servers). Indirect kills do not count",
            labels=("player", ),
        ),
        "raid_trigger":
        CounterMetricFamily(
            name="mc_player_triggered_raid",
            documentation="The number of times the player has triggered a Raid",
            labels=("player", ),
        ),
        "raid_win":
        CounterMetricFamily(
            name="mc_player_won_raid",
            documentation="The number of times the player has won a Raid",
            labels=("player", ),
        ),
        "target_hit":
        CounterMetricFamily(
            name="mc_player_hit_target",
            documentation=
            "The number of times the player has shot a target block",
            labels=("player", ),
        ),
        "time":
        CounterMetricFamily(
            name="mc_player_time_spend",
            documentation=
            "The total amount of time in sec [since death, since rest, played, sneak])",
            labels=("player", "action"),
        ),
        "sleep_in_bed":
        CounterMetricFamily(
            name="mc_player_slept_in_bed",
            documentation="The number of times the player has slept in a bed",
            labels=("player", ),
        ),
        "traded_with_villager":
        CounterMetricFamily(
            name="mc_player_traded_with_villager",
            documentation="The number of times traded with villagers",
            labels=("player", ),
        ),
        "use_cauldron":
        CounterMetricFamily(
            name="mc_player_used_cauldron",
            documentation=
            "The number of times the player took water from cauldrons with glass bottles",
            labels=("player", ),
        ),
    }
Пример #13
0
    def collect(self):
        logger.info('Collecting data')

        channel_id = GaugeMetricFamily('docsis_channel_id',
                                       'Channel ID',
                                       labels=['direction', 'index'])
        channel_carrier = GaugeMetricFamily('docsis_channel_carrier_mhz',
                                            'Channel carrier frequency',
                                            labels=['direction', 'index'])
        channel_power_level = GaugeMetricFamily(
            'docsis_channel_power_level_dbmv',
            'Channel power level',
            labels=['direction', 'index'])
        channel_mse = GaugeMetricFamily('docsis_channel_mse_db',
                                        'Channel mean squared error (MSE)',
                                        labels=['direction', 'index'])
        channel_latency = GaugeMetricFamily('docsis_channel_latency_ms',
                                            'Channel latency',
                                            labels=['direction', 'index'])
        channel_correctable_errors = CounterMetricFamily(
            'docsis_channel_correctable_errors',
            'Number of correctable errors',
            labels=['direction', 'index'])
        channel_uncorrectable_errors = CounterMetricFamily(
            'docsis_channel_uncorrectable_errors',
            'Number of uncorrectable errors',
            labels=['direction', 'index'])

        # Handle 403 here
        rx, tx = self._session.docsis_info()

        for rx_channel in rx:
            rx_channel_idx = rx_channel['channel']
            rx_channel_id = rx_channel['channelID']
            rx_channel_carrier = rx_channel['frequency']  # MHz
            # rx_channel_modulation = rx_channel[2]
            rx_channel_power_level = rx_channel['powerLevel']  # dBmV
            rx_channel_mse = rx_channel['mse']  # dB
            rx_channel_latency = rx_channel['latency']  # ms
            rx_channel_correctable_errors = rx_channel['corrErrors']
            rx_channel_uncorrectable_errors = rx_channel['nonCorrErrors']

            labels = ['rx', str(rx_channel_idx)]
            channel_id.add_metric(labels, int(rx_channel_id))
            channel_carrier.add_metric(labels, float(rx_channel_carrier))
            channel_power_level.add_metric(labels,
                                           float(rx_channel_power_level))
            channel_mse.add_metric(labels, float(rx_channel_mse))
            channel_latency.add_metric(labels, float(rx_channel_latency))
            channel_correctable_errors.add_metric(
                labels, int(rx_channel_correctable_errors))
            channel_uncorrectable_errors.add_metric(
                labels, int(rx_channel_uncorrectable_errors))

        for tx_channel in tx:
            tx_channel_idx = tx_channel['channel']
            tx_channel_id = tx_channel['channelID']
            tx_channel_carrier = tx_channel['frequency']  # MHz
            # tx_channel_modulation = tx_channel[2]
            # tx_channel_multiplexing_scheme = tx_channel[3]
            tx_channel_power_level = tx_channel['powerLevel']  # dBmV

            labels = ['tx', str(tx_channel_idx)]
            channel_id.add_metric(labels, int(tx_channel_id))
            channel_carrier.add_metric(labels, float(tx_channel_carrier))
            channel_power_level.add_metric(labels,
                                           float(tx_channel_power_level))

        yield channel_id
        yield channel_carrier
        yield channel_power_level
        yield channel_mse
        yield channel_latency
        yield channel_correctable_errors
        yield channel_uncorrectable_errors