Monitor internet in R

library("beepr", "curl")

internet <- NULL

TimeToMonitorInSeconds <- 60 # 60*60*5
plot(0:TimeToMonitorInSeconds, rep(0, 1+TimeToMonitorInSeconds), xlim=c(0, TimeToMonitorInSeconds),
     ylim=c(0, 1), type="n", bty="n",
     xlab=paste0("Seconds since ", date()), ylab="Internet", yaxt="n", xaxt="n")
axis(1, 0:TimeToMonitorInSeconds)
axis(2, c(0, 1), labels = c("Correct", "Failed"), las=1)

previousx <- NULL
previousy <- NULL


for (i in 0:TimeToMonitorInSeconds) {
  t <- curl::has_internet()
  names(t) <- date()
  # print(t)
  if (!t) beep()
  internet <- c(internet, t)
  if (!is.null(previousx)) segments(x0=previousx, x1=i, y0=previousy, y1=ifelse(t, 0, 1))
  previousx <- i
  previousy <- ifelse(t, 0, 1)
  Sys.sleep(1)
}

# General plot
plot(0:TimeToMonitorInSeconds, ifelse(internet, 0, 1), ylim=c(0, 1), type="l", bty="n",
     xlab=paste0("Seconds since ", names(internet)[1]), ylab="Internet", yaxt="n")
axis(2, c(0, 1), labels = c("Correct", "Failed"), las=1)



Commentaires

Posts les plus consultés de ce blog

Standard error from Hessian Matrix... what can be done when problem occurs

Multivariable analysis and correlation of iconography

Install treemix in ubuntu 20.04