예제 #1
0
 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
예제 #2
0
파일: rules.py 프로젝트: witzatom/promgen
 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']))
예제 #3
0
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()
예제 #4
0
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()
예제 #5
0
 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())
예제 #6
0
 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
예제 #7
0
 def test_write(self, mock_render):
     result = prometheus.render_rules()
     self.assertEqual(result, _RULES % self.rule.id)
예제 #8
0
파일: rules.py 프로젝트: wyatt88/promgen
 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())
예제 #9
0
 def test_write_new(self, mock_post):
     result = prometheus.render_rules(version=2)
     self.assertEqual(result, _RULE_NEW % self.rule.id)
예제 #10
0
 def test_write_old(self, mock_post):
     result = prometheus.render_rules(version=1)
     self.assertEqual(result, _RULES % self.rule.id)
예제 #11
0
파일: views.py 프로젝트: dikang123/promgen
 def get(self, request):
     return HttpResponse(prometheus.render_rules(), content_type='text/plain; charset=utf-8')
예제 #12
0
파일: views.py 프로젝트: dikang123/promgen
 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')