support flattened osdmap format added in octopus
This commit is contained in:
parent
94efb30be1
commit
2122a3331f
|
@ -60,11 +60,11 @@ func (exporter *Exporter) getCollectors() []prometheus.Collector {
|
|||
|
||||
func (exporter *Exporter) cephVersionCmd() []byte {
|
||||
cmd, err := json.Marshal(map[string]interface{}{
|
||||
"prefix": "Version",
|
||||
"prefix": "version",
|
||||
"format": "json",
|
||||
})
|
||||
if err != nil {
|
||||
exporter.Logger.WithError(err).Panic("failed to marshal ceph Version command")
|
||||
exporter.Logger.WithError(err).Panic("failed to marshal ceph version command")
|
||||
}
|
||||
|
||||
return cmd
|
||||
|
@ -87,6 +87,7 @@ func (exporter *Exporter) setCephVersion() error {
|
|||
|
||||
parsedVersion, err := ParseCephVersion(cephVersion.Version)
|
||||
if err != nil {
|
||||
exporter.Logger.Info("version " + cephVersion.Version)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -113,15 +114,15 @@ func (exporter *Exporter) Describe(ch chan<- *prometheus.Desc) {
|
|||
// prometheus. Collect could be called several times concurrently
|
||||
// and thus its run is protected by a single mutex.
|
||||
func (exporter *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||
exporter.mu.Lock()
|
||||
defer exporter.mu.Unlock()
|
||||
|
||||
err := exporter.setCephVersion()
|
||||
if err != nil {
|
||||
exporter.Logger.WithError(err).Error("failed to set ceph Version")
|
||||
return
|
||||
}
|
||||
|
||||
exporter.mu.Lock()
|
||||
defer exporter.mu.Unlock()
|
||||
|
||||
for _, cc := range exporter.getCollectors() {
|
||||
cc.Collect(ch)
|
||||
}
|
||||
|
|
|
@ -976,6 +976,13 @@ func (c *ClusterHealthCollector) collectorList() []prometheus.Collector {
|
|||
}
|
||||
}
|
||||
|
||||
type osdMap struct {
|
||||
NumOSDs float64 `json:"num_osds"`
|
||||
NumUpOSDs float64 `json:"num_up_osds"`
|
||||
NumInOSDs float64 `json:"num_in_osds"`
|
||||
NumRemappedPGs float64 `json:"num_remapped_pgs"`
|
||||
}
|
||||
|
||||
type cephHealthStats struct {
|
||||
Health struct {
|
||||
Summary []struct {
|
||||
|
@ -991,15 +998,8 @@ type cephHealthStats struct {
|
|||
} `json:"summary"`
|
||||
} `json:"checks"`
|
||||
} `json:"health"`
|
||||
OSDMap struct {
|
||||
OSDMap struct {
|
||||
NumOSDs float64 `json:"num_osds"`
|
||||
NumUpOSDs float64 `json:"num_up_osds"`
|
||||
NumInOSDs float64 `json:"num_in_osds"`
|
||||
NumRemappedPGs float64 `json:"num_remapped_pgs"`
|
||||
} `json:"osdmap"`
|
||||
} `json:"osdmap"`
|
||||
PGMap struct {
|
||||
OSDMap map[string]interface{} `json:"osdmap"`
|
||||
PGMap struct {
|
||||
NumPGs float64 `json:"num_pgs"`
|
||||
TotalObjects float64 `json:"num_objects"`
|
||||
WriteOpPerSec float64 `json:"write_op_per_sec"`
|
||||
|
@ -1350,15 +1350,38 @@ func (c *ClusterHealthCollector) collect(ch chan<- prometheus.Metric) error {
|
|||
c.CacheFlushIORate.Set(stats.PGMap.CacheFlushBytePerSec)
|
||||
c.CachePromoteIOOps.Set(stats.PGMap.CachePromoteOpPerSec)
|
||||
|
||||
c.OSDsUp.Set(stats.OSDMap.OSDMap.NumUpOSDs)
|
||||
c.OSDsIn.Set(stats.OSDMap.OSDMap.NumInOSDs)
|
||||
c.OSDsNum.Set(stats.OSDMap.OSDMap.NumOSDs)
|
||||
var actualOsdMap osdMap
|
||||
if c.version.IsAtLeast(Octopus) {
|
||||
if stats.OSDMap != nil {
|
||||
actualOsdMap = osdMap{
|
||||
NumOSDs: stats.OSDMap["num_osds"].(float64),
|
||||
NumUpOSDs: stats.OSDMap["num_up_osds"].(float64),
|
||||
NumInOSDs: stats.OSDMap["num_in_osds"].(float64),
|
||||
NumRemappedPGs: stats.OSDMap["num_remapped_pgs"].(float64),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if stats.OSDMap != nil {
|
||||
innerMap := stats.OSDMap["osdmap"].(map[string]interface{})
|
||||
|
||||
actualOsdMap = osdMap{
|
||||
NumOSDs: innerMap["num_osds"].(float64),
|
||||
NumUpOSDs: innerMap["num_up_osds"].(float64),
|
||||
NumInOSDs: innerMap["num_in_osds"].(float64),
|
||||
NumRemappedPGs: innerMap["num_remapped_pgs"].(float64),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.OSDsUp.Set(actualOsdMap.NumUpOSDs)
|
||||
c.OSDsIn.Set(actualOsdMap.NumInOSDs)
|
||||
c.OSDsNum.Set(actualOsdMap.NumOSDs)
|
||||
|
||||
// Ceph (until v10.2.3) doesn't expose the value of down OSDs
|
||||
// from its status, which is why we have to compute it ourselves.
|
||||
c.OSDsDown.Set(stats.OSDMap.OSDMap.NumOSDs - stats.OSDMap.OSDMap.NumUpOSDs)
|
||||
c.OSDsDown.Set(actualOsdMap.NumOSDs - actualOsdMap.NumUpOSDs)
|
||||
|
||||
c.RemappedPGs.Set(stats.OSDMap.OSDMap.NumRemappedPGs)
|
||||
c.RemappedPGs.Set(actualOsdMap.NumRemappedPGs)
|
||||
c.TotalPGs.Set(stats.PGMap.NumPGs)
|
||||
c.Objects.Set(stats.PGMap.TotalObjects)
|
||||
|
||||
|
|
|
@ -816,6 +816,7 @@ $ sudo ceph -s
|
|||
)
|
||||
|
||||
collector := NewClusterHealthCollector(&Exporter{Conn: conn, Cluster: "ceph", Logger: logrus.New()})
|
||||
collector.version = &Version{Major: 14, Minor: 2, Patch: 0}
|
||||
err := prometheus.Register(collector)
|
||||
require.NoError(t, err)
|
||||
defer prometheus.Unregister(collector)
|
||||
|
|
|
@ -73,7 +73,9 @@ func ParseCephVersion(cephVersion string) (*Version, error) {
|
|||
}
|
||||
|
||||
otherVersions := strings.Split(someVersions[2], "-")
|
||||
if len(otherVersions) != 3 {
|
||||
if len(otherVersions) == 1 {
|
||||
otherVersions = []string{otherVersions[0], "0", ""}
|
||||
} else if len(otherVersions) != 3 {
|
||||
return nil, ErrInvalidVersion
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,12 @@ func TestParseCephVersion(t *testing.T) {
|
|||
want: &Version{Major: 16, Minor: 2, Patch: 3, Revision: 33, Commit: "gcc1e126"},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "real pacific",
|
||||
args: args{cephVersion: "ceph version 16.2.7 (dd0603118f56ab514f133c8d2e3adfc983942503) pacific (stable)"},
|
||||
want: &Version{Major: 16, Minor: 2, Patch: 7, Revision: 0, Commit: ""},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue