Merge pull request #761 from prometheus/status-page

Display more information on status page
This commit is contained in:
Max Inden 2017-05-02 09:45:42 +02:00 committed by GitHub
commit 233cad6591
5 changed files with 163 additions and 40 deletions

View File

@ -2,8 +2,8 @@ module Status.Api exposing (getStatus)
import Utils.Api exposing (baseUrl, send, get)
import Utils.Types exposing (ApiData)
import Status.Types exposing (StatusResponse)
import Json.Decode exposing (Decoder, map2, string, field, at)
import Status.Types exposing (StatusResponse, VersionInfo, MeshStatus, MeshPeer)
import Json.Decode exposing (Decoder, map2, string, field, at, list, int)
getStatus : (ApiData StatusResponse -> msg) -> Cmd msg
@ -20,6 +20,40 @@ getStatus msg =
decodeStatusResponse : Decoder StatusResponse
decodeStatusResponse =
map2 StatusResponse
(field "status" string)
(at [ "data", "uptime" ] string)
field "data" decodeData
decodeData : Decoder StatusResponse
decodeData =
Json.Decode.map4 StatusResponse
(field "config" string)
(field "uptime" string)
(field "versionInfo" decodeVersionInfo)
(field "meshStatus" decodeMeshStatus)
decodeVersionInfo : Decoder VersionInfo
decodeVersionInfo =
Json.Decode.map6 VersionInfo
(field "branch" string)
(field "buildDate" string)
(field "buildUser" string)
(field "goVersion" string)
(field "revision" string)
(field "version" string)
decodeMeshStatus : Decoder MeshStatus
decodeMeshStatus =
Json.Decode.map3 MeshStatus
(field "name" string)
(field "nickName" string)
(field "peers" (list decodeMeshPeer))
decodeMeshPeer : Decoder MeshPeer
decodeMeshPeer =
Json.Decode.map3 MeshPeer
(field "name" string)
(field "nickName" string)
(field "uid" int)

View File

@ -1,7 +1,33 @@
module Status.Types exposing (StatusResponse)
module Status.Types exposing (StatusResponse, VersionInfo, MeshStatus, MeshPeer)
type alias StatusResponse =
{ status : String
{ config : String
, uptime : String
, versionInfo : VersionInfo
, meshStatus : MeshStatus
}
type alias VersionInfo =
{ branch : String
, buildDate : String
, buildUser : String
, goVersion : String
, revision : String
, version : String
}
type alias MeshStatus =
{ name : String
, nickName : String
, peers : List MeshPeer
}
type alias MeshPeer =
{ name : String
, nickName : String
, uid : Int
}

View File

@ -26,7 +26,7 @@ currentView : Model -> Html Msg
currentView model =
case model.route of
StatusRoute ->
Status.view model
Status.view model.status
SilenceRoute silenceId ->
Silence.view model

View File

@ -1,42 +1,105 @@
module Views.Status.Views exposing (view)
import Html exposing (Html, text, button, div, li, ul, b)
import Status.Types exposing (StatusResponse)
import Types exposing (Msg(MsgForStatus), Model)
import Html exposing (..)
import Html.Attributes exposing (class, style)
import Status.Types exposing (StatusResponse, VersionInfo, MeshStatus, MeshPeer)
import Types exposing (Msg(MsgForStatus))
import Utils.Types exposing (ApiResponse(Failure, Success, Loading), ApiData)
import Views.Status.Types exposing (StatusModel)
import Utils.Views
view : Model -> Html Types.Msg
view model =
ul []
[ li []
[ b [] [ text "Status: " ], text (getStatus model.status.statusInfo) ]
, li []
[ b [] [ text "Uptime: " ], text (getUptime model.status.statusInfo) ]
view : StatusModel -> Html Types.Msg
view { statusInfo } =
case statusInfo of
Success info ->
viewStatusInfo info
Loading ->
Utils.Views.loading
Failure msg ->
Utils.Views.error msg
viewStatusInfo : StatusResponse -> Html Types.Msg
viewStatusInfo status =
div []
[ h1 [] [ text "Status" ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Uptime:" ]
, div [ class "col-sm-10" ] [ text status.uptime ]
]
, viewMeshStatus status.meshStatus
, viewVersionInformation status.versionInfo
, viewConfig status.config
]
getStatus : ApiData StatusResponse -> String
getStatus apiResponse =
case apiResponse of
Failure e ->
"Error occured when requesting status information: " ++ (toString e)
Loading ->
"Loading"
Success a ->
a.status
viewConfig : String -> Html Types.Msg
viewConfig config =
div []
[ h2 [] [ text "Config" ]
, pre [ class "p-4", style [ ( "background", "#f7f7f9" ), ( "font-family", "monospace" ) ] ]
[ code []
[ text config
]
]
]
getUptime : ApiData StatusResponse -> String
getUptime apiResponse =
case apiResponse of
Failure e ->
"Error occured when requesting status information: " ++ (toString e)
viewMeshStatus : MeshStatus -> Html Types.Msg
viewMeshStatus meshStatus =
span []
[ h2 [] [ text "Mesh Status" ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Name:" ]
, div [ class "col-sm-10" ] [ text meshStatus.name ]
]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Nick Name:" ]
, div [ class "col-sm-10" ] [ text meshStatus.nickName ]
]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Peers:" ]
, ul [ class "col-sm-10" ] <|
List.map viewMeshPeer meshStatus.peers
]
]
Loading ->
"Loading"
Success a ->
a.uptime
viewMeshPeer : MeshPeer -> Html Types.Msg
viewMeshPeer peer =
li []
[ div [ class "" ]
[ b [ class "" ] [ text "Name: " ]
, text peer.name
]
, div [ class "" ]
[ b [ class "" ] [ text "Nick Name: " ]
, text peer.nickName
]
, div [ class "" ]
[ b [ class "" ] [ text "UID: " ]
, text <| toString peer.uid
]
]
viewVersionInformation : VersionInfo -> Html Types.Msg
viewVersionInformation versionInfo =
span []
[ h2 [] [ text "Version Information" ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Branch:" ], div [ class "col-sm-10" ] [ text versionInfo.branch ] ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "BuildDate:" ], div [ class "col-sm-10" ] [ text versionInfo.buildDate ] ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "BuildUser:" ], div [ class "col-sm-10" ] [ text versionInfo.buildUser ] ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "GoVersion:" ], div [ class "col-sm-10" ] [ text versionInfo.goVersion ] ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Revision:" ], div [ class "col-sm-10" ] [ text versionInfo.revision ] ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Version:" ], div [ class "col-sm-10" ] [ text versionInfo.version ] ]
]

File diff suppressed because one or more lines are too long