Skip to content

Commit

Permalink
Initial work on uptime homepage API
Browse files Browse the repository at this point in the history
Resolves elastic#69716
  • Loading branch information
andrewvc committed Jun 26, 2020
1 parent 5c8df21 commit deab3de
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions x-pack/plugins/uptime/public/apps/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ import {
} from '../../../../../src/plugins/data/public';
import { alertTypeInitializers } from '../lib/alert_types';
import { kibanaService } from '../state/kibana_service';
import { UptimeFetchDataResponse } from 'x-pack/plugins/observability/public/typings/fetch_data_response';
import { fetchSnapshotCount, fetchIndexStatus, fetchPingHistogram } from '../state/api';
import { ObservabilityPluginSetup } from 'x-pack/plugins/observability/public';

export interface ClientPluginsSetup {
data: DataPublicPluginSetup;
home: HomePublicPluginSetup;
observability: ObservabilityPluginSetup;
triggers_actions_ui: TriggersAndActionsUIPublicPluginSetup;
}

Expand Down Expand Up @@ -63,6 +67,51 @@ export class UptimePlugin
});
}

// This doesn't actually work
plugins.observability.dashboard.register({
appName: 'uptime',
hasData: async () => {
const status = await fetchIndexStatus();
return status.docCount > 0;
},
fetchData: async ({startTime, endTime, bucketSize}) => {
const snapshot = await fetchSnapshotCount({dateRangeStart: startTime, dateRangeEnd: endTime});
const pings = await fetchPingHistogram({dateStart: startTime, dateEnd: endTime});
const response: UptimeFetchDataResponse = {
title: 'Uptime',
appLink: "/app/uptime#/", // Todo is there some sort of helper that handles subpaths?
stats: {
monitors: {
type: 'number',
label: 'Monitors',
value: snapshot.total,
},
up: {
type: 'number',
label: 'Up',
value: snapshot.up,
},
down: {
type: 'number',
label: 'Down',
value: snapshot.down
}
},
series: {
up: {
label: 'Up',
coordinates: pings.histogram.map(p => { return {x: p.x!, y: p.upCount || 0}})
},
down: {
label: 'Down',
coordinates: pings.histogram.map(p => { return {x: p.x!, y: p.downCount || 0}})
}
}
};
return response;
},
});

core.application.register({
appRoute: '/app/uptime#/',
id: PLUGIN.ID,
Expand Down

0 comments on commit deab3de

Please sign in to comment.