-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from performant-software/feature/iiif82_system…
…_status IIIF #82 - System status
- Loading branch information
Showing
23 changed files
with
847 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Api::DashboardController < Api::BaseController | ||
def heap | ||
render json: { errors: [I18n.t('errors.dashboard_controller.unauthorized')] }, status: :unauthorized and return unless current_user.admin? | ||
|
||
service = Iiif::Server.new | ||
|
||
json = serializer.heap( | ||
service.status.dig(:data) | ||
) | ||
|
||
render json: json, status: :ok | ||
end | ||
|
||
def status | ||
render json: { errors: [I18n.t('errors.dashboard_controller.unauthorized')] }, status: :unauthorized and return unless current_user.admin? | ||
|
||
service = Iiif::Server.new | ||
|
||
json = serializer.status( | ||
service.health.dig(:data, :color), | ||
service.status.dig(:data) | ||
) | ||
|
||
render json: json, status: :ok | ||
end | ||
|
||
private | ||
|
||
def serializer | ||
DashboardSerializer.new | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class DashboardSerializer | ||
def heap(info) | ||
{ | ||
used: info.dig(:vm, :usedHeapBytes), | ||
max: info.dig(:vm, :maxHeapBytes) | ||
} | ||
end | ||
|
||
def status(color, info) | ||
{ | ||
application: { | ||
name: I18n.t('dashboard_serializer.application_name'), | ||
version: info.dig(:application, :version) | ||
}, | ||
vm: { | ||
name: info.dig(:vm, :name), | ||
version: info.dig(:vm, :version) | ||
}, | ||
os: { | ||
name: info.dig(:vm, :vendor), | ||
processors: info.dig(:vm, :numProcessors) | ||
}, | ||
status_color: color | ||
} | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Iiif | ||
class Server | ||
|
||
def clear_cache(key) | ||
body = { | ||
verb: 'PurgeItemFromCache', | ||
identifier: key | ||
} | ||
|
||
parse_response HTTParty.post("#{ENV['IIIF_HOST']}/tasks", body: body.to_json, basic_auth: basic_auth) | ||
end | ||
|
||
def health | ||
parse_response HTTParty.get("#{ENV['IIIF_HOST']}/health") | ||
end | ||
|
||
def status | ||
parse_response HTTParty.get("#{ENV['IIIF_HOST']}/status", basic_auth: basic_auth) | ||
end | ||
|
||
private | ||
|
||
def basic_auth | ||
{ | ||
username: ENV['CANTALOUPE_API_USERNAME'], | ||
password: ENV['CANTALOUPE_API_PASSWORD'] | ||
} | ||
end | ||
|
||
def parse_response(response) | ||
if response.body.nil? || response.body.empty? | ||
body = '{}' | ||
else | ||
body = response.body | ||
end | ||
|
||
{ | ||
success?: response.success?, | ||
data: JSON.parse(body, symbolize_names: true), | ||
errors: response['exception'] || response['message'] || response['errors'] | ||
} | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// @flow | ||
|
||
import React, { type ComponentType } from 'react'; | ||
import styles from './AttributeView.module.css'; | ||
|
||
type Props = { | ||
label: string, | ||
value: string | ||
}; | ||
|
||
const AttributeView: ComponentType<any> = (props: Props) => ( | ||
<div | ||
className={styles.gridItem} | ||
> | ||
<div | ||
className={styles.label} | ||
> | ||
{ props.label } | ||
</div> | ||
<div | ||
className={styles.value} | ||
> | ||
{ props.value } | ||
</div> | ||
</div> | ||
); | ||
|
||
export default AttributeView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.gridItem .label { | ||
color: rgba(0, 0, 0, .6); | ||
padding-top: 0.25em; | ||
} | ||
|
||
.gridItem .value { | ||
font-weight: bold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// @flow | ||
|
||
import React, { type ComponentType } from 'react'; | ||
import { Icon } from 'semantic-ui-react'; | ||
|
||
type Props = { | ||
className?: string, | ||
status: 'positive' | 'warning' | 'negative' | ||
}; | ||
|
||
const StatusIcon: ComponentType<any> = (props: Props) => { | ||
if (props.status === 'positive') { | ||
return ( | ||
<Icon | ||
className={props.className} | ||
color='green' | ||
name='check circle' | ||
/> | ||
); | ||
} | ||
|
||
if (props.status === 'warning') { | ||
return ( | ||
<Icon | ||
className={props.className} | ||
color='yellow' | ||
name='warning circle' | ||
/> | ||
); | ||
} | ||
|
||
if (props.status === 'negative') { | ||
return ( | ||
<Icon | ||
className={props.className} | ||
color='red' | ||
name='times circle' | ||
/> | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export default StatusIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @flow | ||
|
||
import cx from 'classnames'; | ||
import React, { type ComponentType, type Node } from 'react'; | ||
import { | ||
Button, | ||
Dimmer, | ||
Header, | ||
Loader | ||
} from 'semantic-ui-react'; | ||
import styles from './Widget.module.css'; | ||
|
||
type Props = { | ||
children: Node, | ||
className?: string, | ||
loading: boolean, | ||
onReload?: () => void, | ||
title: string | ||
}; | ||
|
||
const Widget: ComponentType<any> = (props: Props) => ( | ||
<div | ||
className={cx(styles.widget, props.className)} | ||
> | ||
<Dimmer | ||
active={props.loading} | ||
inverted | ||
> | ||
<Loader /> | ||
</Dimmer> | ||
<div | ||
className={styles.headerContainer} | ||
> | ||
<Header | ||
className={cx(styles.ui, styles.header)} | ||
> | ||
{ props.title } | ||
</Header> | ||
{ props.onReload && ( | ||
<Button | ||
basic | ||
className={cx(styles.ui, styles.button, styles.reload)} | ||
icon='refresh' | ||
onClick={props.onReload} | ||
/> | ||
)} | ||
</div> | ||
{ props.children } | ||
</div> | ||
); | ||
|
||
export default Widget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.widget > .headerContainer { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
.widget > .headerContainer > .ui.header { | ||
margin-top: 0; | ||
} | ||
|
||
.widget > .headerContainer > .ui.button.reload, | ||
.widget > .headerContainer > .ui.button.reload:active, | ||
.widget > .headerContainer > .ui.button.reload:hover, | ||
.widget > .headerContainer > .ui.button.reload:focus { | ||
background: none !important; | ||
box-shadow: none !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.