Add user to exporter for use with rbd/rgw commands
This commit is contained in:
parent
19a3cd5c7e
commit
957b06df91
|
@ -34,6 +34,7 @@ type Exporter struct {
|
|||
Conn Conn
|
||||
Cluster string
|
||||
Config string
|
||||
User string
|
||||
RgwMode int
|
||||
RbdMirror bool
|
||||
Logger *logrus.Logger
|
||||
|
@ -42,11 +43,12 @@ type Exporter struct {
|
|||
|
||||
// NewExporter returns an initialized *Exporter
|
||||
// We can choose to enable a collector to extract stats out of by adding it to the list of collectors.
|
||||
func NewExporter(conn Conn, cluster string, config string, rgwMode int, logger *logrus.Logger) *Exporter {
|
||||
func NewExporter(conn Conn, cluster string, config string, user string, rgwMode int, logger *logrus.Logger) *Exporter {
|
||||
return &Exporter{
|
||||
Conn: conn,
|
||||
Cluster: cluster,
|
||||
Config: config,
|
||||
User: user,
|
||||
RgwMode: rgwMode,
|
||||
Logger: logger,
|
||||
}
|
||||
|
|
|
@ -49,10 +49,11 @@ type rbdMirrorPoolStatus struct {
|
|||
// RbdMirrorStatusCollector displays statistics about each pool in the Ceph cluster.
|
||||
type RbdMirrorStatusCollector struct {
|
||||
config string
|
||||
user string
|
||||
logger *logrus.Logger
|
||||
version *Version
|
||||
|
||||
getRbdMirrorStatus func(config string) ([]byte, error)
|
||||
getRbdMirrorStatus func(config string, user string) ([]byte, error)
|
||||
|
||||
// RbdMirrorStatus shows the overall health status of a rbd-mirror.
|
||||
RbdMirrorStatus prometheus.Gauge
|
||||
|
@ -65,8 +66,8 @@ type RbdMirrorStatusCollector struct {
|
|||
}
|
||||
|
||||
// rbdMirrorStatus get the RBD Mirror Pool Status
|
||||
var rbdMirrorStatus = func(config string) ([]byte, error) {
|
||||
out, err := exec.Command(rbdPath, "-c", config, "mirror", "pool", "status", "--format", "json").Output()
|
||||
var rbdMirrorStatus = func(config string, user string) ([]byte, error) {
|
||||
out, err := exec.Command(rbdPath, "-c", config, "--user", user, "mirror", "pool", "status", "--format", "json").Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -80,6 +81,7 @@ func NewRbdMirrorStatusCollector(exporter *Exporter) *RbdMirrorStatusCollector {
|
|||
|
||||
collector := &RbdMirrorStatusCollector{
|
||||
config: exporter.Config,
|
||||
user: exporter.User,
|
||||
logger: exporter.Logger,
|
||||
version: exporter.Version,
|
||||
|
||||
|
@ -154,7 +156,7 @@ func (c *RbdMirrorStatusCollector) Describe(ch chan<- *prometheus.Desc) {
|
|||
|
||||
// Collect sends all the collected metrics Prometheus.
|
||||
func (c *RbdMirrorStatusCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
status, err := rbdMirrorStatus(c.config)
|
||||
status, err := rbdMirrorStatus(c.config, c.user)
|
||||
if err != nil {
|
||||
c.logger.WithError(err).Error("failed to run 'rbd mirror pool status'")
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
)
|
||||
|
||||
func setStatus(b []byte) {
|
||||
rbdMirrorStatus = func(string) ([]byte, error) {
|
||||
rbdMirrorStatus = func(string, string) ([]byte, error) {
|
||||
return b, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,13 +57,13 @@ func (gc rgwTaskGC) ExpiresAt() time.Time {
|
|||
}
|
||||
|
||||
// rgwGetGCTaskList get the RGW Garbage Collection task list
|
||||
func rgwGetGCTaskList(config string) ([]byte, error) {
|
||||
func rgwGetGCTaskList(config string, user string) ([]byte, error) {
|
||||
var (
|
||||
out []byte
|
||||
err error
|
||||
)
|
||||
|
||||
if out, err = exec.Command(radosgwAdminPath, "-c", config, "gc", "list", "--include-all").Output(); err != nil {
|
||||
if out, err = exec.Command(radosgwAdminPath, "-c", config, "--user", user, "gc", "list", "--include-all").Output(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,7 @@ func rgwGetGCTaskList(config string) ([]byte, error) {
|
|||
// RGWCollector collects metrics from the RGW service
|
||||
type RGWCollector struct {
|
||||
config string
|
||||
user string
|
||||
background bool
|
||||
logger *logrus.Logger
|
||||
version *Version
|
||||
|
@ -87,7 +88,7 @@ type RGWCollector struct {
|
|||
// PendingObjects reports the total number of RGW GC objects contained in pending tasks
|
||||
PendingObjects *prometheus.GaugeVec
|
||||
|
||||
getRGWGCTaskList func(string) ([]byte, error)
|
||||
getRGWGCTaskList func(string, string) ([]byte, error)
|
||||
}
|
||||
|
||||
// NewRGWCollector creates an instance of the RGWCollector and instantiates
|
||||
|
@ -171,7 +172,7 @@ func (r *RGWCollector) backgroundCollect() error {
|
|||
}
|
||||
|
||||
func (r *RGWCollector) collect() error {
|
||||
data, err := r.getRGWGCTaskList(r.config)
|
||||
data, err := r.getRGWGCTaskList(r.config, r.user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ func TestRGWCollector(t *testing.T) {
|
|||
} {
|
||||
func() {
|
||||
collector := NewRGWCollector(&Exporter{Cluster: "ceph", Logger: logrus.New()}, false) // run in foreground for testing
|
||||
collector.getRGWGCTaskList = func(cluster string) ([]byte, error) {
|
||||
collector.getRGWGCTaskList = func(cluster string, user string) ([]byte, error) {
|
||||
if tt.input != nil {
|
||||
return tt.input, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue