-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from bcgov/release/add-available-form-statistics
Added Form Statistics to Prometheus monitoring
- Loading branch information
Showing
5 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import requests | ||
|
||
class dfmetrics: | ||
def __init__(self, logging): | ||
self.logging = logging | ||
self.form_inventory_api_url = os.getenv('DF_FORM_INVENTORY_API_URL', 'http://localhost:5000/api/v1/forms/statistics') | ||
|
||
def genFormInventoryMetrics(self): | ||
self.logging.info("Generating metrics for form inventory") | ||
try: | ||
response = requests.get(self.form_inventory_api_url) | ||
data = response.json() | ||
return data | ||
except Exception as e: | ||
self.logging.error("Error in generating metrics for form inventory") | ||
self.logging.info(e) | ||
return [] | ||
|
||
def genAvailableFormsMetric(self, form_type): | ||
inventory = self.genFormInventoryMetrics() | ||
for item in inventory: | ||
if item['form_type'] == form_type: | ||
return item['available_forms'] | ||
return 0 | ||
|
||
def genLeasedFormsMetric(self, form_type): | ||
inventory = self.genFormInventoryMetrics() | ||
for item in inventory: | ||
if item['form_type'] == form_type: | ||
return item['leased_forms'] | ||
return 0 | ||
|
||
def genTotalFormsMetric(self, form_type): | ||
inventory = self.genFormInventoryMetrics() | ||
for item in inventory: | ||
if item['form_type'] == form_type: | ||
return item['total_forms'] | ||
return 0 | ||
|
||
def genTotalUsedFormsMetric(self, form_type): | ||
inventory = self.genFormInventoryMetrics() | ||
for item in inventory: | ||
if item['form_type'] == form_type: | ||
return item['total_used_forms'] | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters