From cd1b1c1f6a155225f74d3a970d0ee68308beb192 Mon Sep 17 00:00:00 2001 From: Phillip Date: Tue, 26 Nov 2024 12:01:33 +0100 Subject: [PATCH] BC-8401 new groups metrics (#1020) --- .../templates/values.yml.j2 | 222 ++++++++++++++++++ 1 file changed, 222 insertions(+) diff --git a/ansible/roles/mongodb_query_exporter/templates/values.yml.j2 b/ansible/roles/mongodb_query_exporter/templates/values.yml.j2 index 74180432e..3da03166b 100644 --- a/ansible/roles/mongodb_query_exporter/templates/values.yml.j2 +++ b/ansible/roles/mongodb_query_exporter/templates/values.yml.j2 @@ -1095,3 +1095,225 @@ aggregations: } } ] + + + - database: {{ mongodb_query_exporter_mongodb_sc_db_name }} + collection: groups + metrics: + - name: sc_groups_count_by_type + type: gauge + help: 'Groups count by type' + value: groupCount + overrideEmpty: true + emptyValue: 0 + labels: + - type + constLabels: + longterm: 'true' + mode: pull + pipeline: | + [ + { + "$group": { + "_id": "$type", + "groupCount": { "$sum": 1 } + } + }, + { + "$project": { + "type": "$_id", + "groupCount": 1 + } + } + ] + + + - database: {{ mongodb_query_exporter_mongodb_sc_db_name }} + collection: groups + metrics: + - name: sc_groups_size_distribution_by_type + type: gauge + help: 'Distribution of user counts in groups by size and group type' + value: count + overrideEmpty: true + emptyValue: 0 + labels: + - type + - group_size + constLabels: + longterm: 'true' + mode: pull + pipeline: | + [ + { + "$project": { + "type": 1, + "group_size": { "$size": "$users" } + } + }, + { + "$project": { + "type": 1, + "group_size": { + "$switch": { + "branches": [ + { "case": { "$eq": ["$group_size", 1] }, "then": "0" }, + { "case": { "$eq": ["$group_size", 1] }, "then": "1" }, + { "case": { "$and": [{ "$gt": ["$group_size", 1] }, { "$lte": ["$group_size", 50] }] }, "then": "2-50" }, + { "case": { "$and": [{ "$gt": ["$group_size", 50] }, { "$lte": ["$group_size", 100] }] }, "then": "51-100" }, + { "case": { "$and": [{ "$gt": ["$group_size", 100] }, { "$lte": ["$group_size", 150] }] }, "then": "101-150" }, + { "case": { "$and": [{ "$gt": ["$group_size", 150] }, { "$lte": ["$group_size", 200] }] }, "then": "151-200" } + ], + "default": "200plus" + } + } + } + }, + { + "$group": { + "_id": { "type": "$type", "group_size": "$group_size" }, + "count": { "$sum": 1 } + } + }, + { + "$project": { + "_id": 0, + "type": "$_id.type", + "group_size": "$_id.group_size", + "count": { "$toDouble": "$count" } + } + }, + { + "$sort": { "type": 1, "group_size": 1 } + } + ] + + + - database: {{ mongodb_query_exporter_mongodb_sc_db_name }} + collection: groups + metrics: + - name: sc_groups_users_size_distribution + type: gauge + help: 'Distribution of user counts in groups by size and group type' + value: user_count + overrideEmpty: true + emptyValue: 0 + labels: + - type + - bucket + constLabels: + longterm: 'true' + mode: pull + pipeline: | + [ + { "$unwind": "$users" }, + { + "$group": { + "_id": { "user": "$users", "type": "$type" }, + "group_count": { "$sum": 1 } + } + }, + { + "$project": { + "type": "$_id.type", + "bucket": { + "$switch": { + "branches": [ + { "case": { "$eq": ["$group_count", 0] }, "then": "0" }, + { "case": { "$eq": ["$group_count", 1] }, "then": "1" }, + { "case": { "$and": [{ "$gte": ["$group_count", 2] }, { "$lte": ["$group_count", 50] }] }, "then": "2-50" }, + { "case": { "$and": [{ "$gte": ["$group_count", 51] }, { "$lte": ["$group_count", 100] }] }, "then": "51-100" }, + { "case": { "$and": [{ "$gte": ["$group_count", 101] }, { "$lte": ["$group_count", 150] }] }, "then": "101-150" }, + { "case": { "$and": [{ "$gte": ["$group_count", 151] }, { "$lte": ["$group_count", 200] }] }, "then": "151-200" }, + { "case": { "$gt": ["$group_count", 200] }, "then": "200plus" } + ], + "default": "other" + } + } + } + }, + { + "$group": { + "_id": { "type": "$type", "bucket": "$bucket" }, + "user_count": { "$sum": 1 } + } + }, + { + "$project": { + "type": "$_id.type", + "bucket": "$_id.bucket", + "user_count": "$user_count", + "_id": 0 + } + }, + { "$sort": { "type": 1, "bucket": 1 } } + ] + + + - database: {{ mongodb_query_exporter_mongodb_sc_db_name }} + collection: groups + metrics: + - name: sc_groups_organization_group_count_distribution + type: gauge + help: 'Distribution of groups per organization' + value: count + overrideEmpty: true + emptyValue: 0 + labels: + - type + - group_count_bucket + constLabels: + longterm: 'true' + mode: pull + pipeline: | + [ + { + "$group": { + "_id": { "organization": "$organization", "type": "$type" }, + "group_count": { "$sum": 1 } + } + }, + { + "$project": { + "organization": "$_id.organization", + "type": "$_id.type", + "group_count": 1, + "_id": 0 + } + }, + { + "$project": { + "organization": 1, + "type": 1, + "group_count_bucket": { + "$switch": { + "branches": [ + { "case": { "$eq": ["$group_count", 1] }, "then": "1" }, + { "case": { "$and": [{ "$gt": ["$group_count", 1] }, { "$lte": ["$group_count", 50] }] }, "then": "2-50" }, + { "case": { "$and": [{ "$gt": ["$group_count", 50] }, { "$lte": ["$group_count", 100] }] }, "then": "51-100" }, + { "case": { "$and": [{ "$gt": ["$group_count", 100] }, { "$lte": ["$group_count", 150] }] }, "then": "101-150" }, + { "case": { "$and": [{ "$gt": ["$group_count", 150] }, { "$lte": ["$group_count", 200] }] }, "then": "151-200" } + ], + "default": "200+" + } + } + } + }, + { + "$group": { + "_id": { "group_count_bucket": "$group_count_bucket", "type": "$type" }, + "count": { "$sum": 1 } + } + }, + { + "$project": { + "_id": 0, + "group_count_bucket": "$_id.group_count_bucket", + "type": "$_id.type", + "count": { "$toDouble": "$count" } + } + }, + { + "$sort": { "type": 1, "group_count_bucket": 1 } + } + ] \ No newline at end of file