Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added for metrics
- Loading branch information
Showing
9 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
cardano-node/src/Cardano/Node/Tracing/Tracers/NodeVersion.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
{-# OPTIONS_GHC -Wno-name-shadowing #-} | ||
|
||
module Cardano.Node.Tracing.Tracers.NodeVersion | ||
( | ||
NodeVersionTrace (..) | ||
, getNodeVersion | ||
) | ||
where | ||
|
||
import Cardano.Logging | ||
import Data.Aeson (toJSON, (.=)) | ||
import Data.Text (Text, pack) | ||
|
||
import Data.Version (Version (..), showVersion) | ||
|
||
import Cardano.Git.Rev (gitRev) | ||
|
||
import Paths_cardano_node (version) | ||
import System.Info (arch, compilerName, compilerVersion, os) | ||
|
||
|
||
|
||
data NodeVersionTrace = NodeVersionTrace | ||
{ applicationName :: Text | ||
, applicationVersion :: Version | ||
, osName :: Text | ||
, architecture :: Text | ||
, compilerName :: Text | ||
, compilerVersion :: Version | ||
, gitRevision :: Text | ||
} deriving (Eq, Show) | ||
|
||
getNodeVersion :: NodeVersionTrace | ||
getNodeVersion = | ||
let applicationName = "cardano-node" | ||
applicationVersion = version | ||
osName = pack os | ||
architecture = pack arch | ||
compilerName = pack System.Info.compilerName | ||
compilerVersion = System.Info.compilerVersion | ||
|
||
gitRevision = $(gitRev) | ||
in NodeVersionTrace {..} | ||
|
||
instance MetaTrace NodeVersionTrace where | ||
namespaceFor NodeVersionTrace {} = | ||
Namespace [] ["NodeVersion"] | ||
severityFor (Namespace _ ["NodeVersion"]) _ = Just Info | ||
severityFor _ _ = Nothing | ||
|
||
documentFor (Namespace _ ["NodeVersion"]) = Just "Node version information" | ||
|
||
documentFor _ = Nothing | ||
|
||
metricsDocFor (Namespace _ ["NodeVersion"]) = | ||
[("Cardano.Version.Major", "Cardano node version information") | ||
,("Cardano.Version.Minor", "Cardano node version information") | ||
,("Cardano.Version.Patch", "Cardano node version information") | ||
,("Cardano.Version.GitRevision", "Cardano node version information") | ||
,("Cardano.CompilerName", "Cardano compiler name") | ||
,("Cardano.CompilerMajor", "Cardano compiler version information") | ||
,("Cardano.CompilerMinor", "Cardano compiler version information") | ||
,("Cardano.CompilerPatch", "Cardano compiler version information") | ||
,("Cardano.OSName", "Cardano node operating system information") | ||
,("Cardano.Architecture", "Cardano node architecture information") | ||
,("Cardano_Build_Info", "Cardano node build info") | ||
,("Haskell_Build_Info", "Haskell compiler build information") | ||
] | ||
metricsDocFor _ = [] | ||
|
||
allNamespaces = [Namespace [] ["NodeVersion"]] | ||
|
||
instance LogFormatting NodeVersionTrace where | ||
forHuman NodeVersionTrace {..} = mconcat | ||
[ "cardano-node ", pack (showVersion applicationVersion) | ||
, " git rev ", gitRevision | ||
, " - ", pack os, "-", pack arch | ||
, " - ", compilerName, "-", pack (showVersion compilerVersion) | ||
] | ||
|
||
forMachine _dtal NodeVersionTrace {..} = mconcat | ||
|
||
[ "applicationName" .= applicationName | ||
, "applicationVersion" .= toJSON applicationVersion | ||
, "gitRevision" .= gitRevision | ||
, "osName" .= osName | ||
, "architecture" .= architecture | ||
, "compilerName" .= compilerName | ||
, "compilerVersion" .= toJSON compilerVersion | ||
] | ||
|
||
asMetrics nvt@NodeVersionTrace {..} = | ||
[ IntM "Cardano.Version.Major" (fromIntegral (getMajor applicationVersion)) | ||
, IntM "Cardano.Version.Minor" (fromIntegral (getMinor applicationVersion)) | ||
, IntM "Cardano.Version.Patch" (fromIntegral (getPatch applicationVersion)) | ||
, IntM ("Cardano.Version.GitRevision " <> gitRevision) 1 | ||
, IntM ("Cardano.CompilerName " <> compilerName) 1 | ||
, IntM "Cardano.CompilerMajor " (fromIntegral (getMajor compilerVersion)) | ||
, IntM "Cardano.CompilerMinor " (fromIntegral (getMinor compilerVersion)) | ||
, IntM "Cardano.CompilerPatch " (fromIntegral (getPatch compilerVersion)) | ||
, IntM ("Cardano.OSName " <> osName) 1 | ||
, IntM ("Cardano.Architecture " <> architecture) 1 | ||
, IntM ("Cardano_Build_Info " <> getCardanoBuildInfo nvt) 1 | ||
, IntM ("Haskell_Build_Info " <> getHaskellBuildInfo nvt) 1 | ||
] | ||
|
||
getCardanoBuildInfo :: NodeVersionTrace -> Text | ||
getCardanoBuildInfo NodeVersionTrace {..} = pack $ showVersion applicationVersion | ||
|
||
|
||
getHaskellBuildInfo :: NodeVersionTrace -> Text | ||
getHaskellBuildInfo NodeVersionTrace {..} = pack $ showVersion compilerVersion | ||
|
||
getMajor :: Version -> Int | ||
getMajor (Version (x:_) _) = x | ||
getMajor _ = 0 | ||
|
||
getMinor :: Version -> Int | ||
getMinor (Version (_:x:_) _) = x | ||
getMinor _ = 0 | ||
|
||
|
||
getPatch :: Version -> Int | ||
getPatch (Version (_:_:x:_) _) = x | ||
getPatch _ = 0 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters