Пример #1
0
    def info_metrics(self):
        """
        Return a list of information tags for the PV Supervisor
        """
        network_status = self.communication_interfaces
        interface_info = InfoMetricFamily(
            name="sunpower_pvs_communication_interface",
            documentation="Communications Interface Information",
        )

        for comm in network_status.get("interfaces", []):
            value = dict(interface=comm["interface"],
                         internet=comm["internet"],
                         sms=comm["sms"],
                        )
            interface_info.add_metric(labels=[], value=value)

        grid_profile = self.grid_profile
        value = None
        if grid_profile:
            value = dict(id=grid_profile["active_id"],
                         name=grid_profile["active_name"],
                         percent=str(grid_profile["percent"]),
                         status=grid_profile["status"],
                        )
        grid_info = InfoMetricFamily(
            name="sunpower_pvs_grid_profile",
            documentation="Grid Profile",
            value=value,
        )

        return [dict(key="interface_info", metric=interface_info),
                dict(key="grid_profile", metric=grid_info)
               ]
Пример #2
0
    def _process_info(data: Union[Dict, List[Dict]],
                      label: str) -> List[InfoMetricFamily]:
        i = InfoMetricFamily(f'patroni_{label}', f'{label} info')

        # to ensure we have an iterable of dicts
        # the info datasets are different, some are lists of dicts,
        # some are dict only
        if not isinstance(data, (list, tuple)):
            data = [data]

        for dataset in data:
            i.add_metric([], {k: str(v) for k, v in dataset.items()})
        return [i]
Пример #3
0
	def collect(self, describing=False):
		if not describing: 
			cli = CoAPAirClient(self.ip)
			status = cli.get_status()

			if "name" not in status:
				return
			labels = [self.ip, status["name"]]

		label_names = ["device_hostname", "name"]

		device_info = InfoMetricFamily('air_purifier_device_info', 'Air Purifier Device Information', labels=label_names)
		if not describing:
			device_info.add_metric(labels, {
				"type": status["type"],
				"mode": status["mode"],
				"model": status["modelid"],
				"software_version": status["swversion"],
				"wifi_version": status["WifiVersion"],
				"product_id": status["ProductId"],
				"device_id": status["DeviceId"],
				"status_type": status["StatusType"],
				"connect_type": status["ConnectType"],
			})
		yield device_info

		def gauge(name, desc, field_name, xfrm=lambda x: x):
			if not describing and field_name not in status:
				return None
			g = GaugeMetricFamily("air_purifier_" + name, "Air Purifiier " + desc, labels=label_names)
			if not describing:
				g.add_metric(labels, xfrm(status[field_name]))
			yield g

		yield from gauge("runtime", "running time", "runtime", lambda x: x/1000)
		yield from gauge("on", "powered on", "pwr")

		def fan_speed_xfrm(om):
			if om == "s":
				fan_speed = 0
			elif om == "t":
				fan_speed = 9
			else:
				fan_speed = int(om)
			return fan_speed
		yield from gauge("fan_speed", "fan speed setting", "om", fan_speed_xfrm)
		yield from gauge("pm25", "PM 2.5 level ug/m3","pm25")
		yield from gauge("iaql", "Indoor Air Quality Index", "iaql")
		yield from gauge("pre_filter_time_til_clean", "Pre filter hours remaining", "fltsts0")
		yield from gauge("hepa_filter_time_til_replace", "Pre filter hours remaining", "fltsts1")
		yield from gauge("carbon_filter_time_til_replace", "Carbon filter hours remaining", "fltsts2")
Пример #4
0
    def collect_bgp(self):
        command = 'show ip bgp summary'
        data = self.switch_command(command)
        ipv4 = data['result'][0]['vrfs']
        command = 'show ipv6 bgp summary'
        data = self.switch_command(command)
        ipv6 = data['result'][0]['vrfs']

        labels = ['vrf', 'peer', 'asn']
        prefixes = GaugeMetricFamily('arista_bgp_accepted_prefixes',
                                     'Number of prefixes accepted',
                                     labels=labels)
        peer_state = InfoMetricFamily('arista_bgp_peer_state',
                                      'State of the BGP peer',
                                      labels=labels + ['state', 'router_id'])

        for vrf, vrf_data in ipv4.items():
            if 'peers' not in vrf_data:
                continue
            router_id = vrf_data['routerId']
            for peer, peer_data in vrf_data['peers'].items():
                labels = {
                    'vrf': vrf,
                    'router_id': router_id,
                    'peer': peer,
                    'asn': str(peer_data['asn']),
                    'state': peer_data['peerState']
                }
                peer_state.add_metric(value=labels, labels=labels)
                labels = [vrf, peer, str(peer_data['asn'])]
                prefixes.add_metric(value=peer_data['prefixReceived'],
                                    labels=labels)
        for vrf, vrf_data in ipv6.items():
            if 'peers' not in vrf_data:
                continue
            router_id = vrf_data['routerId']
            for peer, peer_data in vrf_data['peers'].items():
                labels = {
                    'vrf': vrf,
                    'router_id': router_id,
                    'peer': peer,
                    'asn': str(peer_data['asn']),
                    'state': peer_data['peerState']
                }
                peer_state.add_metric(value=labels, labels=labels)
                labels = [vrf, peer, str(peer_data['asn'])]
                prefixes.add_metric(value=peer_data['prefixReceived'],
                                    labels=labels)
        yield peer_state
        yield prefixes
    def get_info_metrics(self, result):
        metric = InfoMetricFamily(
            'dkron_info',
            'Dkron job info',
            labels=["jobname"])

        for job in result:
            name = job['name']
            # If there's a null result, we want to export a zero.
            owner = job.get('owner')
            owner_email = job.get('owner_email')
            metric.add_metric([name], {'owner': owner, 'owner_email': owner_email})
            # job_status = job['status']
        return metric
    def collect(self):
        metrics = self.request_data_from('/metrics/metrics')
        system_info = self.request_data_from('/system/info')
        """
        Rundeck system info
        """
        rundeck_system_info = InfoMetricFamily('rundeck_system',
                                               'Rundeck system info')
        rundeck_system_info.add_metric(
            [],
            {x: str(y)
             for x, y in system_info['system']['rundeck'].items()})
        yield rundeck_system_info
        """
        Rundeck system stats
        """
        for system_stats in self.get_system_stats(system_info):
            yield system_stats
        """
        Rundeck counters
        """
        for counters in self.get_counters(metrics):
            yield counters
        """
        Rundeck projects executions info
        """
        if self.args.rundeck_projects_executions:
            endpoint = '/projects'

            if self.args.rundeck_projects_filter:
                projects = [{
                    "name": x
                } for x in self.args.rundeck_projects_filter]
            else:
                if self.args.rundeck_projects_executions_cache:
                    projects = self.cached_request_data_from(endpoint)
                else:
                    projects = self.request_data_from(endpoint)

            with ThreadPoolExecutor() as threadpool:
                project_executions = threadpool.map(
                    self.get_project_executions, projects)

                for executions in project_executions:
                    for execution in executions:
                        if execution is not None:
                            yield (execution)
 def create_info_collector(name, info, dicts, labels=[]):
     labels.append('routerboard_name')
     if type(dicts) is list:
         collector = InfoMetricFamily(f'routeros_{name}', info)
         for d in dicts:
             labels_values = {}
             for label in labels:
                 if d.get(label):
                     labels_values[label] = d.get(label)
                 else:
                     labels_values[label] = ''
             collector.add_metric(labels, labels_values)
         return collector
     else:
         raise Exception(
             f'{type(dicts)} is not a dictionary or a list of dictionaries.'
         )
Пример #8
0
    def collect(self):
        info = self.rpc.getinfo()
        info_labels = {k: v for k, v in info.items() if isinstance(v, str)}
        node_info_fam = InfoMetricFamily(
            'lightning_node',
            'Static node information',
            labels=info_labels.keys(),
        )
        node_info_fam.add_metric(info_labels, info_labels)
        yield node_info_fam

        blockheight = info['blockheight']
        yield GaugeMetricFamily(
            'lightning_node_blockheight',
            "Current Bitcoin blockheight on this node.",
            value=blockheight,
        )
Пример #9
0
 def collect(self):
     info = InfoMetricFamily('xxxx', 'xxxxxx')
     info.add_metric(labels='version',
                     value={
                         'version': 'xxxxx',
                         'loglevel': 'xxx',
                         'root': 'xxxx',
                         'workers': 'xxxx',
                         'ip': 'xxxxx',
                         'port': 'xxx',
                         'config_name': 'xxxx',
                         'mode': 'xx',
                         'debug': 'xxx',
                         'node': 'xxx',
                         'pod': 'xxx',
                         'pid': str(os.getpid())
                     })
     yield info
