Skip to content

Commit

Permalink
add metric page
Browse files Browse the repository at this point in the history
  • Loading branch information
tianj7 committed Mar 5, 2025
1 parent 58b8322 commit 4a934b3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/UserMetricDashboard/UserMetricDashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dashboard {
padding: 20px 20px;
background: inherit;
}
42 changes: 42 additions & 0 deletions src/UserMetricDashboard/UserMetricDashboard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, {useState} from 'react';
import { fetchWithCreds } from '../actions';
import { auditAPIPath } from '../localconf';

export const getAuditData = async (url) => {
const urlPath = `${auditAPIPath}log/${url}`;
const { data } = await fetchWithCreds({ path: urlPath, method: 'GET' });
return data;
};

const UserMetricDashboard = () => {
const [totalLogins, setTotalLogins] = useState(-1);
const [uchicagoLogins, setUchicagoLogins] = useState(-1);
const [vaLogins, setVaLogins] = useState(-1);
const [totalDownloads, setTotalDownloads] = useState(-1);

const epochTimeThirtyDaysAgo = Math.round((Date.now() - (180 * 24 * 60 * 60 * 1000))/1000)

getAuditData('login?start=' + epochTimeThirtyDaysAgo + '&count').then((count) => {console.log('setting total login', count); setTotalLogins(count.data);});
getAuditData('login?start=' + epochTimeThirtyDaysAgo + '&count&fence_idp=shibboleth').then((count) => {console.log('setting total login', count); setUchicagoLogins(count.data);});;
getAuditData('login?start=' + epochTimeThirtyDaysAgo + '&count&idp=cognito').then((count) => {console.log('setting total login', count); setVaLogins(count.data);});;
getAuditData('presigned_url?start=' + epochTimeThirtyDaysAgo + '&count').then((count) => {console.log('setting total login', count); setTotalDownloads(count.data);});;

return (
<div className='dashboard'>
<h1>Metrics</h1>
<h3>Total Login: {totalLogins}</h3>
<h3>Uchicago Login: {uchicagoLogins}</h3>
<h3>VA Login: {vaLogins}</h3>
<h3>Downloads: {totalDownloads}</h3>
</div>
);

}

UserMetricDashboard.propTypes = {
};

UserMetricDashboard.defaultProps = {
};

export default UserMetricDashboard;
2 changes: 2 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import NotFound from './components/NotFound';
import AccessDenied from './components/AccessDenied';
import ErrorPage403 from './components/ErrorPage403';
import GenericAccessRequestForm from './GenericAccessRequestForm/GenericAccessRequestForm';
import UserMetricDashboard from './UserMetricDashboard/UserMetricDashboard'

// monitor user's session
sessionMonitor.start();
Expand Down Expand Up @@ -549,6 +550,7 @@ async function init() {
}
/>
)}
<FaroRoute path="/metrics" component={UserMetricDashboard} />
<FaroRoute
path='/not-found'
component={NotFound}
Expand Down

0 comments on commit 4a934b3

Please sign in to comment.