flexlm_exporter icon indicating copy to clipboard operation
flexlm_exporter copied to clipboard

Feature Request: simple/sum user licence usage per feature

Open D4R4 opened this issue 4 years ago • 3 comments

As you can see below, flexlm_feature_used_users is differentiating users based on the server, display, and tool they are using for one specific feature: image I was wondering if there is the possibility to maybe create a flexlm_feature_used_users_simple view that can trim the extra stuff and sum each user's usage for a total amount. For example, user1 in the above example would be 4+2+2 and list as 8 tokens, Or can I already do that in Prometheus? I am sorry if it's a beginner question.

D4R4 avatar Apr 06 '20 11:04 D4R4

Hi @D4R4, I am actually wondering why the user string has so much information. I would expect a simple username there. Can you share some information on that?

Besides of that, you have to ways of "grouping" or sum up the usage over a label, in this case user.

  1. On the Prometheus server side, see recording_rules. You will have the information on the TSDB, and could also discard the original metrics.
  2. On the Grafana side, putting a similar Prometheus query on your dashboard, not touching the prometheus TSDB.

Both have pros and cons as always, depending on what you prefer.

mjtrangoni avatar Apr 10 '20 13:04 mjtrangoni

I added a function like this:

lmstatFeatureUsedUsersSimple: prometheus.NewDesc(
			prometheus.BuildFQName(namespace, "feature", "used_users_simple"),
			"License feature used by user labeled by app, feature name and "+
				"username of the license.", []string{"app", "name", "user"}, nil,),
if licenses.MonitorUsers && (licUsersByFeature[name] != nil) {
			var licUsers = licUsersByFeature[name]

			var licUsersTrimmed = map[string]float64{}

			for username, licused := range licUsers {
				var re = regexp.MustCompile(`^([^\s]*)\s.*$`)

				usernameSimple := re.ReplaceAllString(username, `$1`)
				if licUsersTrimmed[usernameSimple] != 0 {
					licUsersTrimmed[usernameSimple] += licused
				} else {
					licUsersTrimmed[usernameSimple] = licused
				}
			}

			for usernameSimple, licused := range licUsersTrimmed {
				ch <- prometheus.MustNewConstMetric(
					c.lmstatFeatureUsedUsersSimple, prometheus.GaugeValue,
					licused, licenses.Name, name, usernameSimple)
			}
		}

To get the job done

D4R4 avatar Apr 15 '20 17:04 D4R4

Hi @D4R4, I am also interested in summing and reporting tokens per user. Where did you add this function and "if" statement?

sorinel999 avatar May 25 '22 01:05 sorinel999