The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojo::Netdata::Collector::HTTP - A website collector for Mojo::Netdata

SYNOPSIS

Config

Below is an example /etc/netdata/mojo.conf.d/http.conf.pl config file. Note that the file can have any name and you have have as many as you want, as long as it has the .conf.pl extension.

  {
    # Required
    collector => 'Mojo::Netdata::Collector::HTTP',

    # Optional
    concurrency     => 4,     # Number of HTTP requests at the same time
    insecure        => 0,     # Set to "1" to allow insecure SSL/TLS connections
    connect_timeout => 5,     # Max time for the connection to be established
    request_timeout => 5,     # Max time for the whole request to complete
    proxy           => 1,     # Set to "0" to disable proxy auto-detect
    update_every    => 30,    # How often to run the "jobs" below
    user_agent      => '...', # Custom User-Agent name

    # Default values, unless defined in the job
    family  => 'default-family-name',
    headers => {'X-Merged-With' => 'headers inside job config'},

    # Required - List of URLs and an optional config hash (object)
    jobs => [

      # List of URLs to check (Config is optional)
      'https://superwoman.example.com',
      'https://superman.example.com',

      # URL and config parameters
      'https://example.com' => {
        method  => 'GET',              # GET (Default), HEAD, POST, ...
        headers => {'X-Foo' => 'bar'}, # HTTP headers

        # Replace "host" in the URL with this IP and set the "Host" header
        via => '192.168.2.1',

        # Set "dimension" to get a custom label in the chart.
        # Default to the "Host" header or the host part of the URL.
        dimension => 'foo', # Default: "example.com"

        # Set "family" to group multiple domains together in one chart,
        # Default to the "Host" header or the host part of the URL.
        family => 'bar', # Default: "example.com"

        # Only one of these can be present
        json   => {...},           # JSON HTTP body
        form   => {key => $value}, # Form data
        body   => '...',           # Raw HTTP body
      },
    ],
  };

Health

Here is an example /etc/netdata/health.d/mojo-http.conf file:

   template: web_server_code
         on: httpcheck.code
      class: Errors
       type: Web Server
  component: HTTP endpoint
     plugin: mojo
     lookup: max -5m absolute foreach *
      every: 1m
       warn: $this >= 300 && $this < 500
       crit: $this >= 500 && $this != 503
         to: webmaster

   template: web_server_up
         on: httpcheck.code
      class: Errors
       type: Web Server
  component: HTTP endpoint
     plugin: mojo
     lookup: min -5m absolute foreach *
      every: 1m
       crit: $this == 0
      units: up/down
         to: webmaster

DESCRIPTION

Mojo::Netdata::Collector::HTTP is a collector that can chart web page response time and HTTP status codes.

ATTRIBUTES

concurrency

  $int = $collector->concurrency;

Number of requests that should be performed at the same time. Default is 4.

jobs

  $array_ref = $collector->jobs;

A list of jobs generated by "register".

type

  $str = $collector->type;

Defaults to "HTTP".

ua

  $ua = $collector->ua;

Holds a Mojo::UserAgent.

update_every

  $num = $chart->update_every;

Default value is 30. See "update_every" in Mojo::Netdata::Collector for more details.

METHODS

register

  $collector = $collector->register(\%config, $netdata);

Returns a $collector object if any "jobs" are defined in %config. Will also set "update_every" from %config or use "update_every" in Mojo::Netdata if it is 10 or greater.

update_p

  $p = $collector->update_p;

Gathers information about the "jobs" registered.

SEE ALSO

Mojo::Netdata and Mojo::Netdata::Collector.