Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions gluster-exporter/metric_daemon_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package main

import (
"errors"
"io/ioutil"
"net/http"
"strings"

"github.com/gluster/gluster-prometheus/pkg/glusterutils"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)

const (
// GDaemonLabel provides static label to info/error provided from this metrics
GDaemonLabel = "Gluster_Daemon_Status"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose served by this error message label? We are not using such labeling for other error messages. Do we really need this as all the gl-exporter logs go to a separate log file? @aravindavk suggestions?

)

func gdStatus(conf *glusterutils.Config) error {
if conf.GlusterMgmt == glusterutils.MgmtGlusterd {
if _, err := glusterutils.ExecuteCmd("ps --no-header -ww -o pid,comm -C glusterd"); err != nil {
return err
}
} else if conf.GlusterMgmt == glusterutils.MgmtGlusterd2 {
if conf.Glusterd2Endpoint == "" {
return errors.New("[" + GDaemonLabel + "] Empty GD2 Endpoint")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel better to use fmt.Sprintf() for formatting strings.

}
pingURL := strings.Join([]string{conf.Glusterd2Endpoint, "ping"}, "/")
// #nosec
resp, err := http.Get(pingURL)
if err != nil {
return errors.New("[" + GDaemonLabel + "]" + "Endpoint Get Error: " + err.Error())
}
_, err = ioutil.ReadAll(resp.Body)
if err != nil {
return errors.New("[" + GDaemonLabel + "]" + "Endpoint Read Error: " + err.Error())
}
}
return nil
}

var (
// metric labels
gdStatusLbl = []MetricLabel{
{
Name: "name",
Help: "Metric name, for which the status is collected",
},
{
Name: "gdType",
Help: "Type of gluster daemon / service running (GD1 or GD2)",
},
{
Name: "peerID",
Help: "Peer ID of the host for which this metric status is updated",
},
}
gExprtrLbl = []MetricLabel{
{
Name: "name",
Help: "Metric Name to be collected",
},
{
Name: "peerID",
Help: "Peer ID of the host, on which the data is collected",
},
}
glusterDaemonStatus = newPrometheusGaugeVec(Metric{
Namespace: "gluster",
Name: "daemon_status",
Help: "Status of gluster management daemon (1 = running and 0 = not-running)",
LongHelp: "",
Labels: gdStatusLbl,
})
glusterExporterStatus = newPrometheusGaugeVec(Metric{
Namespace: "gluster",
Name: "exporter_status",
Help: "Status of gluster exporter (will be set 1 always)",
LongHelp: "",
Labels: gExprtrLbl,
})
)

// gDaemonStatus registering function,
// provides the status of services running on the machine
func gDaemonStatus() error {
var conf *glusterutils.Config
if gluster == nil {
return errors.New("[" + GDaemonLabel + "] Unable to get a 'GInterface' object")
}
peerID, err := gluster.LocalPeerID()
if err != nil {
return errors.New("[" + GDaemonLabel + "] Getting Peer ID failed: " + err.Error())
}
conf, err = glusterutils.GDConfigFromInterface(gluster)
if err != nil {
return errors.New("[" + GDaemonLabel + "] Error: " + err.Error())
}
log.Println("GD Management: ", conf.GlusterMgmt)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. I feel this was added for debugging purpose.

genrlLbls := prometheus.Labels{
"name": "Glusterd_Status",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we follow all small case separated by underscore so use the same way for uniformity.

"gdType": conf.GlusterMgmt,
"peerID": peerID,
}
err = gdStatus(conf)
if err != nil {
log.WithError(err).WithFields(log.Fields{
"peer": peerID,
"name": "Glusterd_Status",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

}).Errorln("["+GDaemonLabel+"] Error:", err)
glusterDaemonStatus.With(genrlLbls).Set(float64(0))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare constants for states 0 and 1.

} else {
glusterDaemonStatus.With(genrlLbls).Set(float64(1))
}
genrlLbls = prometheus.Labels{
"name": "Gluster_Exporter_Status",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all small cases separated by underscores?

"peerID": peerID,
}
glusterExporterStatus.With(genrlLbls).Set(float64(1))
return nil
}

func init() {
registerMetric("gluster_daemon_status", gDaemonStatus)
}
22 changes: 22 additions & 0 deletions pkg/glusterutils/exporterd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ var (
peerIDPattern = regexp.MustCompile("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")
)

// GDConfigFromInterface checks the given interface is compatible with 'GDConfigInterface'
// and returns a pointer to glusterutils.Config
func GDConfigFromInterface(iFace interface{}) (*Config, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the purpose of this change and ideally this should go as part of another infra level PR and not as part of some feature PR.

if gdConf, ok := iFace.(GDConfigInterface); ok {
return gdConf.Config(), nil
}
return nil, errors.New("Incompatible interface type, " +
"cannot be converted to 'GDConfigInterface'")
}

// Config returns the configuration associated with it
// and makes it compatible with 'GDConfigInterface'
func (g *GD1) Config() *Config {
return g.config
}

// IsLeader returns true or false based on whether the node is the leader of the cluster or not
func (g *GD1) IsLeader() (bool, error) {
setDefaultConfig(g.config)
Expand Down Expand Up @@ -42,6 +58,12 @@ func (g *GD1) IsLeader() (bool, error) {
return false, nil
}

// Config returns the configuration associated with it
// and makes it compatible with 'GDConfigInterface'
func (g *GD2) Config() *Config {
return g.config
}

// IsLeader returns true or false based on whether the node is the leader of the cluster or not
func (g *GD2) IsLeader() (bool, error) {
peerList, err := g.Peers()
Expand Down
5 changes: 5 additions & 0 deletions pkg/glusterutils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ type GInterface interface {
EnableVolumeProfiling(volinfo Volume) error
}

// GDConfigInterface returns the configuration of the GD
type GDConfigInterface interface {
Config() *Config
}

// FopStat defines file ops related details
type FopStat struct {
Name string
Expand Down