Skip to content

Commit

Permalink
add quotas exporter and minor refactoring of package module (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Aug 20, 2024
1 parent f0ba9b7 commit fc0414a
Show file tree
Hide file tree
Showing 17 changed files with 264 additions and 36 deletions.
15 changes: 11 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ stages:

el-7:
image: gitlab-registry.cern.ch/linuxsupport/cc7-base
variables:
PKG_MGR: yum
extends: .build_eos-exporter-template

stage: build:rpm
script:
- yum-config-manager --save --setopt=epel.baseurl=https://linuxsoft.cern.ch/internal/archive/epel/7/x86_64/
- yum install -y sudo sssd-client createrepo tree
- tree
- yum install -y golang rpm-devel rpm-build make rpmdevtools sudo createrepo git
- make rpm
- mkdir -p ${CI_JOB_NAME}_artifacts
- cp --recursive rpmbuild/SRPMS/ ${CI_JOB_NAME}_artifacts
- cp --recursive rpmbuild/RPMS/ ${CI_JOB_NAME}_artifacts
el-8:
image: gitlab-registry.cern.ch/linuxsupport/alma8-base
variables:
Expand All @@ -37,6 +43,7 @@ rpm_artifacts:
stage: publish
image: gitlab-registry.cern.ch/linuxsupport/cc7-base
script:
- yum-config-manager --save --setopt=epel.baseurl=https://linuxsoft.cern.ch/internal/archive/epel/7/x86_64/
- yum install -y sudo sssd-client createrepo tree
- tree
- sudo -u stci -H ./gitlab-ci/publish_rpms.sh
Expand Down
2 changes: 1 addition & 1 deletion collector/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
)

type FSCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion collector/fsck.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
)

type FsckCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion collector/fusex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
)

// sample line
Expand Down
2 changes: 1 addition & 1 deletion collector/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
)

type GroupCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion collector/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
)

type InspectorLayoutCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion collector/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
)

type IOInfoCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion collector/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion collector/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"

//"os"
//"bufio"
Expand Down
164 changes: 164 additions & 0 deletions collector/quotas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package collector

import (
"context"
"fmt"

// "time"
"log"

"github.com/cern-eos/eos_exporter/eosclient"
"github.com/prometheus/client_golang/prometheus"
)

type QuotasCollector struct {
*CollectorOpts
QuotaUsedBytes *prometheus.GaugeVec
QuotaMaxBytes *prometheus.GaugeVec
QuotaUsedLogicalBytes *prometheus.GaugeVec
QuotaMaxLogicalBytes *prometheus.GaugeVec
QuotaUsedFiles *prometheus.GaugeVec
QuotaMaxFiles *prometheus.GaugeVec
}

// NewQuotasCollector creates an cluster of the QuotasCollector
func NewQuotasCollector(opts *CollectorOpts) *QuotasCollector {
cluster := opts.Cluster
labels := make(prometheus.Labels)
labels["cluster"] = cluster

namespace := "eos"

return &QuotasCollector{
//file: f,
CollectorOpts: opts,
QuotaUsedBytes: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "quota_used_bytes",
Help: "Quota used bytes",
ConstLabels: labels,
},
[]string{"uid", "gid", "space"},
),
QuotaMaxBytes: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "quota_max_bytes",
Help: "Quota max bytes",
ConstLabels: labels,
},
[]string{"uid", "gid", "space"},
),
QuotaUsedLogicalBytes: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "quota_used_logical_bytes",
Help: "Quota used logical bytes",
ConstLabels: labels,
},
[]string{"uid", "gid", "space"},
),
QuotaMaxLogicalBytes: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "quota_max_logical_bytes",
Help: "Quota maxlogical bytes",
ConstLabels: labels,
},
[]string{"uid", "gid", "space"},
),
QuotaUsedFiles: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "quota_used_files",
Help: "Quota used files",
ConstLabels: labels,
},
[]string{"uid", "gid", "space"},
),
QuotaMaxFiles: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "quota_max_files",
Help: "Quota max files",
ConstLabels: labels,
},
[]string{"uid", "gid", "space"},
),
}
}

func (o *QuotasCollector) collectorList() []prometheus.Collector {
return []prometheus.Collector{
o.QuotaUsedBytes,
o.QuotaMaxBytes,
o.QuotaUsedFiles,
o.QuotaMaxFiles,
o.QuotaUsedLogicalBytes,
o.QuotaMaxLogicalBytes,
}
}

