<commit_before>#!/usr/bin/perl
#
# Copyright (C) 2006-2010 by <NAME>
#
# This package is free software; you can redistribute it and/or modify
# it under the terms of the Artistic License, included as the file
# "LICENSE" in the source code archive.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# You should have received a copy of the file "LICENSE", containing
# the License John Weiss originally placed this program under.
#
# $Id$
############


############
#
# Configuration Variables
#
############


my $_ConfigFile = undef();
my $_DataFile = "/tmp/mrtg-ping-bandwidth.dat";
my $_TieAttempts = 5;
my $_TieWait = 1;
my $_PostDaemonizeWait = 5;
#my $_DaemonPIDFile = "/tmp/mrtg-ping-bandwidth.pid";
my $_DaemonPIDFile = "/var/run/mrtg-ping-bandwidth.pid";
my $_DaemonLog = "/tmp/mrtg-ping-bandwidth.log";
my $_ProbeInterval = 5*60;
my $_ConfigUpdateInterval = 7;


############
#
# Precompilation Init
#
############
# Before anything else, split the script's name into directory/file.  We
# want to add the script's directory to the set of include-dirs.  This way, we
# get any packages living in the script's directory.
my $_MyName;
my $_MyPath;
BEGIN {
    if ($0 =~ m|\A(.*)/([^/]+\Z)|) {
        if ($1 ne ".") { $_MyPath = $1; }
        $_MyName = $2;
    } else { $_MyName = $0; }  # No path; only the script name.
    if (defined($_MyPath)) { push @INC, $_MyPath; }
}


############
#
# Includes/Packages
#
############


require 5;
use strict;
use bytes;           # Overrides Unicode support
use Data::Dumper;
use Tie::File;
use POSIX qw(nice setsid);


############
#
# Other Global Variables
#
############


my $_TracerouteCmd = "traceroute -4 -n -w 1 -N 1 ";
# WARMING:  A packet size above 1k will not work with all hosts.
#my $_PingCmd = "/bin/ping -A -n -c 5 -w 5 -s 32768 ";
my $_PingCmd = "/bin/ping -A -n -c 5 -w 5 -s 1024 ";
my @_Measurements;
my $_refDataTieObj;


############
#
# Functions
#
############


#
# Ping/Traceroute
#

sub bandwidth_ping($) {
    my $host = shift();

    my $pingcmd=$_PingCmd;
    $pingcmd .= $host;
    $pingcmd .= " 2>&1 |";
    #print STDERR ("#DBG#  Running:  $pingcmd\n");
    unless (open(PINGFH, $pingcmd)) {
        print STDERR ("FATAL: Can't run command: ", $pingcmd,
                      "\nReason: \"", $!, "\"\n");
        return -1;
    }
    my @pingLines = <PINGFH>;
    close(PINGFH);

    my $bytes = 0;
    my $msecs = 0;
    foreach (@pingLines) {
        if (m/(\d+) bytes from .* time=([[:digit:].]+) ms/) {
            $bytes += $1;
            $msecs += $2;
        }
    }

    my $rate = $bytes;
    if ($msecs) {
        $rate /= $msecs;
        $rate *= 1000;
    } else {<commit_msg>Added some debugging print()'s to bandwidth_ping().<commit_after>#!/usr/bin/perl
#
# Copyright (C) 2006-2010 by <NAME>
#
# This package is free software; you can redistribute it and/or modify
# it under the terms of the Artistic License, included as the file
# "LICENSE" in the source code archive.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# You should have received a copy of the file "LICENSE", containing
# the License <NAME> originally placed this program under.
#
# $Id$
############


############
#
# Configuration Variables
#
############


my $_ConfigFile = undef();
my $_DataFile = "/tmp/mrtg-ping-bandwidth.dat";
my $_TieAttempts = 5;
my $_TieWait = 1;
my $_PostDaemonizeWait = 5;
#my $_DaemonPIDFile = "/tmp/mrtg-ping-bandwidth.pid";
my $_DaemonPIDFile = "/var/run/mrtg-ping-bandwidth.pid";
my $_DaemonLog = "/tmp/mrtg-ping-bandwidth.log";
my $_ProbeInterval = 5*60;
my $_ConfigUpdateInterval = 7;


############
#
# Precompilation Init
#
############
# Before anything else, split the script's name into directory/file.  We
# want to add the script's directory to the set of include-dirs.  This way, we
# get any packages living in the script's directory.
my $_MyName;
my $_MyPath;
BEGIN {
    if ($0 =~ m|\A(.*)/([^/]+\Z)|) {
        if ($1 ne ".") { $_MyPath = $1; }
        $_MyName = $2;
    } else { $_MyName = $0; }  # No path; only the script name.
    if (defined($_MyPath)) { push @INC, $_MyPath; }
}


############
#
# Includes/Packages
#
############


require 5;
use strict;
use bytes;           # Overrides Unicode support
use Data::Dumper;
use Tie::File;
use POSIX qw(nice setsid);


############
#
# Other Global Variables
#
############


my $_TracerouteCmd = "traceroute -4 -n -w 1 -N 1 ";
# WARMING:  A packet size above 1k will not work with all hosts.
#my $_PingCmd = "/bin/ping -A -n -c 5 -w 5 -s 32768 ";
my $_PingCmd = "/bin/ping -A -n -c 5 -w 5 -s 1024 ";
my @_Measurements;
my $_refDataTieObj;


############
#
# Functions
#
############


#
# Ping/Traceroute
#

sub bandwidth_ping($) {
    my $host = shift();

    my $pingcmd=$_PingCmd;
    $pingcmd .= $host;
    $pingcmd .= " 2>&1 |";
    #print STDERR ("#DBG#  Running:  $pingcmd\n");
    unless (open(PINGFH, $pingcmd)) {
        print STDERR ("FATAL: Can't run command: ", $pingcmd,
                      "\nReason: \"", $!, "\"\n");
        return -1;
    }
    my @pingLines = <PINGFH>;
    close(PINGFH);
    #print STDERR ("#DBG#:  @pingLines\n");

    my $bytes = 0;
    my $msecs = 0;
    foreach (@pingLines) {
        if (m/(\d+) bytes from .* time=([[:digit:].]+) ms/) {
            #print STDERR ("#DBG#:  ", $1, " bytes, ", $2, " ms\n");
            $bytes += $1;
            $msecs += $2;
            #print STDERR ("#DBG# Sums: ", $bytes, " b, ", $msecs, " ms\n");
        }
    }

    my $rate = $bytes;
    if ($msecs) {
        $rate /= $msecs;
        $rate *= 1000;
    } else {
{'fraction_non_alphanumeric': 0.19313524590163936, 'fraction_numerical': 0.01707650273224044, 'mean_word_length': 2.894281914893617, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4588717', 'n_tokens_mistral': 2198, 'n_tokens_neox': 2036, 'n_words': 647}