def restricted_registry(self, names):
names = set(names)<EOL>collectors = set()<EOL>with self._lock:<EOL><INDENT>for name in names:<EOL><INDENT>if name in self._names_to_collectors:<EOL><INDENT>collectors.add(self._names_to_collectors[name])<EOL><DEDENT><DEDENT><DEDENT>metrics = []<EOL>for collector in collectors:<EOL><INDENT>for metric in collector.collect():<EOL><INDENT>samples = [s for s in metric.samples if s[<NUM_LIT:0>] in names]<EOL>if samples:<EOL><INDENT>m = Metric(metric.name, metric.documentation, metric.type)<EOL>m.samples = samples<EOL>metrics.append(m)<EOL><DEDENT><DEDENT><DEDENT>class RestrictedRegistry(object):<EOL><INDENT>def collect(self):<EOL><INDENT>return metrics<EOL><DEDENT><DEDENT>return RestrictedRegistry()<EOL>
Returns object that only collects some metrics.

        Returns an object which upon collect() will return
        only samples with the given names.

        Intended usage is:
            generate_latest(REGISTRY.restricted_registry(['a_timeseries']))

        Experimental.