* [pve-devel] [PATCH manager v2 1/2] api2/cluster: add 'metricserver' api endpoints
2020-11-20 14:12 [pve-devel] [PATCH manager v2 0/2] add UI support for editing metric servers Dominik Csapak
@ 2020-11-20 14:12 ` Dominik Csapak
2020-11-20 14:12 ` [pve-devel] [PATCH manager v2 2/2] ui: add MetricServerView to Datacenter Dominik Csapak
2020-11-23 6:11 ` [pve-devel] applied: [PATCH manager v2 0/2] add UI support for editing metric servers Thomas Lamprecht
2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2020-11-20 14:12 UTC (permalink / raw)
To: pve-devel
modeled after our typical api endpoints for sectionschema configs
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
PVE/API2/Cluster.pm | 7 +
PVE/API2/Cluster/Makefile | 1 +
PVE/API2/Cluster/MetricServerConfig.pm | 228 +++++++++++++++++++++++++
3 files changed, 236 insertions(+)
create mode 100644 PVE/API2/Cluster/MetricServerConfig.pm
diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index e768cbc6..4b570e75 100644
--- a/PVE/API2/Cluster.pm
+++ b/PVE/API2/Cluster.pm
@@ -25,6 +25,7 @@ use PVE::API2::ACMEPlugin;
use PVE::API2::Backup;
use PVE::API2::BackupInfo;
use PVE::API2::Cluster::Ceph;
+use PVE::API2::Cluster::MetricServerConfig;
use PVE::API2::ClusterConfig;
use PVE::API2::Firewall::Cluster;
use PVE::API2::HAConfig;
@@ -43,6 +44,11 @@ __PACKAGE__->register_method ({
path => 'replication',
});
+__PACKAGE__->register_method ({
+ subclass => "PVE::API2::Cluster::MetricServerConfig",
+ path => 'metricserver',
+});
+
__PACKAGE__->register_method ({
subclass => "PVE::API2::ClusterConfig",
path => 'config',
@@ -132,6 +138,7 @@ __PACKAGE__->register_method ({
{ name => 'config' },
{ name => 'acme' },
{ name => 'ceph' },
+ { name => 'metricserver' },
];
if ($have_sdn) {
diff --git a/PVE/API2/Cluster/Makefile b/PVE/API2/Cluster/Makefile
index 8d8388c7..3f11006f 100644
--- a/PVE/API2/Cluster/Makefile
+++ b/PVE/API2/Cluster/Makefile
@@ -3,6 +3,7 @@ include ../../../defines.mk
# for node independent, cluster-wide applicable, API endpoints
# ensure we do not conflict with files shipped by pve-cluster!!
PERLSOURCE= \
+ MetricServerConfig.pm \
Ceph.pm
all:
diff --git a/PVE/API2/Cluster/MetricServerConfig.pm b/PVE/API2/Cluster/MetricServerConfig.pm
new file mode 100644
index 00000000..28bb58c8
--- /dev/null
+++ b/PVE/API2/Cluster/MetricServerConfig.pm
@@ -0,0 +1,228 @@
+package PVE::API2::Cluster::MetricServerConfig;
+
+use warnings;
+use strict;
+
+use PVE::Tools qw(extract_param);
+use PVE::Exception qw(raise_perm_exc raise_param_exc);
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::RPCEnvironment;
+use PVE::ExtMetric;
+
+use PVE::RESTHandler;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+ name => 'index',
+ path => '',
+ method => 'GET',
+ description => "List configured metric servers.",
+ permissions => {
+ check => ['perm', '/', ['Sys.Audit']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {},
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ id => {
+ description => "The ID of the entry.",
+ type => 'string'
+ },
+ disable => {
+ description => "Flag to disable the plugin.",
+ type => 'boolean',
+ },
+ type => {
+ description => "Plugin type.",
+ type => 'string',
+ },
+ server => {
+ description => "Server dns name or IP address",
+ type => 'string',
+ },
+ port => {
+ description => "Server network port",
+ type => 'integer',
+ },
+ },
+ },
+ links => [ { rel => 'child', href => "{id}" } ],
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $res = [];
+ my $status_cfg = PVE::Cluster::cfs_read_file('status.cfg');
+
+ for my $id (sort keys %{$status_cfg->{ids}}) {
+ my $plugin_config = $status_cfg->{ids}->{$id};
+ push @$res, {
+ id => $id,
+ disable => $plugin_config->{disable} // 0,
+ type => $plugin_config->{type},
+ server => $plugin_config->{server},
+ port => $plugin_config->{port},
+ };
+ }
+
+ return $res;
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'read',
+ path => '{id}',
+ method => 'GET',
+ description => "Read metric server configuration.",
+ permissions => {
+ check => ['perm', '/', ['Sys.Audit']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ id => {
+ type => 'string',
+ format => 'pve-configid',
+ },
+ },
+ },
+ returns => { type => 'object' },
+ code => sub {
+ my ($param) = @_;
+
+ my $status_cfg = PVE::Cluster::cfs_read_file('status.cfg');
+ my $id = $param->{id};
+
+ if (!defined($status_cfg->{ids}->{$id})) {
+ die "status server entry '$id' does not exist\n";
+ }
+
+ return $status_cfg->{ids}->{$id};
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'create',
+ path => '',
+ protected => 1,
+ method => 'POST',
+ description => "Create a new external metric server config",
+ permissions => {
+ check => ['perm', '/', ['Sys.Modify']],
+ },
+ parameters => PVE::Status::Plugin->createSchema(),
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ my $type = extract_param($param, 'type');
+ my $plugin = PVE::Status::Plugin->lookup($type);
+ my $id = extract_param($param, 'id');
+
+ PVE::Cluster::cfs_lock_file('status.cfg', undef, sub {
+ my $cfg = PVE::Cluster::cfs_read_file('status.cfg');
+
+ die "Metric server '$id' already exists\n"
+ if $cfg->{ids}->{$id};
+
+ my $opts = $plugin->check_config($id, $param, 1, 1);
+ $cfg->{ids}->{$id} = $opts;
+
+ PVE::Cluster::cfs_write_file('status.cfg', $cfg);
+ });
+ die $@ if $@;
+
+ return;
+ }});
+
+
+__PACKAGE__->register_method ({
+ name => 'update',
+ protected => 1,
+ path => '{id}',
+ method => 'PUT',
+ description => "Update metric server configuration.",
+ permissions => {
+ check => ['perm', '/', ['Sys.Modify']],
+ },
+ parameters => PVE::Status::Plugin->updateSchema(),
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ my $id = extract_param($param, 'id');
+ my $digest = extract_param($param, 'digest');
+ my $delete = extract_param($param, 'delete');
+
+ PVE::Cluster::cfs_lock_file('status.cfg', undef, sub {
+ my $cfg = PVE::Cluster::cfs_read_file('status.cfg');
+
+ PVE::SectionConfig::assert_if_modified($cfg, $digest);
+
+ my $data = $cfg->{ids}->{$id};
+ die "no such server '$id'\n" if !$data;
+
+ my $plugin = PVE::Status::Plugin->lookup($data->{type});
+ my $opts = $plugin->check_config($id, $param, 0, 1);
+
+ for my $k (keys %$opts) {
+ $data->{$k} = $opts->{$k};
+ }
+
+ if ($delete) {
+ my $options = $plugin->private()->{options}->{$data->{type}};
+ for my $k (PVE::Tools::split_list($delete)) {
+ my $d = $options->{$k} || die "no such option '$k'\n";
+ die "unable to delete required option '$k'\n" if !$d->{optional};
+ die "unable to delete fixed option '$k'\n" if $d->{fixed};
+
+ delete $data->{$k};
+ }
+ }
+
+ PVE::Cluster::cfs_write_file('status.cfg', $cfg);
+ });
+ die $@ if $@;
+
+ return;
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'delete',
+ protected => 1,
+ path => '{id}',
+ method => 'DELETE',
+ description => "Remove Metric server.",
+ permissions => {
+ check => ['perm', '/', ['Sys.Modify']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ id => {
+ type => 'string',
+ format => 'pve-configid',
+ },
+ }
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ PVE::Cluster::cfs_lock_file('status.cfg', undef, sub {
+ my $cfg = PVE::Cluster::cfs_read_file('status.cfg');
+
+ my $id = $param->{id};
+ delete $cfg->{ids}->{$id};
+ PVE::Cluster::cfs_write_file('status.cfg', $cfg);
+ });
+ die $@ if $@;
+
+ return;
+ }});
+
+1;
--
2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pve-devel] [PATCH manager v2 2/2] ui: add MetricServerView to Datacenter
2020-11-20 14:12 [pve-devel] [PATCH manager v2 0/2] add UI support for editing metric servers Dominik Csapak
2020-11-20 14:12 ` [pve-devel] [PATCH manager v2 1/2] api2/cluster: add 'metricserver' api endpoints Dominik Csapak
@ 2020-11-20 14:12 ` Dominik Csapak
2020-11-23 6:11 ` [pve-devel] applied: [PATCH manager v2 0/2] add UI support for editing metric servers Thomas Lamprecht
2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2020-11-20 14:12 UTC (permalink / raw)
To: pve-devel
adds ui support for configuring the External Metric servers.
for now, influxdb and graphite edit windows do not share code,
it would be ideal to do that once we add more plugins
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
www/manager6/Makefile | 1 +
www/manager6/dc/Config.js | 6 +
www/manager6/dc/MetricServerView.js | 397 ++++++++++++++++++++++++++++
3 files changed, 404 insertions(+)
create mode 100644 www/manager6/dc/MetricServerView.js
diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 4fa8e1a3..a2514464 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -146,6 +146,7 @@ JSSRC= \
dc/TokenView.js \
dc/UserEdit.js \
dc/UserView.js \
+ dc/MetricServerView.js \
lxc/CmdMenu.js \
lxc/Config.js \
lxc/CreateWizard.js \
diff --git a/www/manager6/dc/Config.js b/www/manager6/dc/Config.js
index 905c3dc0..2fdba743 100644
--- a/www/manager6/dc/Config.js
+++ b/www/manager6/dc/Config.js
@@ -231,6 +231,12 @@ Ext.define('PVE.dc.Config', {
list_refs_url: '/cluster/firewall/refs',
itemId: 'firewall-ipset'
},
+ {
+ xtype: 'pveMetricServerView',
+ title: gettext('Metric Server'),
+ iconCls: 'fa fa-bar-chart',
+ itemId: 'metricservers',
+ },
{
xtype: 'pveDcSupport',
title: gettext('Support'),
diff --git a/www/manager6/dc/MetricServerView.js b/www/manager6/dc/MetricServerView.js
new file mode 100644
index 00000000..7777c313
--- /dev/null
+++ b/www/manager6/dc/MetricServerView.js
@@ -0,0 +1,397 @@
+Ext.define('PVE.dc.MetricServerView', {
+ extend: 'Ext.grid.Panel',
+ alias: ['widget.pveMetricServerView'],
+
+ stateful: true,
+ stateId: 'grid-metricserver',
+
+ controller: {
+ xclass: 'Ext.app.ViewController',
+
+ render_type: function(value) {
+ switch (value) {
+ case 'influxdb': return "InfluxDB";
+ case 'graphite': return "Graphite";
+ default: return Proxmox.Utils.unknownText;
+ }
+ },
+
+ addInfluxDB: function() {
+ let me = this;
+ Ext.create(`PVE.dc.InfluxDBEdit`, {
+ url: `/api2/extjs/cluster/metricserver`,
+ autoShow: true,
+ listeners: {
+ destroy: () => me.reload(),
+ },
+ });
+ },
+
+ addGraphite: function() {
+ let me = this;
+ Ext.create(`PVE.dc.GraphiteEdit`, {
+ url: `/api2/extjs/cluster/metricserver`,
+ autoShow: true,
+ listeners: {
+ destroy: () => me.reload(),
+ },
+ });
+ },
+
+ editServer: function() {
+ let me = this;
+ let view = me.getView();
+ let selection = view.getSelection();
+ if (!selection || selection.length < 1) {
+ return;
+ }
+
+ let rec = selection[0];
+
+ let xtype = me.render_type(rec.data.type);
+ Ext.create(`PVE.dc.${xtype}Edit`, {
+ url: `/api2/extjs/cluster/metricserver/${rec.data.id}`,
+ serverid: rec.data.id,
+ autoShow: true,
+ listeners: {
+ destroy: () => me.reload(),
+ },
+ });
+ },
+
+ reload: function() {
+ this.getView().getStore().load();
+ },
+ },
+
+ store: {
+ autoLoad: true,
+ id: 'metricservers',
+ proxy: {
+ type: 'proxmox',
+ url: '/api2/json/cluster/metricserver',
+ },
+ },
+
+ columns: [
+ {
+ text: gettext('Name'),
+ flex: 2,
+ dataIndex: 'id',
+ },
+ {
+ text: gettext('Type'),
+ flex: 1,
+ dataIndex: 'type',
+ renderer: 'render_type',
+ },
+ {
+ text: gettext('Enabled'),
+ dataIndex: 'disable',
+ width: 100,
+ renderer: Proxmox.Utils.format_neg_boolean,
+ },
+ {
+ text: gettext('Server'),
+ width: 200,
+ dataIndex: 'server',
+ },
+ {
+ text: gettext('Port'),
+ width: 100,
+ dataIndex: 'port',
+ },
+ ],
+
+ tbar: [
+ {
+ text: gettext('Add'),
+ menu: [
+ {
+ text: 'Graphite',
+ handler: 'addGraphite',
+ },
+ {
+ text: 'InfluxDB',
+ handler: 'addInfluxDB',
+ },
+ ],
+ },
+ {
+ text: gettext('Edit'),
+ xtype: 'proxmoxButton',
+ handler: 'editServer',
+ disabled: true,
+ },
+ {
+ xtype: 'proxmoxStdRemoveButton',
+ baseurl: `/api2/extjs/cluster/metricserver`,
+ callback: 'reload',
+ },
+ ],
+
+ listeners: {
+ itemdblclick: 'editServer',
+ },
+
+ initComponent: function() {
+ var me = this;
+
+ me.callParent();
+
+ Proxmox.Utils.monStoreErrors(me, me.getStore());
+ },
+});
+
+Ext.define('PVE.dc.InfluxDBEdit', {
+ extend: 'Proxmox.window.Edit',
+ mixins: ['Proxmox.Mixin.CBind'],
+
+ subject: 'InfluxDB',
+
+ cbindData: function() {
+ let me = this;
+ me.isCreate = !me.serverid;
+ me.serverid = me.serverid || "";
+ me.method = me.isCreate ? 'POST' : 'PUT';
+ if (!me.isCreate) {
+ me.subject = `InfluxDB: ${me.serverid}`;
+ }
+ return {};
+ },
+
+ items: [
+ {
+ xtype: 'inputpanel',
+
+ onGetValues: function(values) {
+ values.disable = values.enable ? 0 : 1;
+ delete values.enable;
+ return values;
+ },
+
+ column1: [
+ {
+ xtype: 'hidden',
+ name: 'type',
+ value: 'influxdb',
+ cbind: {
+ submitValue: '{isCreate}',
+ },
+ },
+ {
+ fieldLabel: gettext('Name'),
+ xtype: 'pmxDisplayEditField',
+ name: 'id',
+ allowBlank: false,
+ cbind: {
+ editable: '{isCreate}',
+ value: '{serverid}',
+ },
+ },
+ {
+ fieldLabel: gettext('Enabled'),
+ xtype: 'checkbox',
+ inputValue: 1,
+ uncheckedValue: 0,
+ checked: true,
+ name: 'enable',
+ },
+ ],
+
+ column2: [
+ {
+ fieldLabel: gettext('Server'),
+ xtype: 'proxmoxtextfield',
+ name: 'server',
+ allowBlank: false,
+ },
+ {
+ fieldLabel: gettext('Port'),
+ xtype: 'proxmoxintegerfield',
+ minValue: 1,
+ maximum: 65536,
+ name: 'port',
+ allowBlank: false,
+ },
+ ],
+
+ advancedColumn1: [], // has to exists to render any advanced columns
+
+ advancedColumn2: [
+ {
+ fieldLabel: 'MTU',
+ xtype: 'proxmoxintegerfield',
+ name: 'mtu',
+ minValue: 1,
+ emptyText: '1500',
+ submitEmpty: false,
+ cbind: {
+ deleteEmpty: '{!isCreate}',
+ },
+ },
+ ],
+ },
+ ],
+
+ initComponent: function() {
+ let me = this;
+ me.callParent();
+ if (!me.serverid) { return; }
+
+ me.load({
+ success: function(response, options) {
+ let values = response.result.data;
+ values.enable = !values.disable;
+ me.down('inputpanel').setValues(values);
+ },
+ });
+ },
+});
+
+Ext.define('PVE.dc.GraphiteEdit', {
+ extend: 'Proxmox.window.Edit',
+ mixins: ['Proxmox.Mixin.CBind'],
+
+ subject: 'Graphite',
+
+ cbindData: function() {
+ let me = this;
+ me.isCreate = !me.serverid;
+ me.serverid = me.serverid || "";
+ me.method = me.isCreate ? 'POST' : 'PUT';
+ if (!me.isCreate) {
+ me.subject = `Graphite: ${me.serverid}`;
+ }
+ return {};
+ },
+
+ items: [
+ {
+ xtype: 'inputpanel',
+
+ onGetValues: function(values) {
+ values.disable = values.enable ? 0 : 1;
+ delete values.enable;
+ return values;
+ },
+
+ column1: [
+ {
+ xtype: 'hidden',
+ name: 'type',
+ value: 'graphite',
+ cbind: {
+ submitValue: '{isCreate}',
+ },
+ },
+ {
+ fieldLabel: gettext('Name'),
+ xtype: 'pmxDisplayEditField',
+ name: 'id',
+ allowBlank: false,
+ cbind: {
+ editable: '{isCreate}',
+ value: '{serverid}',
+ },
+ },
+ {
+ fieldLabel: gettext('Enabled'),
+ xtype: 'checkbox',
+ inputValue: 1,
+ uncheckedValue: 0,
+ checked: true,
+ name: 'enable',
+ },
+ ],
+
+ column2: [
+ {
+ fieldLabel: gettext('Server'),
+ xtype: 'proxmoxtextfield',
+ name: 'server',
+ allowBlank: false,
+ },
+ {
+ fieldLabel: gettext('Port'),
+ xtype: 'proxmoxintegerfield',
+ minimum: 1,
+ maximum: 65536,
+ name: 'port',
+ allowBlank: false,
+ },
+ {
+ fieldLabel: gettext('Path'),
+ xtype: 'proxmoxtextfield',
+ emptyText: 'proxmox',
+ name: 'path',
+ cbind: {
+ deleteEmpty: '{!isCreate}',
+ },
+ },
+ ],
+
+ advancedColumn1: [
+ {
+ fieldLabel: gettext('Protocol'),
+ xtype: 'proxmoxKVComboBox',
+ name: 'proto',
+ value: '__default__',
+ cbind: {
+ deleteEmpty: '{!isCreate}',
+ },
+ comboItems: [
+ ['__default__', 'UDP'],
+ ['tcp', 'TCP'],
+ ],
+ listeners: {
+ change: function(field, value) {
+ let me = this;
+ me.up('inputpanel').down('field[name=timeout]').setDisabled(value !== 'tcp');
+ me.up('inputpanel').down('field[name=mtu]').setDisabled(value === 'tcp');
+ },
+ },
+ },
+ ],
+
+ advancedColumn2: [
+ {
+ fieldLabel: 'MTU',
+ xtype: 'proxmoxintegerfield',
+ name: 'mtu',
+ minimum: 1,
+ emptyText: '1500',
+ submitEmpty: false,
+ cbind: {
+ deleteEmpty: '{!isCreate}',
+ },
+ },
+ {
+ fieldLabel: gettext('TCP Timeout'),
+ xtype: 'proxmoxintegerfield',
+ name: 'timeout',
+ disabled: true,
+ cbind: {
+ deleteEmpty: '{!isCreate}',
+ },
+ minValue: 1,
+ emptyText: 1,
+ },
+ ],
+ },
+ ],
+
+ initComponent: function() {
+ let me = this;
+ me.callParent();
+ if (!me.serverid) { return; }
+
+ me.load({
+ success: function(response, options) {
+ let values = response.result.data;
+ values.enable = !values.disable;
+ me.down('inputpanel').setValues(values);
+ },
+ });
+ },
+});
--
2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread