diff --git a/promgen/migrations/0018_default_exporter_scheme.py b/promgen/migrations/0018_default_exporter_scheme.py new file mode 100644 index 000000000..27f70631f --- /dev/null +++ b/promgen/migrations/0018_default_exporter_scheme.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2.10 on 2020-03-16 08:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('promgen', '0017_alter_alertlabel_field'), + ] + + operations = [ + migrations.AddField( + model_name='defaultexporter', + name='scheme', + field=models.CharField(choices=[('http', 'http'), ('https', 'https')], default='http', help_text='Scrape exporter over http or https', max_length=5), + ), + migrations.AlterField( + model_name='defaultexporter', + name='job', + field=models.CharField(help_text='Exporter name. Example node, jmx, app', max_length=128), + ), + migrations.AlterField( + model_name='defaultexporter', + name='path', + field=models.CharField(blank=True, help_text='Exporter path. Defaults to /metrics', max_length=128), + ), + migrations.AlterField( + model_name='defaultexporter', + name='port', + field=models.IntegerField(help_text='Port Exporter is running on'), + ), + ] diff --git a/promgen/models.py b/promgen/models.py index 1c18e70fe..cb855666f 100644 --- a/promgen/models.py +++ b/promgen/models.py @@ -316,7 +316,7 @@ def __str__(self): return '{} [{}]'.format(self.name, self.farm.name) -class Exporter(models.Model): +class BaseExporter(models.Model): job = models.CharField( max_length=128, help_text="Exporter name. Example node, jmx, app" ) @@ -325,27 +325,25 @@ class Exporter(models.Model): max_length=128, blank=True, help_text="Exporter path. Defaults to /metrics" ) scheme = models.CharField( - max_length=5, choices=(("http", "http"), ("https", "https")), default="http", help_text="Scrape exporter over http or https" + max_length=5, + choices=(("http", "http"), ("https", "https")), + default="http", + help_text="Scrape exporter over http or https", ) - project = models.ForeignKey("Project", on_delete=models.CASCADE) - enabled = models.BooleanField(default=True) - class Meta: - ordering = ['job', 'port'] - unique_together = (('job', 'port', 'project',),) + abstract = True - def __str__(self): - return '{}:{}:{} ({})'.format(self.job, self.port, self.path, self.project) - def get_absolute_url(self): - return reverse('project-detail', kwargs={'pk': self.project.pk}) +class DefaultExporter(BaseExporter): + class Meta: + ordering = ["job", "port"] + unique_together = (("job", "port", "path"),) -class DefaultExporter(models.Model): - job = models.CharField(max_length=128) - port = models.IntegerField() - path = models.CharField(max_length=128, blank=True) +class Exporter(BaseExporter): + project = models.ForeignKey("Project", on_delete=models.CASCADE) + enabled = models.BooleanField(default=True) class Meta: ordering = ["job", "port"] diff --git a/promgen/templates/promgen/exporter_form.html b/promgen/templates/promgen/exporter_form.html index ea06bf529..070b994c6 100644 --- a/promgen/templates/promgen/exporter_form.html +++ b/promgen/templates/promgen/exporter_form.html @@ -63,6 +63,7 @@