Skip to content
Open
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
16 changes: 14 additions & 2 deletions internal/openmetrics-exporter/usage_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ func (c *UsageCollector) Collect(ch chan<- prometheus.Metric) {
if len(uusers.Items) > 0 {
for _, usage := range uusers.Items {
uid = strconv.Itoa(usage.User.Id)
// Set quotaValue to the quota
quotaValue := usage.Quota
// if the quota is 0 though, set it to the default quota for users on the filesystem
if usage.Quota == 0 {
quotaValue = usage.FileSystemDefaultQuota
}
ch <- prometheus.MustNewConstMetric(
c.UsageUsersDesc,
prometheus.GaugeValue,
usage.Quota,
quotaValue,
usage.FileSystem.Name, usage.User.Name, uid, "quota",
)
ch <- prometheus.MustNewConstMetric(
Expand All @@ -44,10 +50,16 @@ func (c *UsageCollector) Collect(ch chan<- prometheus.Metric) {
if len(ugroups.Items) > 0 {
for _, usage := range ugroups.Items {
gid = strconv.Itoa(usage.Group.Id)
// Set quotaValue to the quota
Copy link
Collaborator

Choose a reason for hiding this comment

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

As described here, I could not get your requested logic to work since the var gets lost in the if statement.

Something this could work

			// If User Usage Quota is null use the File System Default Quota
			if usage.Quota == nil {
				ch <- prometheus.MustNewConstMetric(
					c.UsageUsersDesc,
					prometheus.GaugeValue,
					usage.FileSystemDefaultQuota,
					usage.FileSystem.Name, usage.User.Name, uid, "quota",
				)
			} else {
				ch <- prometheus.MustNewConstMetric(
					c.UsageUsersDesc,
					prometheus.GaugeValue,
					*usage.Quota,
					usage.FileSystem.Name, usage.User.Name, uid, "quota",
				)
			}

Copy link
Collaborator

Choose a reason for hiding this comment

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

also the User/Group User Quota data type needs to be set from float64 to *float64 to deal with null/nil values

quotaValue := usage.Quota
// if the quota is 0 though, set it to the default quota for users on the filesystem
if usage.Quota == 0 {
quotaValue = usage.FileSystemDefaultQuota
}
ch <- prometheus.MustNewConstMetric(
c.UsageGroupsDesc,
prometheus.GaugeValue,
usage.Quota,
quotaValue,
usage.FileSystem.Name, usage.Group.Name, gid, "quota",
)
ch <- prometheus.MustNewConstMetric(
Expand Down