class _GitMetricCollector(object): """Class for collecting metrics about a git repository. The constructor takes the arguments: `gitdir`, `metric_path`. `gitdir` is the path to the Git directory to collect metrics for and may start with a tilde (expanded to a user's home directory). `metric_path` is the Monarch metric path to report to. """ _commit_hash_metric = metrics.StringMetric( 'git/hash', description='Current Git commit hash.') _timestamp_metric = metrics.GaugeMetric( 'git/timestamp', description='Current Git commit time as seconds since Unix Epoch.') _unstaged_changes_metric = metrics.GaugeMetric( 'git/unstaged_changes', description='Unstaged Git changes.') def __init__(self, gitdir, metric_path): self._gitdir = gitdir self._gitrepo = _GitRepo(os.path.expanduser(gitdir)) self._fields = {'repo': gitdir} self._metric_path = metric_path def collect(self): """Collect metrics.""" try: self._collect_commit_hash_metric() self._collect_timestamp_metric() self._collect_unstaged_changes_metric() except subprocess.CalledProcessError as e: logger.warning(u'Error collecting git metrics for %s: %s', self._gitdir, e) def _collect_commit_hash_metric(self): commit_hash = self._gitrepo.get_commit_hash() logger.debug(u'Collecting Git hash %r for %r', commit_hash, self._gitdir) self._commit_hash_metric.set(commit_hash, self._fields) def _collect_timestamp_metric(self): commit_time = self._gitrepo.get_commit_time() logger.debug(u'Collecting Git timestamp %r for %r', commit_time, self._gitdir) self._timestamp_metric.set(commit_time, self._fields) def _collect_unstaged_changes_metric(self): added, deleted = self._gitrepo.get_unstaged_changes() self._unstaged_changes_metric.set(added, fields=dict(change_type='added', **self._fields)) self._unstaged_changes_metric.set(deleted, fields=dict(change_type='deleted', **self._fields))
from __future__ import absolute_import from __future__ import print_function import errno import os import time import psutil # pylint: disable=import-error from chromite.lib import cros_logging as logging from chromite.lib import metrics logger = logging.getLogger(__name__) _cpu_count_metric = metrics.GaugeMetric('dev/cpu/count', description='Number of CPU cores.') _cpu_time_metric = metrics.FloatMetric( 'dev/cpu/time', description='percentage of time spent by the CPU ' 'in different states.') _disk_free_metric = metrics.GaugeMetric( 'dev/disk/free', description='Available bytes on disk partition.') _disk_total_metric = metrics.GaugeMetric( 'dev/disk/total', description='Total bytes on disk partition.') _inodes_free_metric = metrics.GaugeMetric( 'dev/inodes/free', description='Number of available inodes on ' 'disk partition (unix only).') _inodes_total_metric = metrics.GaugeMetric(
# found in the LICENSE file. """Process metrics.""" from __future__ import absolute_import from __future__ import print_function from functools import partial import psutil from chromite.lib import cros_logging as logging from chromite.lib import metrics logger = logging.getLogger(__name__) _count_metric = metrics.GaugeMetric( 'proc/count', description='Number of processes currently running.') _cpu_percent_metric = metrics.GaugeMetric( 'proc/cpu_percent', description='CPU usage percent of processes.') def collect_proc_info(): collector = _ProcessMetricsCollector() collector.collect() class _ProcessMetricsCollector(object): """Class for collecting process metrics.""" def __init__(self): self._metrics = [ _ProcessMetric('autoserv', test_func=_is_parent_autoserv), _ProcessMetric('sysmon',
from __future__ import print_function import time import yaml from chromite.lib import cros_logging as logging from chromite.lib import metrics logger = logging.getLogger(__name__) LAST_RUN_FILE = '/var/lib/cros_puppet/state/last_run_summary.yaml' _config_version_metric = metrics.GaugeMetric( 'puppet/version/config', description='The version of the puppet configuration.' ' By default this is the time that the configuration was parsed') _puppet_version_metric = metrics.StringMetric( 'puppet/version/puppet', description='Version of puppet client installed.') _events_metric = metrics.GaugeMetric( 'puppet/events', description='Number of changes the puppet client made to the system in its' ' last run, by success or failure') _resources_metric = metrics.GaugeMetric( 'puppet/resources', description='Number of resources known by the puppet client in its last' ' run') _times_metric = metrics.FloatMetric( 'puppet/times', description='Time taken to perform various parts of the last puppet run')
'dev/net/packets', start_time=_BOOT_TIME, description='Number of packets up/down on interface.') _net_errors_metric = metrics.CounterMetric( 'dev/net/errors', start_time=_BOOT_TIME, description='Total number of errors up/down on interface.') _net_dropped_metric = metrics.CounterMetric( 'dev/net/dropped', start_time=_BOOT_TIME, description='Total number of dropped packages up/down on interface.') _net_if_isup_metric = metrics.BooleanMetric( 'dev/net/isup', description='Whether interface is up or down.') _net_if_duplex_metric = metrics.GaugeMetric( 'dev/net/duplex', description='Whether interface supports full or half duplex.') _net_if_speed_metric = metrics.GaugeMetric( 'dev/net/speed', description='Network interface speed in Mb.') _net_if_mtu_metric = metrics.GaugeMetric( 'dev/net/mtu', description='Network interface MTU in B.') def collect_net_info(): """Collect network metrics.""" _collect_net_io_duplex_counters() _collect_net_if_stats() _collect_fqdn() _collect_net_if_addrs()