Add metricsAction: supervised loop sampling ekg store to rrd via rrdtool
This commit is contained in:
@@ -14,9 +14,19 @@ import HomeAssistant.Runtime.Metrics
|
||||
, buildSchema
|
||||
, buildCreateArgs
|
||||
, buildUpdateArgs
|
||||
, ensureRrd
|
||||
, sampleAndUpdate
|
||||
, metricsAction
|
||||
)
|
||||
import qualified System.Metrics as M (Value (..))
|
||||
import Test.Hspec
|
||||
import Control.Exception (try, SomeException)
|
||||
import System.Directory (findExecutable, getTemporaryDirectory, removeFile)
|
||||
import System.Exit (ExitCode (ExitSuccess))
|
||||
import System.Process (readProcessWithExitCode)
|
||||
import qualified System.Metrics as Metrics
|
||||
import qualified System.Metrics.Counter as Counter
|
||||
import qualified System.Metrics.Gauge as Gauge
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
@@ -96,3 +106,26 @@ spec = do
|
||||
, "ds1"
|
||||
, "N:U"
|
||||
]
|
||||
|
||||
describe "end-to-end (rrdtool-gated)" $ do
|
||||
it "creates an rrd, samples, and updates it" $ do
|
||||
mRrdtool <- findExecutable "rrdtool"
|
||||
case mRrdtool of
|
||||
Nothing -> pendingWith "rrdtool not on PATH"
|
||||
Just rrdtool -> do
|
||||
store <- Metrics.newStore
|
||||
c <- Metrics.createCounter "test.counter" store
|
||||
g <- Metrics.createGauge "test.gauge" store
|
||||
Counter.inc c
|
||||
Gauge.set g 42
|
||||
tmp <- getTemporaryDirectory
|
||||
let rrdPath = tmp ++ "/hass-controller-metrics-test.rrd"
|
||||
_ <- try (removeFile rrdPath) :: IO (Either SomeException ())
|
||||
schema <- buildSchema <$> Metrics.sampleAll store
|
||||
ensureRrd rrdtool rrdPath schema
|
||||
sampleAndUpdate store rrdtool rrdPath schema
|
||||
(rc, out, _) <- readProcessWithExitCode rrdtool ["fetch", rrdPath, "AVERAGE"] ""
|
||||
rc `shouldBe` ExitSuccess
|
||||
length out `shouldSatisfy` (> 0)
|
||||
_ <- try (removeFile rrdPath) :: IO (Either SomeException ())
|
||||
return ()
|
||||
|
||||
Reference in New Issue
Block a user