def format(self, rules=None, name='promgen'): content = prometheus.render_rules(rules) response = HttpResponse(content) response['Content-Type'] = 'application/x-yaml' response[ 'Content-Disposition'] = 'attachment; filename=%s.rule.yml' % name return response
def handle(self, **kwargs): if kwargs['out']: prometheus.write_rules( path=kwargs['out'], reload=kwargs['reload'], version=kwargs['version'] ) else: self.stdout.write(prometheus.render_rules(version=kwargs['version']))
def write_rules(path=None, reload=True, chmod=0o644, version=None): if path is None: path = settings.PROMGEN["prometheus"]["rules"] with atomic_write(path, mode="wb", overwrite=True) as fp: # Set mode on our temporary file before we write and move it os.chmod(fp.name, chmod) fp.write(prometheus.render_rules(version=version)) if reload: reload_prometheus()
def write_rules(path=None, reload=True, chmod=0o644): if path is None: path = util.setting("prometheus:rules") with atomic_write(path, mode="wb", overwrite=True) as fp: # Set mode on our temporary file before we write and move it os.chmod(fp.name, chmod) fp.write(prometheus.render_rules()) if reload: reload_prometheus()
def handle(self, **kwargs): if kwargs['out']: tasks.write_rules( path=kwargs['out'], reload=kwargs['reload'], ) else: # Since we're already working with utf8 encoded data, we can skip # the newline ending here self.stdout.ending = None self.stdout.buffer.write(prometheus.render_rules())
def format(self, rules=None, name='promgen'): version = settings.PROMGEN['prometheus'].get('version', 1) content = prometheus.render_rules(rules, version=version) response = HttpResponse(content) if version == 1: response['Content-Type'] = 'text/plain; charset=utf-8' response['Content-Disposition'] = 'attachment; filename=%s.rule' % name else: response['Content-Type'] = 'application/x-yaml' response['Content-Disposition'] = 'attachment; filename=%s.rule.yml' % name return response
def test_write(self, mock_render): result = prometheus.render_rules() self.assertEqual(result, _RULES % self.rule.id)
def handle(self, **kwargs): prometheus.check_rules(models.Rule.objects.all()) if kwargs['out']: prometheus.write_rules(kwargs['out'], kwargs['reload']) else: self.stdout.write(prometheus.render_rules())
def test_write_new(self, mock_post): result = prometheus.render_rules(version=2) self.assertEqual(result, _RULE_NEW % self.rule.id)
def test_write_old(self, mock_post): result = prometheus.render_rules(version=1) self.assertEqual(result, _RULES % self.rule.id)
def get(self, request): return HttpResponse(prometheus.render_rules(), content_type='text/plain; charset=utf-8')
def get(self, request, pk): service = get_object_or_404(models.Service, id=pk) rules = models.Rule.filter(obj=service) return HttpResponse(prometheus.render_rules(rules), content_type='text/plain; charset=utf-8')