title: code for uptime availability of an API call
body: <p>I have a Perl script that runs every 5 minutes which does an API call. This API call consist of a REST call to authenticate to the database. If I authenticate successfully, it returns an 'ok' or a '1'.</p>
  
  <p>I've been tasked to give our front end developer the uptime availability of this API call. For example, something to the nature of '99.98888' that reflects a range; for example, a range of 90 days or possibility 365 days.</p>
  
  <p>Here is the script that does the API call.</p>
  
  <pre><code>#!/usr/bin/perl -w
  use strict;
  use LWP::UserAgent;
  use Data::Dumper;
  use XML::Simple;
  use JSON;
  
  
  ## Perl's way of slurping the xml file
  my $message = do {
    open my $fh, '&lt;', '/usr/lib/xymon/server/ext/States/Puerto-Rico/credentials.xml' or die "Could not open file: $!";
    local $/;
    &lt;$fh&gt;;
  };
  
  
      my $start = `date +%s.%N`;
      my $webpage = "https://xxxxxxxxx/xxxxxx.asp";
  
      my $ua = LWP::UserAgent-&gt;new;
      my $response = $ua-&gt;post($webpage, Content_Type =&gt; 'text/xml',
                                              Content =&gt; $message);
      my $end = `date +%s.%N`;
      my $eventtime = `date +%c`;
      my $time = $end - $start;
      my $response_time = sprintf "%.1f", $time;
  
  
      if ( $response-&gt;is_success) {
  
  my $xml = new XML::Simple;
  my $x = $response-&gt;decoded_content;
  
  # read XML file
  my $data = $xml-&gt;XMLin($x);
  
  
  
  my $success =  $data-&gt;{'success'};
  
  
  
  if ( $response_time &lt; 5 &amp;&amp; $success == '1' )
  {
  print "good\n";
  }
  </code></pre>
  
  <p>I need to add the code or mathematical formula to give me the uptime availability of this API call for 90 or 365 days (script can run every 1 or 5 minutes) in this Perl script so it can populate a text file. Then the front end developer will retrieve the data from the text file and make a pretty web page or JavaScript call. Any hints will be appreciated and I could write this in python too.</p>