Skip to content

Commit

Permalink
Addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
voetberg committed Aug 2, 2024
1 parent 3a5bcf9 commit 7f69b96
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions common/check_expired_locked_rules
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ if __name__ == "__main__":
status = OK
session = session.get_session()

# Select statement used for both metrics
base_statement = select(
models.ReplicationRule,
models.DataIdentifier.name,
models.DataIdentifier.scope,
models.ReplicationRule.rse_expression,
)
# Use prometheus pusher to send results to a remote service
with PrometheusPusher() as manager:
try:
statement = base_statement.where(
Expand All @@ -48,17 +50,21 @@ if __name__ == "__main__":
models.ReplicationRule.expires_at < datetime.now(tz=timezone.utc),
)
)
query = session.execute(statement).scalars()
query = session.execute(statement).all()
rule_counts = defaultdict(int)

# Print rules for nagios monitoring
print("Locked expired rules")
for rule_id, scope, name, rse_expression in query:
print(rule_id, scope, name, rse_expression)
status = CRITICAL
rule_counts[rse_expression] += 1

# Add an empty entry where there is no result so the metric has continuity
if len(rule_counts.keys()) == 0:
rule_counts["All"] = 0

# Send to Prometheus pusher
for rse_expression, count in rule_counts.items():
(
manager.gauge(
Expand Down Expand Up @@ -88,7 +94,7 @@ if __name__ == "__main__":
)
)

query = session.execute(statement).scalars()
query = session.execute(statement).all()
datasets_count = defaultdict(int)

print("Datasets expired with locked rules")
Expand Down

0 comments on commit 7f69b96

Please sign in to comment.