Skip to content

Commit

Permalink
feat(Runtime): refresh Threads and Metrics periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
mmelko committed Sep 19, 2023
1 parent 8567e94 commit 04607cb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
16 changes: 11 additions & 5 deletions packages/hawtio/src/plugins/runtime/Metrics.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { Card, CardBody, CardHeader, Grid, GridItem, Title } from '@patternfly/react-core'
import React, { useEffect, useState } from 'react'
import { getMetrics } from '@hawtiosrc/plugins/runtime/runtime-service'
import { getMetrics, REFRESH_INTERVAL } from '@hawtiosrc/plugins/runtime/runtime-service'
import { Metric } from '@hawtiosrc/plugins/runtime/types'
import { ChartBullet } from '@patternfly/react-charts'

export const Metrics: React.FunctionComponent = () => {
const [metrics, setMetrics] = useState<Metric[]>([])

useEffect(() => {
getMetrics().then(m => {
console.log('received metrics:', m)
setMetrics(m)
})
let timeoutHandle: NodeJS.Timeout
const readMetrics = async () => {
const metrics = await getMetrics()
setMetrics(metrics)

timeoutHandle = setTimeout(readMetrics, REFRESH_INTERVAL)
}

readMetrics()
return () => timeoutHandle && clearTimeout(timeoutHandle)
}, [])

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/hawtio/src/plugins/runtime/SysProps.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen, waitFor, within } from '@testing-library/react'
import { SysProps } from '@hawtiosrc/plugins/runtime/SysProps'
import { SystemProperty } from '@hawtiosrc/plugins/runtime/runtime-service'
import { SystemProperty } from './types'
import userEvent from '@testing-library/user-event'

function getMockedProperties(): SystemProperty[] {
Expand Down
3 changes: 2 additions & 1 deletion packages/hawtio/src/plugins/runtime/SysProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import {
} from '@patternfly/react-core'
import { TableComposable, Tbody, Td, Th, Thead, ThProps, Tr } from '@patternfly/react-table'
import { SearchIcon } from '@patternfly/react-icons'
import { getSystemProperties, SystemProperty } from '@hawtiosrc/plugins/runtime/runtime-service'
import { getSystemProperties } from './runtime-service'
import { objectSorter } from '@hawtiosrc/util/objects'
import { SystemProperty } from './types'

export const SysProps: React.FunctionComponent = () => {
const [properties, setProperties] = useState<{ key: string; value: string }[]>([])
Expand Down
18 changes: 11 additions & 7 deletions packages/hawtio/src/plugins/runtime/Threads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
dumpThreads,
enableThreadContentionMonitoring,
isThreadContentionMonitoringEnabled,
REFRESH_INTERVAL,
} from '@hawtiosrc/plugins/runtime/runtime-service'
import { objectSorter } from '@hawtiosrc/util/objects'
import { Thread } from '@hawtiosrc/plugins/runtime/types'
Expand Down Expand Up @@ -85,13 +86,16 @@ export const Threads: React.FunctionComponent = () => {
const [threadConnectionMonitoring, setThreadConnectionMonitoring] = useState(false)

useEffect(() => {
getThreads().then((props: Thread[]) => {
setThreads(props)
setFilteredThreads(props)
})
isThreadContentionMonitoringEnabled().then(enabled => {
setThreadConnectionMonitoring(enabled)
})
let timeoutHandle: NodeJS.Timeout
const readThreads = async () => {
const threads = await getThreads()
setThreads(threads)
setFilteredThreads(threads)
setThreadConnectionMonitoring(await isThreadContentionMonitoringEnabled())
timeoutHandle = setTimeout(readThreads, REFRESH_INTERVAL)
}
readThreads()
return () => timeoutHandle && clearTimeout(timeoutHandle)
}, [])

const onDeleteFilter = (filter: string) => {
Expand Down
1 change: 1 addition & 0 deletions packages/hawtio/src/plugins/runtime/runtime-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { jolokiaService } from '@hawtiosrc/plugins/shared'
import { Metric, SystemProperty, Thread } from './types'

export const REFRESH_INTERVAL = 5000
function convertMsToDaysHours(ms: number): string {
const seconds = Math.floor(ms / 1000)
const minutes = Math.floor(seconds / 60)
Expand Down
6 changes: 5 additions & 1 deletion packages/hawtio/src/plugins/runtime/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export type SystemProperty = { key: string; value: string }
export type SystemProperty = {
key: string
value: string
}

export type Metric = {
type: 'JVM' | 'System'
name: string
Expand Down

0 comments on commit 04607cb

Please sign in to comment.