2020-04-30 21:59:35 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { i18n } from '@kbn/i18n';
|
|
|
|
import {
|
|
|
|
App,
|
|
|
|
AppMountParameters,
|
|
|
|
CoreSetup,
|
|
|
|
CoreStart,
|
|
|
|
Plugin,
|
|
|
|
PluginInitializerContext,
|
|
|
|
} from 'kibana/public';
|
|
|
|
import {
|
|
|
|
FeatureCatalogueCategory,
|
|
|
|
HomePublicPluginSetup,
|
|
|
|
} from '../../../../src/plugins/home/public';
|
2020-06-05 09:55:42 +02:00
|
|
|
import { UI_SETTINGS } from '../../../../src/plugins/data/public';
|
2020-05-05 23:56:22 +02:00
|
|
|
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/public';
|
2020-07-14 23:50:22 +02:00
|
|
|
import { MonitoringStartPluginDependencies, MonitoringConfig } from './types';
|
|
|
|
import { TriggersAndActionsUIPublicPluginSetup } from '../../triggers_actions_ui/public';
|
|
|
|
import { createCpuUsageAlertType } from './alerts/cpu_usage_alert';
|
|
|
|
import { createLegacyAlertTypes } from './alerts/legacy_alert';
|
|
|
|
|
|
|
|
interface MonitoringSetupPluginDependencies {
|
|
|
|
home?: HomePublicPluginSetup;
|
|
|
|
cloud?: { isCloudEnabled: boolean };
|
|
|
|
triggers_actions_ui: TriggersAndActionsUIPublicPluginSetup;
|
|
|
|
}
|
2020-04-30 21:59:35 +02:00
|
|
|
|
|
|
|
export class MonitoringPlugin
|
2020-07-14 23:50:22 +02:00
|
|
|
implements
|
|
|
|
Plugin<boolean, void, MonitoringSetupPluginDependencies, MonitoringStartPluginDependencies> {
|
2020-04-30 21:59:35 +02:00
|
|
|
constructor(private initializerContext: PluginInitializerContext<MonitoringConfig>) {}
|
|
|
|
|
|
|
|
public setup(
|
2020-07-14 23:50:22 +02:00
|
|
|
core: CoreSetup<MonitoringStartPluginDependencies>,
|
|
|
|
plugins: MonitoringSetupPluginDependencies
|
2020-04-30 21:59:35 +02:00
|
|
|
) {
|
|
|
|
const { home } = plugins;
|
|
|
|
const id = 'monitoring';
|
|
|
|
const icon = 'monitoringApp';
|
|
|
|
const title = i18n.translate('xpack.monitoring.stackMonitoringTitle', {
|
|
|
|
defaultMessage: 'Stack Monitoring',
|
|
|
|
});
|
|
|
|
const monitoring = this.initializerContext.config.get();
|
|
|
|
|
|
|
|
if (!monitoring.ui.enabled || !monitoring.enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (home) {
|
|
|
|
home.featureCatalogue.register({
|
|
|
|
id,
|
|
|
|
title,
|
|
|
|
icon,
|
|
|
|
path: '/app/monitoring',
|
|
|
|
showOnHomePage: true,
|
|
|
|
category: FeatureCatalogueCategory.ADMIN,
|
|
|
|
description: i18n.translate('xpack.monitoring.monitoringDescription', {
|
|
|
|
defaultMessage: 'Track the real-time health and performance of your Elastic Stack.',
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-14 23:50:22 +02:00
|
|
|
plugins.triggers_actions_ui.alertTypeRegistry.register(createCpuUsageAlertType());
|
|
|
|
const legacyAlertTypes = createLegacyAlertTypes();
|
|
|
|
for (const legacyAlertType of legacyAlertTypes) {
|
|
|
|
plugins.triggers_actions_ui.alertTypeRegistry.register(legacyAlertType);
|
|
|
|
}
|
|
|
|
|
2020-04-30 21:59:35 +02:00
|
|
|
const app: App = {
|
|
|
|
id,
|
|
|
|
title,
|
2020-07-16 00:07:30 +02:00
|
|
|
order: 9030,
|
2020-04-30 21:59:35 +02:00
|
|
|
euiIconType: icon,
|
|
|
|
category: DEFAULT_APP_CATEGORIES.management,
|
|
|
|
mount: async (params: AppMountParameters) => {
|
|
|
|
const [coreStart, pluginsStart] = await core.getStartServices();
|
|
|
|
const { AngularApp } = await import('./angular');
|
2020-07-14 23:50:22 +02:00
|
|
|
const deps: MonitoringStartPluginDependencies = {
|
2020-04-30 21:59:35 +02:00
|
|
|
navigation: pluginsStart.navigation,
|
2020-06-24 11:26:19 +02:00
|
|
|
kibanaLegacy: pluginsStart.kibanaLegacy,
|
2020-04-30 21:59:35 +02:00
|
|
|
element: params.element,
|
|
|
|
core: coreStart,
|
|
|
|
data: pluginsStart.data,
|
|
|
|
isCloud: Boolean(plugins.cloud?.isCloudEnabled),
|
|
|
|
pluginInitializerContext: this.initializerContext,
|
|
|
|
externalConfig: this.getExternalConfig(),
|
2020-07-14 23:50:22 +02:00
|
|
|
triggersActionsUi: plugins.triggers_actions_ui,
|
2020-04-30 21:59:35 +02:00
|
|
|
};
|
|
|
|
|
2020-06-24 11:26:19 +02:00
|
|
|
pluginsStart.kibanaLegacy.loadFontAwesome();
|
2020-04-30 21:59:35 +02:00
|
|
|
this.setInitialTimefilter(deps);
|
|
|
|
|
|
|
|
const monitoringApp = new AngularApp(deps);
|
2020-05-22 09:08:58 +02:00
|
|
|
const removeHistoryListener = params.history.listen((location) => {
|
2020-04-30 21:59:35 +02:00
|
|
|
if (location.pathname === '' && location.hash === '') {
|
|
|
|
monitoringApp.applyScope();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
removeHistoryListener();
|
|
|
|
monitoringApp.destroy();
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
core.application.register(app);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public start(core: CoreStart, plugins: any) {}
|
|
|
|
|
|
|
|
public stop() {}
|
|
|
|
|
2020-07-14 23:50:22 +02:00
|
|
|
private setInitialTimefilter({ core: coreContext, data }: MonitoringStartPluginDependencies) {
|
2020-04-30 21:59:35 +02:00
|
|
|
const { timefilter } = data.query.timefilter;
|
|
|
|
const { uiSettings } = coreContext;
|
|
|
|
const refreshInterval = { value: 10000, pause: false };
|
|
|
|
const time = { from: 'now-1h', to: 'now' };
|
|
|
|
timefilter.setRefreshInterval(refreshInterval);
|
|
|
|
timefilter.setTime(time);
|
|
|
|
uiSettings.overrideLocalDefault(
|
2020-06-05 09:55:42 +02:00
|
|
|
UI_SETTINGS.TIMEPICKER_REFRESH_INTERVAL_DEFAULTS,
|
2020-04-30 21:59:35 +02:00
|
|
|
JSON.stringify(refreshInterval)
|
|
|
|
);
|
|
|
|
uiSettings.overrideLocalDefault('timepicker:timeDefaults', JSON.stringify(time));
|
|
|
|
}
|
|
|
|
|
|
|
|
private getExternalConfig() {
|
|
|
|
const monitoring = this.initializerContext.config.get();
|
|
|
|
return [
|
|
|
|
['minIntervalSeconds', monitoring.ui.min_interval_seconds],
|
|
|
|
['showLicenseExpiration', monitoring.ui.show_license_expiration],
|
|
|
|
['showCgroupMetricsElasticsearch', monitoring.ui.container.elasticsearch.enabled],
|
|
|
|
['showCgroupMetricsLogstash', monitoring.ui.container.logstash.enabled],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|