{"id":21670,"library":"oslo-metrics","title":"Oslo Metrics","description":"Oslo Metrics is a library for collecting and reporting metrics in OpenStack services. It provides a pluggable backend system for metrics such as counters, gauges, and histograms. The current version is 0.15.1, with a relatively stable release cadence.","status":"active","version":"0.15.1","language":"python","source_language":"en","source_url":"https://opendev.org/openstack/oslo.metrics","tags":["metrics","openstack","monitoring","library"],"install":[{"cmd":"pip install oslo-metrics","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for configuration options","package":"oslo.config","optional":false},{"reason":"Used for logging","package":"oslo.log","optional":false}],"imports":[{"note":"","wrong":"","symbol":"MetricsClient","correct":"from oslo_metrics import MetricsClient"},{"note":"Wrong path; get_metrics_client is exposed at package level.","wrong":"from oslo_metrics.client import get_metrics_client","symbol":"get_metrics_client","correct":"from oslo_metrics import get_metrics_client"},{"note":"","wrong":"","symbol":"Counter","correct":"from oslo_metrics import Counter"}],"quickstart":{"code":"from oslo_metrics import get_metrics_client, Counter\nfrom oslo_config import cfg\n\n# Configuration (example using oslo.config)\nconf = cfg.ConfigOpts()\nconf.register_opts(cfg.CONF.opts)\n\nclient = get_metrics_client(conf)\n\n# Create a counter metric\ncounter = Counter('requests.total', 'Total number of requests')\nclient.register_metric(counter)\n\n# Increment counter\ncounter.increment()\n\n# Flush metrics to backend\nclient.flush()","lang":"python","description":"Basic usage: configure and use a MetricClient, register metrics, and flush."},"warnings":[{"fix":"Update imports and usage to use new metric classes (e.g., from oslo_metrics import Counter).","message":"In version 0.12.0, the API for creating metrics changed. Older 'Counter', 'Gauge', 'Histogram' classes were replaced with new metric types. Old code using the old classes will break.","severity":"breaking","affected_versions":">=0.12.0"},{"fix":"Use a single client instance, or pass conf consistently.","message":"Metrics client is a singleton per process. Calling get_metrics_client multiple times returns the same instance, which can lead to unintended sharing of state.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace 'import oslo.metrics' with 'import oslo_metrics'.","message":"The 'oslo.metrics' namespace (with dot) is deprecated in favor of 'oslo_metrics' (with underscore). Using the old dotted package name will cause ImportError in future releases.","severity":"deprecated","affected_versions":">=0.15.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use 'import oslo_metrics' instead of 'import oslo.metrics'.","cause":"Using the deprecated dotted package name.","error":"ImportError: No module named oslo.metrics"},{"fix":"Ensure you have loaded the necessary options: from oslo_config import cfg; cfg.CONF.register_opts(...).","cause":"Incorrect configuration setup; register_opts is a method of ConfigOpts but requires proper options.","error":"ConfigOpts instance has no attribute 'register_opts'"},{"fix":"Use unique metric names or check if metric exists before registering: if not client.has_metric('...'): client.register_metric(...).","cause":"Attempting to register a metric with a name that already exists in the client.","error":"ValueError: Metric '...' is already registered"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}