Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaadF committed Oct 20, 2020
1 parent 9a1130f commit facd13e
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package com.normation.rudder.services.healthcheck

import java.lang.Runtime.getRuntime

import better.files.File
import better.files.File.root
import com.normation.errors.IOResult
import com.normation.rudder.domain.logger.{HealthcheckLoggerPure => logger}
import com.normation.rudder.hooks.Cmd
import com.normation.rudder.hooks.RunNuCommand
import com.normation.rudder.services.healthcheck.HealthcheckResult.Critical
import com.normation.rudder.services.healthcheck.HealthcheckResult.Warning
import com.normation.rudder.services.healthcheck.HealthcheckResult.Ok
Expand Down Expand Up @@ -59,4 +63,28 @@ final object CheckCoreNumber extends Check {
case n => Ok(s"${n} cores available")
}
}
}

final object CheckFreeSpace extends Check {
def name: CheckName = CheckName("Disk free space available")
def run: IOResult[HealthcheckResult] = {
// val cmd = Cmd("/usr/share/ncf/ncf", "write_all_methods" :: Nil, Map.empty)
val file = root/"proc"/"mounts"
val partc = file.lines.map(x => x.split(" ")(1)).toSet
val re = "^(/var)".r
val varDir = partc.filter(_.regionMatches())
val spaceTaken = partc.reduceLeft(_ + File(_).size)

for {
// updateCmd <- RunNuCommand.run(cmd)
// res <- updateCmd.await
availableCores <- IOResult.effect(getRuntime.availableProcessors)
} yield {
availableCores match {
case i if i <= 0 => Critical("No Core available")
case 1 => Warning(s"Only one cores available")
case n => Ok(s"${n} cores available")
}
}
}
}

0 comments on commit facd13e

Please sign in to comment.