1
0

mecha.pl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/perl -w
  2. # Klimbim Software collection, A bag full of things
  3. # Copyright (C) 2011-2023 Johannes 'Banana' Keßler
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. # 2020 by Johannes 'Banana' Keßler
  18. # some simple URL load check with running
  19. # headless (or not) chrome
  20. use warnings;
  21. use strict;
  22. use utf8;
  23. use WWW::Mechanize::Chrome;
  24. use Log::Log4perl qw(:easy);
  25. use Time::HiRes qw/ time sleep /;
  26. use File::Temp 'tempdir';
  27. # how often each url will be called
  28. my @timesToCheck = (1..10);
  29. # the urls to be called
  30. my @urlsToCheck = (
  31. 'https://www.some.tld',
  32. 'https://www.some.tld/with/path',
  33. 'https://www.some-other.tld'
  34. );
  35. my $mech = WWW::Mechanize::Chrome->new(
  36. launch_exe => '/usr/bin/google-chrome-stable', # path to your chome
  37. incognito => 1,
  38. data_directory => tempdir(CLEANUP => 1 ),
  39. launch_arg => [
  40. #"--headless", # headless or not
  41. "--disk-cache-dir=/dev/null",
  42. "--aggressive-cache-discard",
  43. "--disable-gpu",
  44. "--deterministic-mode",
  45. "--disk-cache-size=1",
  46. "--no-sandbox"
  47. ],
  48. cookie_jar => {}
  49. );
  50. $mech->add_header(
  51. 'user-agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/999.99 (KHTML, like Gecko) Chrome/79.0.3945.131 Safari/537.36',
  52. 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
  53. 'Accept-Charset' => 'iso-8859-1,*,utf-8',
  54. 'Accept-Language' => 'en-US',
  55. 'accept-encoding' => 'gzip, deflate, br',
  56. 'Cache-Control' => 'no-cache',
  57. );
  58. foreach my $url(@urlsToCheck) {
  59. my $displayUrl = substr($url, -70);
  60. for (@timesToCheck) {
  61. my $start = time;
  62. $mech->get($url.'?'.$start);
  63. if ($mech->success()) {
  64. my $time = time;
  65. $time = ($time - $start);
  66. my $out = sprintf "%s %.4f sec \n", $displayUrl, $time;
  67. print $out;
  68. }
  69. $mech->sleep( 2 );
  70. }
  71. }
  72. $mech->close();