@@ -2,6 +2,7 @@ package analyzer
22
33import (
44 "encoding/json"
5+ "fmt"
56 "path"
67 "strings"
78
@@ -64,6 +65,30 @@ var CephStatusDefaultOutcomes = []*troubleshootv1beta2.Outcome{
6465 },
6566}
6667
68+ type CephStatus struct {
69+ Health HealthStatus `json:"health"`
70+ OsdMap struct {
71+ OsdMap OsdMap `json:"osdmap"`
72+ } `json:"osdmap"`
73+ PgMap PgMap `json:"pgmap"`
74+ }
75+
76+ type HealthStatus struct {
77+ Status string `json:"status"`
78+ }
79+
80+ type OsdMap struct {
81+ NumOsd int `json:"num_osds"`
82+ NumUpOsd int `json:"num_up_osds"`
83+ Full bool `json:"full"`
84+ NearFull bool `json:"nearfull"`
85+ }
86+
87+ type PgMap struct {
88+ UsedBytes uint64 `json:"bytes_used"`
89+ TotalBytes uint64 `json:"bytes_total"`
90+ }
91+
6792func cephStatus (analyzer * troubleshootv1beta2.CephStatusAnalyze , getCollectedFileContents func (string ) ([]byte , error )) (* AnalyzeResult , error ) {
6893 fileName := path .Join (collect .GetCephCollectorFilepath (analyzer .CollectorName , analyzer .Namespace ), "status.json" )
6994 collected , err := getCollectedFileContents (fileName )
@@ -82,11 +107,7 @@ func cephStatus(analyzer *troubleshootv1beta2.CephStatusAnalyze, getCollectedFil
82107 IconURI : "https://troubleshoot.sh/images/analyzer-icons/rook.svg?w=11&h=16" ,
83108 }
84109
85- status := struct {
86- Health struct {
87- Status string `json:"status"`
88- } `json:"health"`
89- }{}
110+ status := CephStatus {}
90111 if err := json .Unmarshal (collected , & status ); err != nil {
91112 return nil , errors .Wrap (err , "failed to unmarshal status.json" )
92113 }
@@ -105,7 +126,7 @@ func cephStatus(analyzer *troubleshootv1beta2.CephStatusAnalyze, getCollectedFil
105126 return nil , errors .Wrap (err , "failed to compare ceph status" )
106127 } else if match {
107128 analyzeResult .IsFail = true
108- analyzeResult .Message = outcome .Fail .Message
129+ analyzeResult .Message = detailedCephMessage ( outcome .Fail .Message , status )
109130 analyzeResult .URI = outcome .Fail .URI
110131 return analyzeResult , nil
111132 }
@@ -118,7 +139,7 @@ func cephStatus(analyzer *troubleshootv1beta2.CephStatusAnalyze, getCollectedFil
118139 return nil , errors .Wrap (err , "failed to compare ceph status" )
119140 } else if match {
120141 analyzeResult .IsWarn = true
121- analyzeResult .Message = outcome .Warn .Message
142+ analyzeResult .Message = detailedCephMessage ( outcome .Warn .Message , status )
122143 analyzeResult .URI = outcome .Warn .URI
123144 return analyzeResult , nil
124145 }
@@ -173,3 +194,22 @@ func compareCephStatus(actual, when string) (bool, error) {
173194 return false , errors .New ("unknown operator" )
174195 }
175196}
197+
198+ func detailedCephMessage (msg string , status CephStatus ) string {
199+ if status .OsdMap .OsdMap .NumOsd > 0 {
200+ msg = fmt .Sprintf ("%s. %v/%v OSDs up" , msg , status .OsdMap .OsdMap .NumUpOsd , status .OsdMap .OsdMap .NumOsd )
201+ }
202+
203+ if status .OsdMap .OsdMap .Full {
204+ msg = fmt .Sprintf ("%s. OSD disk is full" , msg )
205+ } else if status .OsdMap .OsdMap .NearFull {
206+ msg = fmt .Sprintf ("%s. OSD disk is nearly full" , msg )
207+ }
208+
209+ if status .PgMap .TotalBytes > 0 {
210+ pgUsage := 100 * float64 (status .PgMap .UsedBytes ) / float64 (status .PgMap .TotalBytes )
211+ msg = fmt .Sprintf ("%s. PG storage usage is %.1f%%." , msg , pgUsage )
212+ }
213+
214+ return msg
215+ }
0 commit comments