diff --git a/config.yaml b/config.yaml index f749eeec1a1873806afb065699869ecb50b102c9..903d418c4f9baa7b101dda3e1b4b5d30cf0bcb9e 100644 --- a/config.yaml +++ b/config.yaml @@ -12,6 +12,11 @@ "default": !!bool "false" "description": | Setting this to True will allow supporting services to log to syslog. + "incomingtofile": + "type": "boolean" + "default": !!bool "false" + "description": | + Use file driver for incoming measures. "use-internal-endpoints": "type": "boolean" "default": !!bool "false" diff --git a/lib/charm/openstack/gnocchi.py b/lib/charm/openstack/gnocchi.py index 034c2c5a7db387d440016f6c76f19b599847d1bd..3e32802ed3b00350220be3ba6e90f7302df57ccb 100644 --- a/lib/charm/openstack/gnocchi.py +++ b/lib/charm/openstack/gnocchi.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import errno import os import pwd import grp @@ -84,6 +85,37 @@ def ceph_config(config): return CEPH_CONF +@charms_openstack.adapters.config_property +def file_pathbase(config): + file_pathbasedir = '/var/lib/gnocchi/measures' + # create path if it does not exist + try: + os.makedirs(file_pathbasedir) + except OSError as exc: + if exc.errno == errno.EEXIST and os.path.isdir(file_pathbasedir): + pass + else: + raise + usr = GnocchiCharm.user + gru = GnocchiCharm.group + uid = pwd.getpwnam(usr).pw_uid + gid = grp.getgrnam(gru).gr_gid + os.chown(file_pathbasedir, uid, gid) + # mount tmpfs unless already mounted + do_mount = 1 + cmd_out = subprocess.check_output(['cat', '/proc/mounts']) + lines = cmd_out.split('\n') + for line in lines: + if file_pathbasedir in line: + do_mount = 0 + break + tmpfs_size = 'size=128m' + if do_mount == 1: + subprocess.check_call(['mount', '-t', 'tmpfs', '-o', tmpfs_size, + 'tmpfs', file_pathbasedir]) + return file_pathbasedir + + # TODO(jamespage): charms.openstack class StorageCephRelationAdapter(adapters.OpenStackRelationAdapter): diff --git a/templates/gnocchi.conf b/templates/gnocchi.conf index 2e5f4097235fc82c769df31a9cd18b94c2e8f18c..66f94fd82152ed8f101c40519dde5c74dece011c 100644 --- a/templates/gnocchi.conf +++ b/templates/gnocchi.conf @@ -21,6 +21,12 @@ url = {{ shared_db.uri }} [metricd] workers = {{ options.workers }} +{% if options.incomingtofile -%} +[incoming] +driver = file +file_basepath = {{ options.file_pathbase }} +{%- endif %} + [storage] {% if coordinator_memcached.url -%} coordination_url = {{ coordinator_memcached.url }} diff --git a/templates/queens/gnocchi.conf b/templates/queens/gnocchi.conf index bf6091480435d67f2c31095b81b345b7d6f37e5e..9369c4cc37d29d02e405a4a2384765c38dafde85 100644 --- a/templates/queens/gnocchi.conf +++ b/templates/queens/gnocchi.conf @@ -25,6 +25,12 @@ url = {{ shared_db.uri }} [metricd] workers = {{ options.workers }} +{% if options.incomingtofile -%} +[incoming] +driver = file +file_basepath = /var/lib/gnocchi/measures/ +{%- endif %} + [storage] {% if storage_ceph.key -%} driver = ceph