func (o *QuotasCollector) collectQuotaDF() error {
ins := getEOSInstance()
url := "root://" + ins
opt := &eosclient.Options{URL: url, Timeout: o.Timeout}
client, err := eosclient.New(opt)
if err != nil {
panic(err)
}

quotas, err := client.Quotas(context.Background(), "root")
if err != nil {
return err
}

// a GaugeVector keeps its state for any combination of labels until the process is restarted.
// For metrics obtained from systems like EOS that do not produce a complete set of metrics (only the active metrics)
// then we risk to expose these metrics forever until the next process restart.
// To workaround this, we reset the gauge vectors when collecting metrics.

// output is like this:
// quota=node uid=9218 space=/eos/user/ usedbytes=158090138 usedlogicalbytes=79045069 usedfiles=1546 maxbytes=0 maxlogicalbytes=0 maxfiles=0 percentageusedbytes=100.00 statusbytes=ignored statusfiles=ignored

o.QuotaUsedBytes.Reset()
o.QuotaMaxBytes.Reset()
o.QuotaUsedLogicalBytes.Reset()
o.QuotaMaxLogicalBytes.Reset()
o.QuotaUsedFiles.Reset()
o.QuotaMaxFiles.Reset()

for _, q := range quotas {
o.QuotaUsedBytes.WithLabelValues(q.Uid, q.Gid, q.Space).Set(float64(q.UsedBytes))
o.QuotaMaxBytes.WithLabelValues(q.Uid, q.Gid, q.Space).Set(float64(q.MaxBytes))
o.QuotaUsedLogicalBytes.WithLabelValues(q.Uid, q.Gid, q.Space).Set(float64(q.UsedLogicalBytes))
o.QuotaMaxLogicalBytes.WithLabelValues(q.Uid, q.Gid, q.Space).Set(float64(q.MaxLogicalBytes))
o.QuotaUsedFiles.WithLabelValues(q.Uid, q.Gid, q.Space).Set(float64(q.UsedFiles))
o.QuotaMaxFiles.WithLabelValues(q.Uid, q.Gid, q.Space).Set(float64(q.MaxFiles))
}

return nil

} // collectQuotaDF()

// Describe sends the descriptors of each SpaceCollector related metrics we have defined
func (o *QuotasCollector) Describe(ch chan<- *prometheus.Desc) {
for _, metric := range o.collectorList() {
fmt.Print(metric)
metric.Describe(ch)
}
}

// Collect sends all the collected metrics to the provided prometheus channel.
func (o *QuotasCollector) Collect(ch chan<- prometheus.Metric) {

if err := o.collectQuotaDF(); err != nil {
log.Println("failed collecting quota metrics:", err)
return
}

for _, collector := range o.collectorList() {
collector.Collect(ch)
}
}
2 changes: 1 addition & 1 deletion collector/recycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
//"os"
//"bufio"
//"strings"
Expand Down
2 changes: 1 addition & 1 deletion collector/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
)

/*
Expand Down
2 changes: 1 addition & 1 deletion collector/who.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

"github.com/prometheus/client_golang/prometheus"
"gitlab.cern.ch/rvalverd/eos_exporter/eosclient"
"github.com/cern-eos/eos_exporter/eosclient"
)

// eos who -a -m provides 3 clusters of information
Expand Down
3 changes: 2 additions & 1 deletion eos_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// "github.com/prometheus/common/log"
/* // For enabling profile mode in Go
"github.com/pkg/profile"*/
"gitlab.cern.ch/rvalverd/eos_exporter/collector"
"github.com/cern-eos/eos_exporter/collector"

_ "embed"
)
Expand Down Expand Up @@ -72,6 +72,7 @@ func NewEOSExporter(opts *collector.CollectorOpts) *EOSExporter {
collector.NewNSBatchCollector(opts), // eos namespace potential batch overload information
collector.NewRecycleCollector(opts), // eos recycle bin information
collector.NewWhoCollector(opts), // eos who information
collector.NewQuotasCollector(opts), // eos quota information
collector.NewFsckCollector(opts), // eos fsck information
collector.NewFusexCollector(opts), // eos fusex information
collector.NewInspectorLayoutCollector(opts), // eos inspector layout information
Expand Down
4 changes: 3 additions & 1 deletion eos_exporter.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# eos_exporter spec file
#
%define version 0.1.8
%define version 0.1.9

Name: eos_exporter
Summary: The Prometheus EOS exporter exposes EOS metrics.
Expand Down Expand Up @@ -58,6 +58,8 @@ rm -rf %buildroot/
%systemd_preun %{name}.service

%changelog
* Mon Aug 19 2024 Gianmaria Del Monte <[email protected]> 0.1.9-1
- Add quotas exporter
* Mon Jun 3 2024 Cedric Caffy <[email protected]> 0.1.8-1
- Adds new eos inspector metrics as access time volume and files, birthtime and cost per group.
- Adds qclient metrics
Expand Down
Loading

0 comments on commit fc0414a

Please sign in to comment.