mirror of
https://github.com/digitalocean/ceph_exporter
synced 2025-02-17 20:06:52 +00:00
Use MgrCommand for "osd df", "osd perf" and "pg dump pgs_brief"
This commit is contained in:
parent
238f39a71b
commit
252eb6604a
@ -15,6 +15,7 @@
|
||||
package collectors
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -30,6 +31,7 @@ import (
|
||||
// unit-testing the collectors.
|
||||
type Conn interface {
|
||||
MonCommand([]byte) ([]byte, string, error)
|
||||
MgrCommand([][]byte) ([]byte, string, error)
|
||||
GetPoolStats(string) (*rados.PoolStat, error)
|
||||
}
|
||||
|
||||
@ -118,6 +120,29 @@ func (c *RadosConn) MonCommand(args []byte) (buffer []byte, info string, err err
|
||||
return
|
||||
}
|
||||
|
||||
// MgrCommand executes a manager command to rados.
|
||||
func (c *RadosConn) MgrCommand(args [][]byte) (buffer []byte, info string, err error) {
|
||||
ll := c.logger.WithField("args", string(bytes.Join(args, []byte(","))))
|
||||
|
||||
ll.Trace("creating rados connection to execute mgr command")
|
||||
|
||||
conn, err := c.newRadosConn()
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
defer conn.Shutdown()
|
||||
|
||||
ll = ll.WithField("conn", conn.GetInstanceID())
|
||||
|
||||
ll.Trace("start executing mgr command")
|
||||
|
||||
buffer, info, err = conn.MgrCommand(args)
|
||||
|
||||
ll.WithError(err).Trace("complete executing mgr command")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetPoolStats returns a *rados.PoolStat for the given rados pool.
|
||||
func (c *RadosConn) GetPoolStats(pool string) (stat *rados.PoolStat, err error) {
|
||||
ll := c.logger.WithField("pool", pool)
|
||||
|
@ -543,12 +543,12 @@ func (c cephPGQuery) backfillTargets() map[int64]int64 {
|
||||
}
|
||||
|
||||
func (o *OSDCollector) collectOSDDF() error {
|
||||
cmd := o.cephOSDDFCommand()
|
||||
buf, _, err := o.conn.MonCommand(cmd)
|
||||
args := o.cephOSDDFCommand()
|
||||
buf, _, err := o.conn.MgrCommand(args)
|
||||
if err != nil {
|
||||
o.logger.WithError(err).WithField(
|
||||
"args", string(cmd),
|
||||
).Error("error executing mon command")
|
||||
"args", string(bytes.Join(args, []byte(","))),
|
||||
).Error("error executing mgr command")
|
||||
|
||||
return err
|
||||
}
|
||||
@ -662,11 +662,11 @@ func (o *OSDCollector) collectOSDDF() error {
|
||||
}
|
||||
|
||||
func (o *OSDCollector) collectOSDPerf() error {
|
||||
cmd := o.cephOSDPerfCommand()
|
||||
buf, _, err := o.conn.MonCommand(cmd)
|
||||
args := o.cephOSDPerfCommand()
|
||||
buf, _, err := o.conn.MgrCommand(args)
|
||||
if err != nil {
|
||||
o.logger.WithError(err).WithField(
|
||||
"args", string(cmd),
|
||||
"args", string(bytes.Join(args, []byte(","))),
|
||||
).Error("error executing mon command")
|
||||
|
||||
return err
|
||||
@ -896,12 +896,12 @@ func (o *OSDCollector) collectOSDDump() error {
|
||||
}
|
||||
|
||||
func (o *OSDCollector) performPGDumpBrief() error {
|
||||
cmd := o.cephPGDumpCommand()
|
||||
buf, _, err := o.conn.MonCommand(cmd)
|
||||
args := o.cephPGDumpCommand()
|
||||
buf, _, err := o.conn.MgrCommand(args)
|
||||
if err != nil {
|
||||
o.logger.WithError(err).WithField(
|
||||
"args", string(cmd),
|
||||
).Error("error executing mon command")
|
||||
"args", string(bytes.Join(args, []byte(","))),
|
||||
).Error("error executing mgr command")
|
||||
|
||||
return err
|
||||
}
|
||||
@ -964,7 +964,7 @@ func (o *OSDCollector) cephOSDDump() []byte {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *OSDCollector) cephOSDDFCommand() []byte {
|
||||
func (o *OSDCollector) cephOSDDFCommand() [][]byte {
|
||||
cmd, err := json.Marshal(map[string]interface{}{
|
||||
"prefix": "osd df",
|
||||
"format": jsonFormat,
|
||||
@ -972,10 +972,10 @@ func (o *OSDCollector) cephOSDDFCommand() []byte {
|
||||
if err != nil {
|
||||
o.logger.WithError(err).Panic("error marshalling ceph osd df")
|
||||
}
|
||||
return cmd
|
||||
return [][]byte{cmd}
|
||||
}
|
||||
|
||||
func (o *OSDCollector) cephOSDPerfCommand() []byte {
|
||||
func (o *OSDCollector) cephOSDPerfCommand() [][]byte {
|
||||
cmd, err := json.Marshal(map[string]interface{}{
|
||||
"prefix": "osd perf",
|
||||
"format": jsonFormat,
|
||||
@ -983,7 +983,7 @@ func (o *OSDCollector) cephOSDPerfCommand() []byte {
|
||||
if err != nil {
|
||||
o.logger.WithError(err).Panic("error marshalling ceph osd perf")
|
||||
}
|
||||
return cmd
|
||||
return [][]byte{cmd}
|
||||
}
|
||||
|
||||
func (o *OSDCollector) cephOSDTreeCommand(states ...string) []byte {
|
||||
@ -1002,7 +1002,7 @@ func (o *OSDCollector) cephOSDTreeCommand(states ...string) []byte {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *OSDCollector) cephPGDumpCommand() []byte {
|
||||
func (o *OSDCollector) cephPGDumpCommand() [][]byte {
|
||||
cmd, err := json.Marshal(map[string]interface{}{
|
||||
"prefix": "pg dump",
|
||||
"dumpcontents": []string{"pgs_brief"},
|
||||
@ -1011,7 +1011,7 @@ func (o *OSDCollector) cephPGDumpCommand() []byte {
|
||||
if err != nil {
|
||||
o.logger.WithError(err).Panic("error marshalling ceph pg dump")
|
||||
}
|
||||
return cmd
|
||||
return [][]byte{cmd}
|
||||
}
|
||||
|
||||
func (o *OSDCollector) cephPGQueryCommand(pgid string) []byte {
|
||||
|
@ -644,10 +644,14 @@ func TestOSDCollector(t *testing.T) {
|
||||
}`,
|
||||
}[tt.test]), "", nil)
|
||||
|
||||
conn.On("MonCommand", mock.MatchedBy(func(in interface{}) bool {
|
||||
conn.On("MgrCommand", mock.MatchedBy(func(in interface{}) bool {
|
||||
v := map[string]interface{}{}
|
||||
|
||||
err := json.Unmarshal(in.([]byte), &v)
|
||||
uv, ok := in.([][]byte)
|
||||
require.True(t, ok)
|
||||
require.Len(t, uv, 1)
|
||||
|
||||
err := json.Unmarshal(uv[0], &v)
|
||||
require.NoError(t, err)
|
||||
|
||||
return cmp.Equal(v, map[string]interface{}{
|
||||
@ -757,10 +761,14 @@ func TestOSDCollector(t *testing.T) {
|
||||
]
|
||||
}`), "", nil)
|
||||
|
||||
conn.On("MonCommand", mock.MatchedBy(func(in interface{}) bool {
|
||||
conn.On("MgrCommand", mock.MatchedBy(func(in interface{}) bool {
|
||||
v := map[string]interface{}{}
|
||||
|
||||
err := json.Unmarshal(in.([]byte), &v)
|
||||
uv, ok := in.([][]byte)
|
||||
require.True(t, ok)
|
||||
require.Len(t, uv, 1)
|
||||
|
||||
err := json.Unmarshal(uv[0], &v)
|
||||
require.NoError(t, err)
|
||||
|
||||
return cmp.Equal(v, map[string]interface{}{
|
||||
@ -858,10 +866,14 @@ func TestOSDCollector(t *testing.T) {
|
||||
}
|
||||
}`), "", nil)
|
||||
|
||||
conn.On("MonCommand", mock.MatchedBy(func(in interface{}) bool {
|
||||
conn.On("MgrCommand", mock.MatchedBy(func(in interface{}) bool {
|
||||
v := map[string]interface{}{}
|
||||
|
||||
err := json.Unmarshal(in.([]byte), &v)
|
||||
uv, ok := in.([][]byte)
|
||||
require.True(t, ok)
|
||||
require.Len(t, uv, 1)
|
||||
|
||||
err := json.Unmarshal(uv[0], &v)
|
||||
require.NoError(t, err)
|
||||
|
||||
return cmp.Equal(v, map[string]interface{}{
|
||||
|
@ -35,6 +35,36 @@ func (_m *Conn) GetPoolStats(_a0 string) (*rados.PoolStat, error) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MgrCommand provides a mock function with given fields: _a0
|
||||
func (_m *Conn) MgrCommand(_a0 [][]byte) ([]byte, string, error) {
|
||||
ret := _m.Called(_a0)
|
||||
|
||||
var r0 []byte
|
||||
if rf, ok := ret.Get(0).(func([][]byte) []byte); ok {
|
||||
r0 = rf(_a0)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]byte)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 string
|
||||
if rf, ok := ret.Get(1).(func([][]byte) string); ok {
|
||||
r1 = rf(_a0)
|
||||
} else {
|
||||
r1 = ret.Get(1).(string)
|
||||
}
|
||||
|
||||
var r2 error
|
||||
if rf, ok := ret.Get(2).(func([][]byte) error); ok {
|
||||
r2 = rf(_a0)
|
||||
} else {
|
||||
r2 = ret.Error(2)
|
||||
}
|
||||
|
||||
return r0, r1, r2
|
||||
}
|
||||
|
||||
// MonCommand provides a mock function with given fields: _a0
|
||||
func (_m *Conn) MonCommand(_a0 []byte) ([]byte, string, error) {
|
||||
ret := _m.Called(_a0)
|
||||
|
Loading…
Reference in New Issue
Block a user