Пример #10
0
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch data
        data = call_rest_api('/mgmt/status/default/IPMISelEvents', self.ip,
                             self.port, self.session, self.timeout)

        if data == '':
            return

        # Update Prometheus metrics
        for ise in data['IPMISelEvents']:
            i = InfoMetricFamily('mqa_ipmi_sel_events',
                                 'MQ Appliance IPMI SEL events information')
            i.add_metric(
                [
                    'appliance', 'index', 'timestamp', 'recordType',
                    'sensorType', 'sensorNumber', 'sensorName',
                    'eventReadingTypeCode', 'eventData', 'eventDirection',
                    'extra'
                ], {
                    'appliance': self.appliance,
                    'index': str(ise['Index']),
                    'timestamp': ise['Timestamp'],
                    'recordType': ise['RecordType'],
                    'sensorType': ise['SensorType'],
                    'sensorNumber': ise['SensorNumber'],
                    'sensorName': ise['SensorName'],
                    'eventReadingTypeCode': ise['EventReadingTypeCode'],
                    'eventData': ise['EventData2'],
                    'eventDirection': ise['EventDirection'],
                    'extra': ise['Extra']
                })
            yield i

        g = GaugeMetricFamily(
            'mqa_exporter_ipmi_sel_events_elapsed_time_seconds',
            'Exporter eleapsed time to collect ipmi sel events metrics',
            labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g
Пример #11
0
    def collect(self):
        headers = {
            'Authorization': 'token {}'.format(os.environ.get("TOKEN", ""))
        }

        for repo in self.repos:
            name = repo.replace('/', '_').replace('-', '_')

            if time.time() - self.time > self.cache_timeout:
                self.cache = {}
                self.time = time.time()

            if name not in self.cache:
                try:
                    response = requests.get(url=self.url.format(repo),
                                            headers=headers,
                                            verify=False,
                                            stream=False,
                                            timeout=5)
                except requests.Timeout:
                    continue
                except requests.ConnectionError:
                    continue

                self.cache[name] = response.json()

            metric_counter = CounterMetricFamily(
                "repo__{}__tags_".format(name),
                "Repo `{}` tags total".format(name),
                labels=['tags'])
            metric_counter.add_metric([name], len(self.cache[name]))
            yield metric_counter

            metric_info = InfoMetricFamily("repo__{}__tag".format(name),
                                           "Repo `{}` tag".format(name))
            metric_info.add_metric(
                ["tag"], {
                    'name':
                    self.cache[name][0]['name']
                    if len(self.cache[name]) else 'inf'
                })
            yield metric_info
 def collect(self):
     tankStatus = self.api_.fetchTanks()
     info = InfoMetricFamily('tankuility_tank',
                             'Tank Info',
                             labels=['tankId'])
     capacity = GaugeMetricFamily('tankuility_capacity',
                                  'Tank Capacity (gallons)',
                                  labels=['tankId'])
     reading = GaugeMetricFamily('tankuility_reading',
                                 'Tank Level (percent)',
                                 labels=['tankId'])
     temperature = GaugeMetricFamily('tankuility_temperature',
                                     'Temperature (Fahrenheit)',
                                     labels=['tankId'])
     battery = GaugeMetricFamily(
         'tankuility_battery',
         'Battery status (critical=0, warning=1, normal=2)',
         labels=['tankId'])
     for tank in tankStatus.values():
         tank_id = tank['short_device_id']
         info.add_metric([tank_id], {
             'name': tank['name'],
             'address': tank['address']
         })
         capacity.add_metric([tank_id], tank['capacity'])
         reading.add_metric([tank_id],
                            tank['lastReading']['tank'],
                            timestamp=tankutility_scale(
                                tank['lastReading']['time']))
         temperature.add_metric([tank_id],
                                tank['lastReading']['temperature'],
                                timestamp=tankutility_scale(
                                    tank['lastReading']['time']))
         battery.add_metric([tank_id], 0 if tank['battery_crit'] else
                            1 if tank['battery_warn'] else 2)
     yield info
     yield capacity
     yield reading
     yield temperature
     yield battery
Пример #13
0
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch data
        data = call_rest_api('/mgmt/status/default/FailureNotificationStatus2',
                             self.ip, self.port, self.session, self.timeout)

        if data == '':
            return

        failureNotifications = []

        if type(data['FailureNotificationStatus2']) is dict:
            failureNotifications.append(data['FailureNotificationStatus2'])
        else:
            failureNotifications = data['FailureNotificationStatus2']

        # Update Prometheus metrics
        for fn in failureNotifications:

            i = InfoMetricFamily('mqa_failure_notification',
                                 'MQ Appliance failure notifications')
            i.add_metric(
                ['appliance', 'date', 'reason', 'uploadStatus', 'location'], {
                    'appliance': self.appliance,
                    'date': fn['Date'],
                    'reason': fn['Reason'],
                    'uploadStatus': fn['UploadStatus'],
                    'location': fn['Location']
                })
            yield i

        g = GaugeMetricFamily(
            'mqa_exporter_failure_notification_elapsed_time_seconds',
            'Exporter eleapsed time to collect failure notification metrics',
            labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g
Пример #14
0
class InfoMetricCollector(Collector):
    """Provides metadata about the feature distribution for querying."""
    def __init__(self, metric: Iterable[Metric]):
        """Computes the feature metadata from a list of collected feature histograms.

        :param metric: A list of Prometheus metrics returned from FeatureHistogramCollector
        :type metric: Iterable[Metric]
        """
        self.metric = InfoMetricFamily(
            name="baseline_metrics",
            documentation="Metadata about the baseline training metrics",
            labels=["feature_name", "metric_name", "metric_type"],
        )
        for m in metric:
            start = m.documentation.find(":") + 1
            name = m.documentation[start:].strip()
            self.metric.add_metric(labels=[name, m.name, m.type], value={})

    def describe(self):
        return self.collect()

    def collect(self):
        yield self.metric
Пример #15
0
    def collect(self):
        info = self.rpc.getinfo()
        info_labels = {k.replace('-', '_'): v for k, v in info.items() if isinstance(v, str)}
        node_info_fam = InfoMetricFamily(
            'lightning_node',
            'Static node information',
            labels=info_labels.keys(),
        )
        node_info_fam.add_metric(info_labels, info_labels)
        yield node_info_fam

        blockheight = info['blockheight']
        yield GaugeMetricFamily(
            'lightning_node_blockheight',
            "Current Bitcoin blockheight on this node.",
            value=blockheight,
        )

        fees_msat = info["msatoshi_fees_collected"]
        yield GaugeMetricFamily(
            'lightning_fees_collected_msat',
            'How much have we been paid to route payments?',
            value=fees_msat,
        )
 def get_memory_and_version_info(_self):
     metrics = []
     records = _self.execute_sql('version')
     if len(records) == 1:
         version = InfoMetricFamily('node_ifx_version',
                                    'Informix version',
                                    labels=["ifxserver"])
         version.add_metric([_self.dbhostname],
                            {'version': records[0]['version']})
         metrics.append(version)
         max_memory = GaugeMetricFamily('node_ifx_max_memory_allowed',
                                        'Informix maximum allowed memory',
                                        labels=["ifxserver"])
         max_memory.add_metric([_self.dbhostname],
                               _self.get_max_license_memory_from_version(
                                   records[0]['version']))
         metrics.append(max_memory)
     records = _self.execute_sql('memory')
     memory_used = GaugeMetricFamily('node_ifx_memory_used',
                                     'Informix memory in use',
                                     labels=["ifxserver"])
     memory_used.add_metric([_self.dbhostname], records[0]['total_size'])
     metrics.append(memory_used)
     return metrics
Пример #17
0
 def test_info_labels(self):
     cmf = InfoMetricFamily('i', 'help', labels=['a'])
     cmf.add_metric(['b'], {'c': 'd'})
     self.custom_collector(cmf)
     self.assertEqual(1, self.registry.get_sample_value('i_info', {'a': 'b', 'c': 'd'}))
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch data
        data = call_rest_api('/mgmt/status/default/QueueManagersStatus',
                             self.ip, self.port, self.session, self.timeout)
        if data == '':
            return

        # Update Prometheus metrics
        for qm in data['QueueManagersStatus']:

            g = GaugeMetricFamily(
                'mqa_queue_manager_cpu_usage',
                'The instantaneous CPU usage by the queue manager as a percentage of the CPU load',
                labels=['appliance', 'qm', 'status'])
            g.add_metric([self.appliance, qm['Name'], qm['Status']],
                         qm['CpuUsage'])
            yield g

            g = GaugeMetricFamily(
                'mqa_queue_manager_memory_bytes_used',
                'The amount of memory in bytes that is currently in use by the queue manager',
                labels=['appliance', 'qm', 'status'])
            # Memory in MB not MiB
            #g.add_metric([self.appliance, qm['Name']], qm['UsedMemory'] * 1048576)
            g.add_metric([self.appliance, qm['Name'], qm['Status']],
                         qm['UsedMemory'] * 1000000)
            yield g

            g = GaugeMetricFamily(
                'mqa_queue_manager_fs_bytes_used',
                'The amount of file system in bytes that is currently in use by the queue manager',
                labels=['appliance', 'qm', 'status'])
            # Memory in MB not MiB
            #g.add_metric([self.appliance, qm['Name']], qm['UsedFs'] * 1048576)
            g.add_metric([self.appliance, qm['Name'], qm['Status']],
                         qm['UsedFs'] * 1000000)
            yield g

            g = GaugeMetricFamily(
                'mqa_queue_manager_fs_bytes_allocated',
                'The amount of file system in bytes allocated for the queue manager',
                labels=['appliance', 'qm', 'status'])
            # Memory in MB not MiB
            #g.add_metric([self.appliance, qm['Name']], qm['TotalFs'] * 1048576)
            g.add_metric([self.appliance, qm['Name'], qm['Status']],
                         qm['TotalFs'] * 1000000)
            yield g

            i = InfoMetricFamily('mqa_queue_manager',
                                 'MQ Appliance queue manager information')
            i.add_metric(
                [
                    'appliance', 'qm', 'status', 'haRole', 'haStatus',
                    'drRole', 'drStatus'
                ], {
                    'appliance':
                    self.appliance,
                    'qm':
                    qm['Name'],
                    'status':
                    qm['Status'],
                    'haRole':
                    'Unknown' if qm['HaRole'] == '' else qm['HaRole'],
                    'haStatus':
                    'Unknown' if qm['HaStatus'] == '' else qm['HaStatus'],
                    'drRole':
                    'Unknown' if qm['DrRole'] == '' else qm['DrRole'],
                    'drStatus':
                    'Unknown' if qm['DrStatus'] == '' else qm['DrStatus']
                })
            yield i

        g = GaugeMetricFamily(
            'mqa_exporter_queue_managers_elapsed_time_seconds',
            'Exporter eleapsed time to collect queue managers metrics',
            labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g
Пример #19
0
    def collect(self):
        get_system_info = self.request_data(args.rundeck_url, 'system/info',
                                            args.rundeck_token,
                                            self.ssl_verify)

        get_metrics = self.request_data(args.rundeck_url, 'metrics/metrics',
                                        args.rundeck_token, self.ssl_verify)

        rundeck_system_info = InfoMetricFamily('rundeck_system',
                                               'Rundeck system info')
        rundeck_system_info.add_metric([], {
            x: str(y)
            for x, y in get_system_info['system']['rundeck'].items()
        })

        yield rundeck_system_info

        for stat, stat_values in get_system_info['system']['stats'].items():
            for counter, value in stat_values.items():
                if counter == 'unit':
                    continue
                elif isinstance(value, dict):
                    if stat == 'cpu':
                        value = value['average']
                    elif stat == 'uptime':
                        value = value['epoch']

                rundeck_system_stats = GaugeMetricFamily(
                    'rundeck_system_stats_{}_{}'.format(stat, counter),
                    'Rundeck system stats')

                rundeck_system_stats.add_metric([], value)

                yield rundeck_system_stats

        rundeck_counters_status = CounterMetricFamily(
            'rundeck_counters_status',
            'Rundeck counters metrics',
            labels=['status'])

        for metric, metric_value in get_metrics.items():
            if not isinstance(metric_value, dict):
                continue

            for counter_name, counter_value in metric_value.items():
                counter_name = counter_name.replace('.', '_').replace('-', '_')

                if not counter_name.startswith('rundeck'):
                    counter_name = 'rundeck_' + counter_name

                if metric == 'counters':
                    counter_value = counter_value['count']

                    if 'status' not in counter_name:
                        rundeck_counters = CounterMetricFamily(
                            counter_name, 'Rundeck counters metrics')
                        rundeck_counters.add_metric([], counter_value)
                        yield rundeck_counters
                    else:
                        counter_name = '_'.join(counter_name.split('_')[3:5])
                        rundeck_counters_status.add_metric([counter_name],
                                                           counter_value)

                elif metric == 'gauges':
                    counter_name = counter_name.split('_')
                    counter_value = counter_value['value']

                    if 'services' in counter_name:
                        rundeck_gauges = GaugeMetricFamily(
                            '_'.join(counter_name[:-1]),
                            'Rundeck gauges metrics',
                            labels=['type'])
                    else:
                        rundeck_gauges = GaugeMetricFamily(
                            '_'.join(counter_name), 'Rundeck gauges metrics')

                    if counter_value is not None:
                        rundeck_gauges.add_metric([counter_name[-1]],
                                                  counter_value)
                    else:
                        rundeck_gauges.add_metric([counter_name[-1]], 0)

                    yield rundeck_gauges

                elif metric == 'meters' or metric == 'timers':
                    rundeck_meters_timers = GaugeMetricFamily(
                        counter_name,
                        "Rundeck {} metrics".format(metric),
                        labels=['type'])

                    for counter, value in counter_value.items():
                        if not isinstance(value, str):
                            rundeck_meters_timers.add_metric([counter], value)

                    yield rundeck_meters_timers

        yield rundeck_counters_status
Пример #20
0
    def parse_for_prom(self):
        general = self._metrics['general']
        """ return general info """
        info = InfoMetricFamily(self.prefix + '_general', '', labels=[])
        info.add_metric([], general)
        yield info
        """ separate general info for value """
        gauge = GaugeMetricFamily(self.prefix + '_general_status',
                                  '',
                                  labels=['power_state'])
        gauge.add_metric([general['power_state']],
                         self._cast(general['power_state']))
        yield gauge

        gauge = GaugeMetricFamily(self.prefix + '_general_health',
                                  '',
                                  labels=['health'])
        gauge.add_metric([general['health']], self._cast(general['health']))
        yield gauge

        gauge = GaugeMetricFamily(self.prefix + '_general_state',
                                  '',
                                  labels=['state'])
        gauge.add_metric([general['state']], self._cast(general['state']))
        yield gauge

        fans = self._metrics['fan']
        """ return thermal metrics """
        gauge = GaugeMetricFamily(self.prefix + '_fan_redundancy',
                                  '',
                                  labels=['health', 'state'])
        gauge.add_metric([fans['redundancy_health'], fans['redundancy_state']],
                         int(
                             self._cast(fans['redundancy_health']) +
                             self._cast(fans['redundancy_state'])))
        yield gauge

        gauge = GaugeMetricFamily(self.prefix + '_fan_rpm',
                                  '',
                                  labels=['name', 'low_limit'])
        gauge_status = GaugeMetricFamily(self.prefix + '_fan',
                                         '',
                                         labels=['name', 'health', 'state'])
        for fan in fans['list']:
            gauge.add_metric([fan['name'], str(fan['low_limit'])],
                             self._cast(fan['rpm']))
            gauge_status.add_metric(
                [fan['name'], fan['health'], fan['state']],
                int(self._cast(fan['health']) + self._cast(fan['state'])))
        yield gauge
        yield gauge_status

        thermal = self._metrics['thermal']
        """ return thermal metrics """
        gauge = GaugeMetricFamily(self.prefix + '_thermal_location',
                                  '',
                                  labels=['name', 'limit'])

        for location in thermal['location']:
            gauge.add_metric(
                [location['name'], str(location['limit'])], location['degres'])
        yield gauge
        """ return power metrics """
        power = self._metrics['power']
        gauge = GaugeMetricFamily(self.prefix + '_power',
                                  '',
                                  labels=['health', 'state'])
        gauge.add_metric(
            [power['health'], power['state']],
            int(self._cast(power['state']) + self._cast(power['health'])))
        yield gauge

        gauge = GaugeMetricFamily(self.prefix + '_power_comsumption',
                                  'watt consumption',
                                  labels=['type', 'unit', 'limit'])
        gauge.add_metric(
            ['average', 'watt', str(power['limit'])], int(power['average']))
        gauge.add_metric(
            ['maxconsumed', 'watt', str(power['limit'])],
            int(power['maxconsumed']))
        gauge.add_metric(
            ['minconsumed', 'watt', str(power['limit'])],
            int(power['minconsumed']))
        yield gauge
        """ return power supply metrics """
        gauge = GaugeMetricFamily(
            self.prefix + '_power_supply',
            '',
            labels=['name', 'capacity', 'health', 'state'])
        for powersupply in power['powersupplies']:
            gauge.add_metric([
                powersupply['name'],
                str(powersupply['power_capacity']), powersupply['health'],
                powersupply['state']
            ],
                             int(
                                 self._cast(powersupply['state']) +
                                 self._cast(powersupply['health'])))

        yield gauge
    def collect(self):
        g = GaugeMetricFamily('vrops_vm_properties',
                              'testtest',
                              labels=[
                                  'vccluster', 'datacenter', 'virtualmachine',
                                  'hostsystem', 'propkey'
                              ])
        i = InfoMetricFamily(
            'vrops_vm',
            'testtest',
            labels=['vccluster', 'datacenter', 'virtualmachine', 'hostsystem'])
        if os.environ['DEBUG'] >= '1':
            print(self.name, 'starts with collecting the metrics')

        for target in self.get_vms_by_target():
            token = self.get_target_tokens()
            token = token[target]

            if not token:
                print("skipping", target, "in", self.name, ", no token")

            uuids = self.target_vms[target]

            if 'number_metrics' in self.property_yaml[self.name]:
                for property_pair in self.property_yaml[
                        self.name]['number_metrics']:
                    property_label = property_pair['label']
                    propkey = property_pair['property']
                    values = Resources.get_latest_number_properties_multiple(
                        target, token, uuids, propkey)
                    if not values:
                        continue
                    for value_entry in values:
                        if 'data' not in value_entry:
                            continue
                        data = value_entry['data']
                        vm_id = value_entry['resourceId']
                        if vm_id not in self.vms:
                            continue
                        g.add_metric(labels=[
                            self.vms[vm_id]['cluster'],
                            self.vms[vm_id]['datacenter'],
                            self.vms[vm_id]['name'],
                            self.vms[vm_id]['parent_host_name'], property_label
                        ],
                                     value=data)

            if 'enum_metrics' in self.property_yaml[self.name]:
                for property_pair in self.property_yaml[
                        self.name]['enum_metrics']:
                    property_label = property_pair['label']
                    propkey = property_pair['property']
                    expected_state = property_pair['expected']
                    values = Resources.get_latest_enum_properties_multiple(
                        target, token, uuids, propkey, expected_state)
                    if not values:
                        continue
                    for value_entry in values:
                        if 'data' not in value_entry:
                            continue
                        data = value_entry['data']
                        vm_id = value_entry['resourceId']
                        latest_state = value_entry['latest_state']
                        if vm_id not in self.vms:
                            continue
                        g.add_metric(labels=[
                            self.vms[vm_id]['cluster'],
                            self.vms[vm_id]['datacenter'],
                            self.vms[vm_id]['name'],
                            self.vms[vm_id]['parent_host_name'],
                            property_label + ": " + latest_state
                        ],
                                     value=data)

            if 'info_metrics' in self.property_yaml[self.name]:
                for property_pair in self.property_yaml[
                        self.name]['info_metrics']:
                    property_label = property_pair['label']
                    propkey = property_pair['property']
                    values = Resources.get_latest_info_properties_multiple(
                        target, token, uuids, propkey)
                    if not values:
                        continue
                    for value_entry in values:
                        if 'data' not in value_entry:
                            continue
                        vm_id = value_entry['resourceId']
                        info_value = value_entry['data']
                        if vm_id not in self.vms:
                            continue
                        i.add_metric(labels=[
                            self.vms[vm_id]['cluster'],
                            self.vms[vm_id]['datacenter'],
                            self.vms[vm_id]['name'],
                            self.vms[vm_id]['parent_host_name']
                        ],
                                     value={property_label: info_value})

        # self.post_metrics(g.name)
        # self.post_metrics(i.name + '_info')
        yield g
        yield i
Пример #22
0
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch data
        data = call_rest_api('/mgmt/status/default/LogTargetStatus', self.ip,
                             self.port, self.session, self.timeout)
        if data == '':
            return

        logTargets = []

        if type(data['LogTargetStatus']) is dict:
            logTargets.append(data['LogTargetStatus'])
        else:
            logTargets = data['LogTargetStatus']

        # Update Prometheus metrics
        for lt in logTargets:

            c = CounterMetricFamily(
                'mqa_log_target_events_processed_total',
                'The number of events that this log target processed',
                labels=['appliance', 'name'])
            c.add_metric([self.appliance, lt['LogTarget']['value']],
                         lt['EventsProcessed'])
            yield c

            c = CounterMetricFamily(
                'mqa_log_target_events_dropped_total',
                'The number of events that this log target dropped because there are too many pending events',
                labels=['appliance', 'name'])
            c.add_metric([self.appliance, lt['LogTarget']['value']],
                         lt['EventsDropped'])
            yield c

            c = CounterMetricFamily(
                'mqa_log_target_events_pending_total',
                'The number of pending events for this log target. These events are waiting to be stored at the destination',
                labels=['appliance', 'name'])
            c.add_metric([self.appliance, lt['LogTarget']['value']],
                         lt['EventsPending'])
            yield c

            c = CounterMetricFamily(
                'mqa_log_target_memory_requested_total',
                'The requested memory for this log target. This measurement represents the high watermark of memory requested',
                labels=['appliance', 'name'])
            c.add_metric([self.appliance, lt['LogTarget']['value']],
                         lt['RequestedMemory'])
            yield c

            i = InfoMetricFamily('mqa_log_target',
                                 'MQ Appliance log target information')
            i.add_metric(
                ['appliance', 'name', 'href', 'status', 'errorInfo'], {
                    'appliance': self.appliance,
                    'name': lt['LogTarget']['value'],
                    'href': lt['LogTarget']['href'],
                    'status': lt['Status'],
                    'errorInfo': lt['ErrorInfo']
                })
            yield i

        g = GaugeMetricFamily(
            'mqa_exporter_log_targets_elapsed_time_seconds',
            'Exporter eleapsed time to collect log targets metrics',
            labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch data
        data = call_rest_api('/mgmt/status/default/DateTimeStatus', self.ip,
                             self.port, self.session, self.timeout)
        data2 = call_rest_api('/mgmt/status/default/FirmwareStatus', self.ip,
                              self.port, self.session, self.timeout)
        data3 = call_rest_api('/mgmt/status/default/FirmwareVersion3', self.ip,
                              self.port, self.session, self.timeout)

        if data == '' or data2 == '' or data3 == '':
            return

        # Update Prometheus metrics
        c = CounterMetricFamily(
            'mqa_bootcount',
            'The number of times the firmware image was restarted through an appliance reboot or a firmware reload. The count is from the initial firmware load on the appliance till the current time. The count is independent of firmware version',
            labels=['appliance'])
        c.add_metric([self.appliance], data2['FirmwareStatus']['BootCount'])
        yield c

        uptime_split = data['DateTimeStatus']['uptime2'].split(' ')
        days = int(uptime_split[0])
        hours = int(uptime_split[2][0:2])
        minutes = int(uptime_split[2][3:5])
        seconds = int(uptime_split[2][6:])
        uptime_seconds = days * 86400 + hours * 3600 + minutes * 60 + seconds

        c = CounterMetricFamily(
            'mqa_uptime_seconds',
            'The total amount of time in seconds the appliance has been up since the last reload or reboot. Note that a shutdown and reload resets this counter',
            labels=['appliance'])
        c.add_metric([self.appliance], uptime_seconds)
        yield c

        bootuptime_split = data['DateTimeStatus']['bootuptime2'].split(' ')
        days = int(bootuptime_split[0])
        hours = int(bootuptime_split[2][0:2])
        minutes = int(bootuptime_split[2][3:5])
        seconds = int(bootuptime_split[2][6:])
        bootuptime_seconds = days * 86400 + hours * 3600 + minutes * 60 + seconds

        c = CounterMetricFamily(
            'mqa_bootuptime_seconds',
            'The total amount of time in seconds since the last reboot. Note that this counter is reset by a shutdown and reboot, but not by a shutdown and reload',
            labels=['appliance'])
        c.add_metric([self.appliance], bootuptime_seconds)
        yield c

        c = CounterMetricFamily(
            'mqa_current_datetime_seconds',
            'The current date and time of the MQ Appliance in epoch seconds',
            labels=['appliance'])
        c.add_metric([self.appliance],
                     datetime_to_epoch(data['DateTimeStatus']['time'],
                                       '%a %b %d %H:%M:%S %Y'))
        yield c

        i = InfoMetricFamily('mqa', 'MQ Appliance information')
        i.add_metric(
            [
                'appliance', 'timezone', 'tzspec', 'type', 'installdate',
                'serial', 'version', 'level', 'build', 'builddate',
                'deliverytype', 'watchdogbuild', 'installeddpos',
                'runningdpos', 'xmlaccelerator', 'machinetype', 'modeltype'
            ], {
                'appliance': self.appliance,
                'timezone': data['DateTimeStatus']['timezone'],
                'tzspec': data['DateTimeStatus']['tzspec'],
                'type': data2['FirmwareStatus']['Type'],
                'installdate': data2['FirmwareStatus']['InstallDate'],
                'serial': data3['FirmwareVersion3']['Serial'],
                'version': data3['FirmwareVersion3']['Version'],
                'level': data3['FirmwareVersion3']['Level'],
                'build': data3['FirmwareVersion3']['Build'],
                'builddate': data3['FirmwareVersion3']['BuildDate'],
                'deliverytype': data3['FirmwareVersion3']['DeliveryType'],
                'watchdogbuild': data3['FirmwareVersion3']['WatchdogBuild'],
                'installeddpos': data3['FirmwareVersion3']['InstalledDPOS'],
                'runningdpos': data3['FirmwareVersion3']['RunningDPOS'],
                'xmlaccelerator': data3['FirmwareVersion3']['XMLAccelerator'],
                'machinetype': data3['FirmwareVersion3']['MachineType'],
                'modeltype': data3['FirmwareVersion3']['ModelType']
            })
        yield i

        g = GaugeMetricFamily(
            'mqa_exporter_mqa_information_elapsed_time_seconds',
            'Exporter eleapsed time to collect mqa information metrics',
            labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g
Пример #24
0
    def collect(self):
        self.data = self.get_data()
        self.satellites = self.get_satellites()
        self.sat_data = self.get_sat_data()

        for key in [
                'nodeID', 'wallet', 'lastPinged', 'lastPingFromID',
                'lastPingFromAddress', 'upToDate'
        ]:
            value = str(self.data[key])
            metric = InfoMetricFamily("storj_" + key,
                                      "Storj " + key,
                                      value={key: value})
            yield metric

### 2do - remove this block in v1.0.0 <======
        for array in ['diskSpace', 'bandwidth']:
            for key in ['used', 'available']:
                value = self.data[array][key]
                metric = GaugeMetricFamily("storj_" + array + "_" + key,
                                           "Storj " + array + " " + key,
                                           value=value)
                yield metric

        for array in ['audit', 'uptime']:
            for key in list(self.sat_data.values())[0][array]:
                metric = GaugeMetricFamily("storj_sat_" + array + "_" + key,
                                           "Storj satellite " + key,
                                           labels=["satellite"])
                for sat in self.satellites:
                    value = self.sat_data[sat][array][key]
                    metric.add_metric([sat], value)
                yield metric

        for key in ['storageSummary', 'bandwidthSummary']:
            metric = GaugeMetricFamily("storj_sat_" + key,
                                       "Storj satellite " + key,
                                       labels=["satellite"])
            for sat in self.satellites:
                value = self.sat_data[sat][key]
                metric.add_metric([sat], value)
            yield metric


################################    <=====

        storj_total_diskspace = GaugeMetricFamily(
            "storj_total_diskspace",
            "Storj total diskspace metrics",
            labels=["type"])
        storj_total_bandwidth = GaugeMetricFamily(
            "storj_total_bandwidth",
            "Storj total bandwidth metrics",
            labels=["type"])
        storj_sat_summary = GaugeMetricFamily(
            "storj_sat_summary",
            "Storj satellite summary metrics",
            labels=["type", "satellite"])
        storj_sat_audit = GaugeMetricFamily("storj_sat_audit",
                                            "Storj satellite audit metrics",
                                            labels=["type", "satellite"])
        storj_sat_uptime = GaugeMetricFamily("storj_sat_uptime",
                                             "Storj satellite uptime metrics",
                                             labels=["type", "satellite"])
        storj_sat_month_egress = GaugeMetricFamily(
            "storj_sat_month_egress",
            "Storj satellite egress since current month start",
            labels=["type", "satellite"])
        storj_sat_month_ingress = GaugeMetricFamily(
            "storj_sat_month_ingress",
            "Storj satellite ingress since current month start",
            labels=["type", "satellite"])
        storj_sat_day_egress = GaugeMetricFamily(
            "storj_sat_day_egress",
            "Storj satellite egress since current day start",
            labels=["type", "satellite"])
        storj_sat_day_ingress = GaugeMetricFamily(
            "storj_sat_day_ingress",
            "Storj satellite ingress since current day start",
            labels=["type", "satellite"])
        storj_sat_day_storage = GaugeMetricFamily(
            "storj_sat_day_storage",
            "Storj satellite data stored on disk since current day start",
            labels=["type", "satellite"])

        self.add_iterable_metrics(['used', 'available'],
                                  self.data["diskSpace"],
                                  storj_total_diskspace)
        self.add_iterable_metrics(['used', 'available'],
                                  self.data["bandwidth"],
                                  storj_total_bandwidth)

        for sat in self.satellites:
            self.add_iterable_metrics(['storageSummary', 'bandwidthSummary'],
                                      self.sat_data[sat], storj_sat_summary,
                                      [sat])
            self.add_iterable_metrics(
                list(self.sat_data.values())[0]["audit"],
                self.sat_data[sat]["audit"], storj_sat_audit, [sat])
            self.add_iterable_metrics(
                list(self.sat_data.values())[0]["uptime"],
                self.sat_data[sat]["uptime"], storj_sat_uptime, [sat])
            self.add_iterable_day_sum_metrics(
                ['repair', 'audit', 'usage'],
                self.sat_data[sat]['bandwidthDaily'], "egress",
                storj_sat_month_egress, [sat])
            self.add_iterable_day_sum_metrics(
                ['repair', 'usage'], self.sat_data[sat]['bandwidthDaily'],
                "ingress", storj_sat_month_ingress, [sat])
            if self.sat_data[sat]['bandwidthDaily']:
                self.add_iterable_metrics(
                    ['repair', 'audit', 'usage'],
                    self.sat_data[sat]['bandwidthDaily'][-1]['egress'],
                    storj_sat_day_egress, [sat])
                self.add_iterable_metrics(
                    ['repair', 'usage'],
                    self.sat_data[sat]['bandwidthDaily'][-1]['ingress'],
                    storj_sat_day_ingress, [sat])
            if self.sat_data[sat]['storageDaily']:
                storj_sat_day_storage.add_metric(
                    ["atRestTotal", sat],
                    self.sat_data[sat]['storageDaily'][-1]['atRestTotal'])

        yield storj_total_diskspace
        yield storj_total_bandwidth
        yield storj_sat_summary
        yield storj_sat_audit
        yield storj_sat_uptime
        yield storj_sat_month_egress
        yield storj_sat_month_ingress
        yield storj_sat_day_egress
        yield storj_sat_day_ingress
        yield storj_sat_day_storage
Пример #25
0
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch data
        data = call_rest_api('/mgmt/status/default/MQSystemResources', self.ip,
                             self.port, self.session, self.timeout)
        if data == '':
            return

        # Update Prometheus metrics
        c = CounterMetricFamily(
            'mqa_mq_resources_storage_bytes_total',
            'The total storage in bytes available for IBM MQ data',
            labels=['appliance'])
        c.add_metric([self.appliance],
                     data['MQSystemResources']['TotalStorage'] * 1000000)
        yield c

        g = GaugeMetricFamily('mqa_mq_resources_storage_bytes_used',
                              'The amount of IBM MQ storage in use in bytes',
                              labels=['appliance'])
        g.add_metric([self.appliance],
                     data['MQSystemResources']['UsedStorage'] * 1000000)
        yield g

        c = CounterMetricFamily(
            'mqa_mq_resources_errors_storage_bytes_total',
            'The total storage in bytes available for IBM MQ error logs',
            labels=['appliance'])
        c.add_metric([self.appliance],
                     data['MQSystemResources']['TotalErrorsStorage'] * 1000000)
        yield c

        g = GaugeMetricFamily(
            'mqa_mq_resources_errors_storage_bytes_used',
            'The amount of IBM MQ error log storage in use in bytes',
            labels=['appliance'])
        g.add_metric([self.appliance],
                     data['MQSystemResources']['UsedErrorsStorage'] * 1000000)
        yield g

        c = CounterMetricFamily(
            'mqa_mq_resources_trace_storage_bytes_total',
            'The total storage in bytes available for IBM MQ trace',
            labels=['appliance'])
        c.add_metric([self.appliance],
                     data['MQSystemResources']['TotalTraceStorage'] * 1000000)
        yield c

        g = GaugeMetricFamily(
            'mqa_mq_resources_trace_storage_bytes_used',
            'The amount of IBM MQ trace storage in bytes in use',
            labels=['appliance'])
        g.add_metric([self.appliance],
                     data['MQSystemResources']['UsedTraceStorage'] * 1000000)
        yield g

        ha_status = data['MQSystemResources']['HAStatus']
        if ha_status == 'Online':
            ha_status_value = 1
        elif ha_status == 'Standby':
            ha_status_value = 2
        else:
            ha_status_value = 0
        g = GaugeMetricFamily(
            'mqa_mq_resources_ha_status',
            'HA status of the appliance (0: HA not set, 1: Online, 2: Standby',
            labels=['appliance'])
        g.add_metric([self.appliance], ha_status_value)
        yield g

        ha_status = data['MQSystemResources']['HAPartner']
        ha_status = ha_status[ha_status.find('(') + 1:ha_status.find(')')]
        if ha_status == 'Online':
            ha_partner_status_value = 1
        elif ha_status == 'Standby':
            ha_partner_status_value = 2
        else:
            ha_partner_status_value = 0
        g = GaugeMetricFamily(
            'mqa_mq_resources_ha_partner_status',
            'HA status of the partner appliance (0: HA not set, 1: Online, 2: Standby',
            labels=['appliance'])
        g.add_metric([self.appliance], ha_partner_status_value)
        yield g

        i = InfoMetricFamily('mqa_mq_resources',
                             'MQ Appliance MQ resources information')
        i.add_metric(
            ['appliance', 'haStatus', 'haPartner'], {
                'appliance': self.appliance,
                'haStatus': data['MQSystemResources']['HAStatus'],
                'haPartner': data['MQSystemResources']['HAPartner']
            })
        yield i

        g = GaugeMetricFamily(
            'mqa_exporter_mq_system_resources_elapsed_time_seconds',
            'Exporter eleapsed time to collect mq system resources metrics',
            labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g
Пример #26
0
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch data
        data = call_rest_api('/mgmt/status/default/NetworkInterfaceStatus',
                             self.ip, self.port, self.session, self.timeout)
        if data == '':
            return

        # Update Prometheus metrics
        for ni in data['NetworkInterfaceStatus']:

            c = CounterMetricFamily(
                'mqa_network_interface_rx_bytes_total',
                'The amount of data successfully received on the interface, which includes MAC framing overhead',
                labels=['appliance', 'name', 'adminStatus', 'operStatus'])
            c.add_metric([
                self.appliance, ni['Name'], ni['AdminStatus'], ni['OperStatus']
            ], ni['RxHCBytes'])
            yield c

            c = CounterMetricFamily(
                'mqa_network_interface_rx_packets_total',
                'The number of packets successfully received on the interface that were passed up to the network layer for processing',
                labels=['appliance', 'name', 'adminStatus', 'operStatus'])
            c.add_metric([
                self.appliance, ni['Name'], ni['AdminStatus'], ni['OperStatus']
            ], ni['RxHCPackets'])
            yield c

            c = CounterMetricFamily(
                'mqa_network_interface_rx_errors_total',
                'The number of packets that could not be received due to errors in the packet or in the hardware',
                labels=['appliance', 'name', 'adminStatus', 'operStatus'])
            c.add_metric([
                self.appliance, ni['Name'], ni['AdminStatus'], ni['OperStatus']
            ], ni['RxErrors2'])
            yield c

            c = CounterMetricFamily(
                'mqa_network_interface_rx_drops_total',
                'The number of received packets that were not in error, but were not passed up to the network layer due to resource constraints',
                labels=['appliance', 'name', 'adminStatus', 'operStatus'])
            c.add_metric([
                self.appliance, ni['Name'], ni['AdminStatus'], ni['OperStatus']
            ], ni['RxDrops2'])
            yield c

            c = CounterMetricFamily(
                'mqa_network_interface_tx_bytes_total',
                'The amount of data successfully transmitted on the interface, which includes MAC framing overhead',
                labels=['appliance', 'name', 'adminStatus', 'operStatus'])
            c.add_metric([
                self.appliance, ni['Name'], ni['AdminStatus'], ni['OperStatus']
            ], ni['TxHCBytes'])
            yield c

            c = CounterMetricFamily(
                'mqa_network_interface_tx_packets_total',
                'The number of packets successfully transmitted on the interface',
                labels=['appliance', 'name', 'adminStatus', 'operStatus'])
            c.add_metric([
                self.appliance, ni['Name'], ni['AdminStatus'], ni['OperStatus']
            ], ni['TxHCPackets'])
            yield c

            c = CounterMetricFamily(
                'mqa_network_interface_tx_errors_total',
                'The number of packets that were not successfully transmitted due to errors on the network or in the hardware',
                labels=['appliance', 'name', 'adminStatus', 'operStatus'])
            c.add_metric([
                self.appliance, ni['Name'], ni['AdminStatus'], ni['OperStatus']
            ], ni['TxErrors2'])
            yield c

            c = CounterMetricFamily(
                'mqa_network_interface_tx_drops_total',
                'The number of packets that were not transmitted because the network layer was generating packets faster than the physical network could accept them',
                labels=['appliance', 'name', 'adminStatus', 'operStatus'])
            c.add_metric([
                self.appliance, ni['Name'], ni['AdminStatus'], ni['OperStatus']
            ], ni['TxDrops2'])
            yield c

            i = InfoMetricFamily(
                'mqa_network_interface',
                'MQ Appliance network interfaces information')
            i.add_metric(
                [
                    'appliance', 'interfaceIndex', 'interfaceType', 'name',
                    'adminStatus', 'operStatus', 'ipType', 'ip',
                    'prefixLength', 'macAddress', 'mtu'
                ], {
                    'appliance': self.appliance,
                    'interfaceIndex': str(ni['InterfaceIndex']),
                    'interfaceType': ni['InterfaceType'],
                    'name': ni['Name'],
                    'adminStatus': ni['AdminStatus'],
                    'operStatus': ni['OperStatus'],
                    'ipType': ni['IPType'],
                    'ip': ni['IP'],
                    'prefixLength': str(ni['PrefixLength']),
                    'macAddress': ni['MACAddress'],
                    'mtu': str(ni['MTU'])
                })
            yield i

        g = GaugeMetricFamily(
            'mqa_exporter_network_interfaces_elapsed_time_seconds',
            'Exporter eleapsed time to collect network interfaces metrics',
            labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g
Пример #27
0
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch data
        data = call_rest_api('/mgmt/status/default/RaidPhysicalDriveStatus',
                             self.ip, self.port, self.session, self.timeout)
        if data == '':
            return

        # Update Prometheus metrics
        for rpd in data['RaidPhysicalDriveStatus']:

            c = CounterMetricFamily(
                'mqa_raid_physical_drive_progress_percent_total',
                'The current progress percentage of the operation on the physical drive. Operations can be rebuild, copyback, patrol, or clear',
                labels=[
                    'appliance', 'controllerID', 'deviceID', 'arrayID',
                    'logicalDriveID', 'position'
                ])
            c.add_metric([
                self.appliance,
                str(rpd['ControllerID']),
                str(rpd['DeviceID']),
                str(rpd['ArrayID']),
                str(rpd['LogicalDriveID']), rpd['Position']
            ], rpd['ProgressPercent'])
            yield c

            c = CounterMetricFamily(
                'mqa_raid_physical_drive_raw_size_bytes_total',
                'The exact size of the drive in bytes',
                labels=[
                    'appliance', 'controllerID', 'deviceID', 'arrayID',
                    'logicalDriveID', 'position'
                ])
            c.add_metric([
                self.appliance,
                str(rpd['ControllerID']),
                str(rpd['DeviceID']),
                str(rpd['ArrayID']),
                str(rpd['LogicalDriveID']), rpd['Position']
            ], rpd['RawSize'] * 1000000)
            yield c

            c = CounterMetricFamily(
                'mqa_raid_physical_drive_coerced_size_bytes_total',
                'The normalized size in megabytes. The value is rounded down to an even multiple, which allows you to swap drives of the same nominal size but might not be the same raw size',
                labels=[
                    'appliance', 'controllerID', 'deviceID', 'arrayID',
                    'logicalDriveID', 'position'
                ])
            c.add_metric([
                self.appliance,
                str(rpd['ControllerID']),
                str(rpd['DeviceID']),
                str(rpd['ArrayID']),
                str(rpd['LogicalDriveID']), rpd['Position']
            ], rpd['CoercedSize'] * 1000000)
            yield c

            if rpd['Temperature'][:3] == 'n/a':
                temperature_celsius = -1
            else:
                temperature_celsius = int(rpd['Temperature'][:3])
            g = GaugeMetricFamily(
                'mqa_raid_physical_drive_temperature_celsius',
                'The temperature of the hard disk drive in celsius',
                labels=[
                    'appliance', 'controllerID', 'deviceID', 'arrayID',
                    'logicalDriveID', 'position'
                ])
            g.add_metric([
                self.appliance,
                str(rpd['ControllerID']),
                str(rpd['DeviceID']),
                str(rpd['ArrayID']),
                str(rpd['LogicalDriveID']), rpd['Position']
            ], temperature_celsius)
            yield g

            g = GaugeMetricFamily(
                'mqa_raid_physical_drive_failure',
                'If the hard disk failure state shows Yes, replace this drive as soon as possible to avoid possible data loss',
                labels=[
                    'appliance', 'controllerID', 'deviceID', 'arrayID',
                    'logicalDriveID', 'position'
                ])
            g.add_metric([
                self.appliance,
                str(rpd['ControllerID']),
                str(rpd['DeviceID']),
                str(rpd['ArrayID']),
                str(rpd['LogicalDriveID']), rpd['Position']
            ], 0 if rpd['Failure'] == 'No' else 1)
            yield g

            i = InfoMetricFamily(
                'mqa_raid_physical_drive',
                'MQ Appliance raid physical drive information')
            i.add_metric(
                [
                    'appliance', 'controllerID', 'deviceID', 'arrayID',
                    'logicalDriveID', 'logicalDriveName', 'position', 'state',
                    'interfaceType', 'interfaceSpeed', 'sasAddress',
                    'vendorID', 'productID', 'revision', 'specificInfo',
                    'failure'
                ], {
                    'appliance': self.appliance,
                    'controllerID': str(rpd['ControllerID']),
                    'deviceID': str(rpd['DeviceID']),
                    'arrayID': str(rpd['ArrayID']),
                    'logicalDriveID': str(rpd['LogicalDriveID']),
                    'logicalDriveName': rpd['LogicalDriveName'],
                    'position': rpd['Position'],
                    'state': rpd['State'],
                    'interfaceType': rpd['InterfaceType'],
                    'interfaceSpeed': rpd['InterfaceSpeed'],
                    'sasAddress': rpd['SASaddress'],
                    'vendorID': rpd['VendorID'],
                    'productID': rpd['ProductID'],
                    'revision': rpd['Revision'],
                    'specificInfo': rpd['SpecificInfo']
                })
            yield i

        g = GaugeMetricFamily(
            'mqa_exporter_raid_physical_drive_elapsed_time_seconds',
            'Exporter eleapsed time to collect raid physical drive metrics',
            labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g
Пример #28
0
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch data
        data = call_rest_api('/mgmt/status/default/RaidBatteryModuleStatus',
                             self.ip, self.port, self.session, self.timeout)
        if data == '':
            return

        # Update Prometheus metrics
        g = GaugeMetricFamily('mqa_raid_battery_module_voltage_volts',
                              'The actual voltage of the battery in volts',
                              labels=['appliance', 'controllerID', 'status'])
        g.add_metric([
            self.appliance,
            str(data['RaidBatteryModuleStatus']['ControllerID']),
            str(data['RaidBatteryModuleStatus']['Status'])
        ], data['RaidBatteryModuleStatus']['Voltage'] / 1000)
        yield g

        g = GaugeMetricFamily(
            'mqa_raid_battery_module_current_amperes',
            'The current that flows through the battery terminals in amperes',
            labels=['appliance', 'controllerID', 'status'])
        g.add_metric([
            self.appliance,
            str(data['RaidBatteryModuleStatus']['ControllerID']),
            str(data['RaidBatteryModuleStatus']['Status'])
        ], data['RaidBatteryModuleStatus']['Current'] / 1000)
        yield g

        g = GaugeMetricFamily(
            'mqa_raid_battery_module_temperature_celsius',
            'The temperature of the battery in degrees celsius',
            labels=['appliance', 'controllerID', 'status'])
        g.add_metric([
            self.appliance,
            str(data['RaidBatteryModuleStatus']['ControllerID']),
            str(data['RaidBatteryModuleStatus']['Status'])
        ], data['RaidBatteryModuleStatus']['Temperature'])
        yield g

        g = GaugeMetricFamily(
            'mqa_raid_battery_module_design_capacity_amperes_hour',
            'The designed capacity of the battery in ampere-hour',
            labels=['appliance', 'controllerID', 'status'])
        g.add_metric([
            self.appliance,
            str(data['RaidBatteryModuleStatus']['ControllerID']),
            str(data['RaidBatteryModuleStatus']['Status'])
        ], data['RaidBatteryModuleStatus']['DesignCapacity'] / 1000)
        yield g

        g = GaugeMetricFamily('mqa_raid_battery_module_design_voltage_volts',
                              'The designed voltage of the battery in volts',
                              labels=['appliance', 'controllerID', 'status'])
        g.add_metric([
            self.appliance,
            str(data['RaidBatteryModuleStatus']['ControllerID']),
            str(data['RaidBatteryModuleStatus']['Status'])
        ], data['RaidBatteryModuleStatus']['DesignVoltage'] / 1000)
        yield g

        i = InfoMetricFamily('mqa_raid_battery_module',
                             'MQ Appliance raid battery module information')
        i.add_metric(
            [
                'appliance', 'controllerID', 'batteryType', 'serial', 'name',
                'status'
            ], {
                'appliance':
                self.appliance,
                'controllerID':
                str(data['RaidBatteryModuleStatus']['ControllerID']),
                'batteryType':
                data['RaidBatteryModuleStatus']['BatteryType'],
                'serial':
                data['RaidBatteryModuleStatus']['Serial'],
                'name':
                data['RaidBatteryModuleStatus']['Name'],
                'status':
                data['RaidBatteryModuleStatus']['Status']
            })

        g = GaugeMetricFamily(
            'mqa_exporter_raid_battery_module_elapsed_time_seconds',
            'Exporter eleapsed time to collect raid battery module metrics',
            labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g
Пример #29
0
    def run(self):
        logging.info("Collecting container image metrics")

        self.fetch_images()
        self.fetch_built_images()

        image_metric_family = GaugeMetricFamily(
            'container_image_creation_timestamp',
            'Creation timestamp of container image',
            labels=[
                'namespace', 'pod_container', 'type', 'image',
                'owner_container', 'repo'
            ])
        route_metric_family = InfoMetricFamily(
            'openshift_route',
            'Information about OpenShift routes',
            labels=[
                'namespace', 'name', 'host', 'service', 'tls_termination',
                'insecure_edge_termination', 'ip_whitelist'
            ])
        env_metric_family = InfoMetricFamily(
            'openshift_pod_env',
            'Information about pod environment variables',
            labels=['namespace', 'pod_container', 'owner_container'])

        self.missing_images = set()
        v1_pod = self.dyn_client.resources.get(api_version='v1', kind='Pod')
        v1_configmap = self.dyn_client.resources.get(api_version='v1',
                                                     kind='ConfigMap')
        container_count = 0
        for pod in v1_pod.get().items:
            namespace = pod['metadata']['namespace']
            pod_name = pod['metadata']['name']
            containers = pod['spec']['containers']
            container_statuses = pod['status']['containerStatuses']
            if pod['status']['phase'] != 'Running' or pod['deletionTimestamp']:
                continue

            owner = self.get_owner(pod)

            for container in containers:
                if not container.env:
                    continue

                container_name = container['name']
                pod_container = f"{pod_name}/{container_name}"
                if owner:
                    owner_container = f"{owner}/{container_name}"
                else:
                    owner_container = ""
                container_env = {}
                for var in container.env:
                    label_name = self.label(var.name)
                    if var.value:
                        container_env[label_name] = var.value
                    elif var.valueFrom:
                        if var.valueFrom.configMapKeyRef:
                            container_env[
                                label_name] = f"<set to the key '{var.valueFrom.configMapKeyRef.key}' in configmap '{var.valueFrom.configMapKeyRef.name}'>"
                        elif var.valueFrom.fieldRef:
                            container_env[
                                label_name] = f"<set to the pod field '{var.valueFrom.fieldRef.fieldPath}'>"
                        elif var.valueFrom.resourceFieldRef:
                            container_env[
                                label_name] = f"<set to container resource '{var.valueFrom.resourceFieldRef.resource}'>"
                        elif var.valueFrom.secretKeyRef:
                            container_env[
                                label_name] = f"<set to the key '{var.valueFrom.secretKeyRef.key}' in secret '{var.valueFrom.secretKeyRef.name}'>"
                if container.envFrom:
                    for ref in container.envFrom:
                        if ref.configMapRef:
                            configmap = v1_configmap.get(
                                namespace=namespace,
                                name=ref.configMapRef.name).to_dict()['data']
                            env_vars = {
                                self.label(key): val
                                for key, val in configmap.items()
                            }
                            container_env.update(env_vars)
                env_metric_family.add_metric(
                    [namespace, pod_container, owner_container], container_env)

            for container_status in container_statuses:
                container_name = container_status['name']
                pod_container = f"{pod_name}/{container_name}"
                if owner:
                    owner_container = f"{owner}/{container_name}"
                else:
                    owner_container = ""

                image_id = container_status['imageID']
                if not image_id:
                    continue

                match = IMAGE_ID_RE.match(container_status['imageID'])
                if match:
                    image_name = match.group(2)
                    image_repo = match.group(3)
                    digest = match.group(4)
                    image_metadata = self.images.get(digest)
                else:
                    image_name = None
                    image_repo = None
                    digest = None
                    image_metadata = None

                if image_metadata:
                    image_creation_timestamp = dateutil.parser.parse(
                        image_metadata['created']).timestamp()
                    base_image = self.find_base_image(digest)
                else:
                    base_image = None
                    image_creation_timestamp = 0
                    if image_name:
                        self.missing_images.add(image_name)

                if base_image:
                    base_image_name = base_image['name']
                    base_image_repo = base_image_name.split('@')[0]
                    base_image_creation_timestamp = dateutil.parser.parse(
                        base_image['created']).timestamp()
                else:
                    base_image_name = None
                    base_image_repo = None
                    base_image_creation_timestamp = 0

                image_metric_family.add_metric([
                    namespace, pod_container, 'container_image', image_name
                    or '<unknown>', owner_container, image_repo or '<unknown>'
                ], image_creation_timestamp)
                image_metric_family.add_metric([
                    namespace, pod_container, 'parent_image', base_image_name
                    or '<unknown>', owner_container, base_image_repo
                    or '<unknown>'
                ], base_image_creation_timestamp)

                container_count += 1

        self.update_missing_imagestream()

        logging.info(
            f"Collected image metrics for {container_count} running containers"
        )

        v1_route = self.dyn_client.resources.get(
            api_version='route.openshift.io/v1', kind='Route')
        for route in v1_route.get().items:
            namespace = route.metadata.namespace
            name = route.metadata.name
            host = route.spec.host
            service = route.spec.to.name
            tls_termination = route.spec.get('tls', {}).get('termination', "")
            insecure_edge_termination = route.spec.get('tls', {}).get(
                'insecureEdgeTerminationPolicy', "")
            ip_whitelist = route.metadata.get('annotations', {}).get(
                'haproxy.router.openshift.io/ip_whitelist', "")
            route_annotations = {}
            for key, value in route.metadata.get('annotations', {}).items():
                match = HAPROXY_ANNOTATION_RE.match(key)
                if match and value:
                    label_name = 'haproxy_' + re.sub(r'[^a-zA-Z_]', '_',
                                                     match.group(1))
                    route_annotations[label_name] = value
            route_metric_family.add_metric([
                namespace, name, host, service, tls_termination,
                insecure_edge_termination, ip_whitelist
            ], route_annotations)

        return image_metric_family, route_metric_family, env_metric_family
Пример #30
0
    def collect(self):

        start = time.time()

        # Perform REST API call to fetch the list of queue managers
        qm_data = call_rest_api('/ibmmq/rest/v2/admin/qmgr', self.ip, self.port, self.session, self.timeout)
        if qm_data == '':
            return

        command = {
            'type': 'runCommandJSON',
            'command': 'display',
            'qualifier': 'chstatus',
            'name': '*',
            'responseParameters': ['all']
        }

        # For each running queue manager fetch the channels
        total_queue_managers = 0
        total_channels = 0

        for qm in qm_data['qmgr']:

            if qm['state'] == 'running':
                headers = {'Content-type': 'application/json;charset=UTF-8', 'ibm-mq-rest-csrf-token': ''}
                 # v2 call, only available since 9.1.5
                channel_data = call_rest_api('/ibmmq/rest/v2/admin/action/qmgr/' + qm['name'] + '/mqsc', self.ip, self.port, self.session, self.timeout, 'POST', headers, command)
                if channel_data == '':
                    continue

                total_queue_managers += 1

                # Update Prometheus metrics
                for channel in channel_data['commandResponse']:
                    if channel['completionCode'] == 0:

                        total_channels += 1

                        job_name = channel['parameters']['jobname']
                        if job_name == 0:
                            job_name = '0000000000000000'

                        g = GaugeMetricFamily('mqa_qm_channel_running_state', 'The current status of the channel, 1 if the channel is in RUNNING state, 0 otherwise', labels=['appliance', 'qm', 'channel', 'chlType', 'jobName'])
                        g.add_metric([self.appliance, qm['name'], channel['parameters']['channel'], channel['parameters']['chltype'], job_name], 1 if channel['parameters']['status'] == 'RUNNING' else 0)
                        yield g

                        c = CounterMetricFamily('mqa_qm_channel_start_datetime_seconds', 'The datetime on which the channel started in epoch seconds', labels=['appliance', 'qm', 'channel', 'chlType', 'jobName'])
                        c.add_metric([self.appliance, qm['name'], channel['parameters']['channel'], channel['parameters']['chltype'], job_name], datetime_to_epoch(channel['parameters']['chstada'] + ' ' + channel['parameters']['chstati'], '%Y-%m-%d %H.%M.%S'))
                        yield c

                        c = CounterMetricFamily('mqa_qm_channel_last_message_datetime_seconds', 'The datetime on which the last message was sent on the channel in epoch seconds', labels=['appliance', 'qm', 'channel', 'chlType', 'jobName'])
                        c.add_metric([self.appliance, qm['name'], channel['parameters']['channel'], channel['parameters']['chltype'], job_name], datetime_to_epoch(channel['parameters']['lstmsgda'] + ' ' + channel['parameters']['lstmsgti'], '%Y-%m-%d %H.%M.%S'))
                        yield c

                        c = CounterMetricFamily('mqa_qm_channel_messages', 'The number of messages sent on the channel since it started', labels=['appliance', 'qm', 'channel', 'chlType', 'jobName'])
                        c.add_metric([self.appliance, qm['name'], channel['parameters']['channel'], channel['parameters']['chltype'], job_name], channel['parameters']['msgs'])
                        yield c

                        try:
                            remoteQMgr = channel['parameters']['rqmname']
                        except KeyError:
                            remoteQMgr = ''

                        i = InfoMetricFamily('mqa_qm_channel', 'MQ Appliance channel information')
                        i.add_metric(['appliance', 'qm', 'channel', 'chlType', 'jobName', 'status', 'conName', 
                                      'remoteQMgr', 'remoteProduct', 'remoteVersion'], 
                                    {'appliance': self.appliance, 
                                    'qm': qm['name'], 
                                    'channel': channel['parameters']['channel'],
                                    'chlType': channel['parameters']['chltype'],
                                    'jobName': job_name,
                                    'status': channel['parameters']['status'],
                                    'conName': channel['parameters']['conname'],
                                    'remoteQMgr': remoteQMgr,
                                    'remoteProduct': channel['parameters']['rproduct'],
                                    'remoteVersion': channel['parameters']['rversion']})
                        yield i

        g = GaugeMetricFamily('mqa_exporter_queue_managers_current_channels_count', 'Exporter total number of current channels for all running queue managers', labels=['appliance'])
        g.add_metric([self.appliance], total_channels)
        yield g

        g = GaugeMetricFamily('mqa_exporter_queue_managers_channels_elapsed_time_seconds', 'Exporter eleapsed time to collect queue managers channels metrics', labels=['appliance'])
        g.add_metric([self.appliance], time.time() - start)
        yield g