InfluxDB::HTTP(3pm)
π InfluxDB::HTTP π
okay bestie, so this is the Perl way to talk to InfluxDB β and honestly? it ate. the manual name is InfluxDB::HTTP and it ships in the User Contributed Perl Documentation, so you already know it's community-coded. π«Ά
β¨ VERSION β¨
Version 0.04 β baby version number but the vibes are immaculate.
π SYNOPSIS π
So InfluxDB::HTTP is your little portal into the InfluxDB HTTP API. the way it works is so clean: basically one method per InfluxDB HTTP API endpoint, and those endpoints are ping, write and query. that's it, that's the whole squad. π
use InfluxDB::HTTP;
my $influx = InfluxDB::HTTP->new();
my $ping_result = $influx->ping();
print "$ping_result\n";
my $query = $influx->query(
[ 'SELECT Lookups FROM _internal.monitor.runtime WHERE time > '.(time - 60)*1000000000, 'SHOW DATABASES'],
epoch => 's',
);
print "$query\n";
π¦ SUBROUTINES/METHODS π¦
π RETURN VALUES AND ERROR HANDLING
Object::Result is the backbone here β it's what hands you data back from every subroutine. the result object it gives you is always usable as a string, and you can also evaluate it on a boolean basis. no cap.
here's the tea: if a result object evaluates to false, that means something went wrong (an error, bestie π), and the matching error message is sitting right there in the error attribute:
my $ping = $influx->ping();
print $ping->error unless ($ping);
and on top of all that, every single result object gives you access to the HTTP::Response object that InfluxDB sent back β it lives in the raw attribute. so you can poke at the raw response whenever you're feeling nosy. β¨
πΈ new host => 'localhost', port => 8086, timeout => 600
Passing host, port and/or timeout is totally optional, bestie. if you don't, it defaults to the InfluxDB defaults β except for the timeout, which defaults to 3 minutes. and yes, that timeout is measured in seconds. β±οΈ
Returns an instance of InfluxDB::HTTP. your new best friend, basically.
π ping
Pings the InfluxDB instance you set up in the constructor (so, whatever you gave it for host and port).
the object it hands back evaluates to true or false depending on whether the ping actually worked or flopped. and if it's true? it's carrying a version attribute that tells you which InfluxDB version is running on the server you just pinged. iconic.
that version attribute gets extracted from the X-Influxdb-Version HTTP response header β which is part of the HTTP response coming back from the pinged InfluxDB instance. iykyk. π«
my $ping = $influx->ping();
print $ping->version if ($ping);
π§ query query, database => "DATABASE", chunk_size => CHUNK_SIZE, epoch => "ns"
This one is for querying the InfluxDB instance. every parameter except the first one is optional β the first one is doing all the heavy lifting.
so that query parameter? it can be a String, or it can be a Perl ArrayRef of Strings, where every String holds one valid InfluxDB query. your call. β¨
if the returned object evaluates to true (meaning your query slayed), then the returned object's data attribute contains the entire response from InfluxDB as a Perl hash. and bonus: the request_id attribute gives you the request identifier, as set in the HTTP response headers by InfluxDB. that's lowkey so useful for correlating requests with log files. π₯
π write measurement, database => "DATABASE", precision => "ns", retention_policy => "RP"
Writes data into InfluxDB. the measurement parameter can be a String or an ArrayRef of Strings, where each String contains one valid InfluxDB LineProtocol statement. all of those measurements then get sent off to InfluxDB and the database you specified. the returned object evaluates to true if the write was successful β and false otherwise. π€
the optional argument precision is there for when you're using a precision other than ns in the line protocol. the InfluxDB docs suggest that using a coarser precision than ns can save space and processing β in many cases s or m might do. π
the optional argument retention_policy lets you specify a retention policy that isn't the default retention policy of the database you picked.
π get_lwp_useragent
Returns the internally used LWP::UserAgent instance so you can modify it β for example, to configure an HTTP proxy. go forth and customize. π
π AUTHOR π
Raphael Seebacher, <raphael@seebachers.ch>
π BUGS π
Please report any bugs or feature requests to <https://github.com/raphaelthomas/InfluxDB-HTTP/issues>. (bestie please actually report them, don't just suffer in silence π)
π LICENSE AND COPYRIGHT π
MIT License
Copyright (c) 2016 Raphael Seebacher
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
okay and that's the whole page!! π this documentation was brought to you by perl v5.38.2 and it's dated 2024-05-16 β so go ping something, write something, query something. main character energy only. periodt. πβ¨π
π¦ where this page comes from
- debian trixie: libinfluxdb-http-perl 0.04-3 Β· MIT
- ubuntu resolute: libinfluxdb-http-perl 0.04-3 Β· MIT
- ubuntu stonking: libinfluxdb-http-perl 0.04-3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms