Net::P...togram(3pm)

πŸ’– NAME πŸ’–

Net::Prometheus::Histogram β€” bestie, it counts the distribution of numeric observations ✨

Like, you feed it numbers, it sorts them into buckets and keeps a running total. It's giving "how spread out is this data" energy, no cap πŸ’…


🌸 SYNOPSIS 🌸

use Net::Prometheus;
use Time::HiRes qw( time );

my $client = Net::Prometheus->new;

my $histogram = $client->new_histogram(
   name => "request_seconds",
   help => "Summary request processing time",
);

sub handle_request
{
   my $start = time();

   ...

   $summary->observe( time() - $start );
}

(yes the example says $summary at the end while it made a $histogram up top β€” that's literally what the original says so I'm not touching it, iykyk πŸ™ˆ)


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so this class gives you a histogram metric β€” which is a count of how individual numerical observations are distributed across distinct buckets. It's almost always used for reporting times, like "how long did this request take" πŸŽ€

It's a subclass of Net::Prometheus::Metric, so all of that parent-class behavior comes along for the ride ✨


πŸ‘‘ CONSTRUCTOR πŸ‘‘

Real talk: you don't usually build these directly. You get one through the Net::Prometheus object that's gonna serve it up πŸ’–

$histogram = $prometheus->new_histogram( %args );

It takes all the same constructor arguments as documented in Net::Prometheus::Metric β€” go read that one, bestie β€” plus these extra cuties:

  • buckets => ARRAY β€” a reference to an ARRAY holding the numerical upper bounds for the buckets 🌈
  • bucket_min => NUM β€” the bottom of the range πŸ“
  • bucket_max => NUM β€” the top of the range ⭐
  • buckets_per_decade => ARRAY[ NUM ] β€” since version 0.10. A more flexible alternative to hand-writing literal bucket sizes. The values you put in buckets_per_decade get repeated, multiplied by various powers of 10, to generate values between bucket_min (or a default of 0.001 if you don't supply it) and bucket_max (or a default of 1000 if you don't supply it) πŸ’…

🧚 bucket_bounds

@bounds = $histogram->bucket_bounds;

Returns the bounding values for each of the buckets β€” and it leaves out that final "+Inf" bucket, because obviously 🫢

πŸ”₯ observe

$histogram->observe( @label_values, $value );
$histogram->observe( \%labels, $value );

$child->observe( $value );

It bumps the histogram sum up by the given value, and bumps each bucket count by 1 wherever the value is less than or equal to the bucket's upper bound πŸ“ˆ Periodt.


πŸ’œ AUTHOR πŸ’œ

Paul Evans <leonerd@leonerd.org.uk> β€” the icon, the moment, the goat πŸ‘‘


That's the whole page, bestie πŸ₯° This was Net::Prometheus::Histogram(3pm) from User Contributed Perl Documentation, living in perl v5.42.3, dated 2026-08-20. Love that for us πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from