6 # NOTE: you need to run this on a PVE host, or modify the source to
7 # provide username/password/hostname from somewhere else.
9 use Time
::HiRes
qw( usleep ualarm gettimeofday tv_interval );
11 use PVE
::APIClient
::LWP
;
12 use PVE
::AccessControl
;
16 # normally you use username/password,
17 # but we can simply create a ticket and CRSF token if we are root
18 # running on a pve host
20 my $hostname = PVE
::INotify
::read_file
("hostname");
21 my $ticket = PVE
::AccessControl
::assemble_ticket
('root@pam');
22 my $csrftoken = PVE
::AccessControl
::assemble_csrf_prevention_token
('root@pam');
27 sub get_local_cert_fingerprint
{ my ($node) = @_; my $cert_path =
28 "/etc/pve/nodes/$node/pve-ssl.pem"; my $custom_cert_path =
29 "/etc/pve/nodes/$node/pveproxy-ssl.pem";
31 $cert_path = $custom_cert_path if -f
$custom_cert_path;
33 my $bio = Net
::SSLeay
::BIO_new_file
($cert_path, 'r'); my $cert =
34 Net
::SSLeay
::PEM_read_bio_X509
($bio); Net
::SSLeay
::BIO_free
($bio);
36 my $fp = Net
::SSLeay
::X509_get_fingerprint
($cert, 'sha256'); die
37 "got empty fingerprint" if !defined($fp) || ($fp eq '');
41 my $local_fingerprint = get_local_cert_fingerprint
($hostname);
46 my $conn = PVE
::APIClient
::LWP-
>new(
47 #username => 'root@pam',
48 #password => 'yourpassword',
50 csrftoken
=> $csrftoken,
52 # add local hosts cert fingerprint
53 cached_fingerprints
=> {
54 $local_fingerprint => 1,
57 for (my $i = 0; $i < $qcount; $i++) {
59 my $res = $conn->get("/", {});
62 print "ERROR: $err\n";
73 my $starttime = [gettimeofday
];
75 for (my $i = 0; $i < $wcount; $i++) {
76 if (my $pid = fork ()) {
87 my $elapsed = int(tv_interval
($starttime) * 1000);
89 my $tpq = $elapsed / ($wcount*$qcount);
91 print "$host: $tpq ms per query\n";
94 run_tests
("localhost"); # test 'pvedaemon'
96 run_tests
($hostname); # test 'pveproxy'