-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,307 additions
and
9 deletions.
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
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,95 @@ | ||
# (c) 2012-2018, Ansible by Red Hat | ||
# | ||
# This file is part of Ansible Galaxy | ||
# | ||
# Ansible Galaxy is free software: you can redistribute it and/or modify | ||
# it under the terms of the Apache License as published by | ||
# the Apache Software Foundation, either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Ansible Galaxy is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# Apache License for more details. | ||
# | ||
# You should have received a copy of the Apache License | ||
# along with Galaxy. If not, see <http://www.apache.org/licenses/>. | ||
|
||
import logging | ||
import sys | ||
|
||
from django.conf import settings | ||
|
||
from rest_framework.request import Request | ||
|
||
|
||
__all__ = [ | ||
'send', | ||
] | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def send(func_name): | ||
def decorator(function): | ||
def wrapper(*args, **kwargs): | ||
# call the view | ||
result = function(*args, **kwargs) | ||
|
||
if settings.METRICS_ENABLED: | ||
# TODO do this async | ||
_send(func_name, args[1]) | ||
|
||
return result | ||
return wrapper | ||
return decorator | ||
|
||
|
||
def _send(func_name, request): | ||
if not isinstance(request, Request): | ||
raise AssertionError( | ||
'Could not send metrics. ' | ||
'Expected rest_framework.request.Request, got %s!' | ||
% type(request) | ||
) | ||
|
||
func = getattr(sys.modules[__name__], func_name, None) | ||
if not callable(func): | ||
raise AssertionError( | ||
'Could not send metrics. % is not callable!' % func_name | ||
) | ||
|
||
try: | ||
# FIXME POST? | ||
func(request.GET) | ||
except IOError as e: | ||
logger.exception(e) | ||
|
||
|
||
def search(data): | ||
platforms = data.get('platforms', '').split() | ||
cloud_platforms = data.get('cloud_platforms', '').split() | ||
tags = data.get('tags', '').split() | ||
keywords = data.get('keywords', '').split() | ||
|
||
if not any((platforms, cloud_platforms, tags, keywords)): | ||
return | ||
|
||
search_criteria = { | ||
'keyword': keywords, | ||
'platform': platforms, | ||
'cloud_platform': cloud_platforms, | ||
'tag': tags, | ||
} | ||
|
||
settings.PROM_CNTR_SEARCH.labels( | ||
keywords=','.join(keywords), | ||
platforms=','.join(platforms), | ||
cloud_platforms=','.join(cloud_platforms), | ||
tags=','.join(tags) | ||
).inc() | ||
|
||
for criteria_type, criteria_values in search_criteria.items(): | ||
for criteria_value in criteria_values: | ||
settings.PROM_CNTR_SEARCH_CRITERIA.labels( | ||
ctype=criteria_type, cvalue=criteria_value).inc() |
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
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,11 @@ | ||
scrape_configs: | ||
- job_name: 'galaxy' | ||
scrape_interval: '60s' | ||
honor_labels: true | ||
metrics_path: '/api/metrics' | ||
static_configs: | ||
- targets: | ||
- 'galaxy.svc:8000' | ||
|
||
remote_write: | ||
- url: "http://influxdb:8086/api/v1/prom/write?u=galaxy&p=galaxy&db=galaxy" |
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,44 @@ | ||
from influxdb import InfluxDBClient | ||
|
||
|
||
INFLUXDB_HOST = 'localhost' | ||
INFLUXDB_PORT = 8086 | ||
INFLUXDB_USER = 'galaxy' | ||
INFLUXDB_PASS = 'galaxy' | ||
INFLUXDB_DB = 'galaxy' | ||
|
||
|
||
client = InfluxDBClient( | ||
host=INFLUXDB_HOST, | ||
port=INFLUXDB_PORT, | ||
username=INFLUXDB_USER, | ||
password=INFLUXDB_PASS | ||
) | ||
|
||
client.create_database(INFLUXDB_DB) | ||
client.switch_database(INFLUXDB_DB) | ||
|
||
# Retention policies | ||
#client.query( | ||
# "CREATE RETENTION POLICY a_month ON %s DURATION 30d REPLICATION 1" | ||
# % INFLUXDB_DB | ||
#) | ||
client.query( | ||
"CREATE RETENTION POLICY a_year ON %s DURATION 365d REPLICATION 1 DEFAULT" | ||
% INFLUXDB_DB | ||
) | ||
|
||
# Continuous queries | ||
#client.query( | ||
# "DROP CONTINUOUS QUERY cq_search_criteria_per_day ON %s" % INFLUXDB_DB | ||
#) | ||
# | ||
#client.query( | ||
# "CREATE CONTINUOUS QUERY cq_search_criteria_per_day ON %s " | ||
# "RESAMPLE EVERY 30m " | ||
# "BEGIN " | ||
# "SELECT count(value) AS value INTO search_criteria_per_day FROM a_month.search_criteria " | ||
# "GROUP BY time(1d), * " | ||
# "END" | ||
# % INFLUXDB_DB | ||
#) |
Oops, something went wrong.