Skip to content

Commit 3aa7d52

Browse files
committed
fixed grafana dashboards for docker
2 parents f272e49 + 8c48a1d commit 3aa7d52

File tree

19 files changed

+1881
-32
lines changed

19 files changed

+1881
-32
lines changed

app/charts/GrafanaEventChart.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface EventChartProps {
1212
// width: number;
1313
// }
1414

15-
type TimeFrame = '5m' | '15m' | '1h' | '2h' | '1d' | '2d' | '3d';
15+
type TimeFrame = '5m' | '15m' | '30m' | '1h' | '2h' | '1d' | '2d';
1616

1717

1818

@@ -84,11 +84,12 @@ const GrafanaEventChart: React.FC<EventChartProps> = React.memo(props => {
8484
<select name="graphType" id="graphType" onChange={(e) => setTimeFrame(e.target.value as TimeFrame)}>
8585
<option value={'5m'}>5 minutes</option>
8686
<option value={'15m'}>15 minutes</option>
87+
<option value={'30m'}>30 minutes</option>
8788
<option value={'1h'}>1 hour</option>
8889
<option value={'2h'}>2 hours</option>
8990
<option value={'1d'}>1 day</option>
9091
<option value={'2d'}>2 days</option>
91-
<option value={'3d'}>3 days</option>
92+
9293
</select>
9394
</div>
9495
{/* create chart using grafana iframe tag*/}

app/containers/EventContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ const EventContainer: React.FC<EventContainerProps> = React.memo(props => {
161161

162162
<div>
163163
{/* <div id="grafana" onClick={() => { setIsGrafana(!isGrafana) }}>Grafana</div> */}
164-
{service.includes('kafkametrics') || service.includes('kubernetesmetrics') || service.includes('books') || service.includes('customers') || service.includes('frontend') || service.includes('orders')? currChunk : []}
164+
<button>Inspect</button>
165+
{service.includes('kafkametrics') || service.includes('kubernetesmetrics') ? currChunk : []}
165166
{eventChartsArr.length > chunkSize && (
166167
<>
167168
<Button id="prevCharts" onClick={prevChunk} variant="contained" color="primary" disabled={currIndex <= chunkSize}>

app/containers/GraphsContainer.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import lightAndDark from '../components/Styling';
2323
import DockerHealthContainer from './DockerHealthContainer';
2424

2525
import '../stylesheets/GraphsContainer.scss';
26+
import { Link } from 'react-router-dom';
27+
import Inspect from './Inspect';
2628

2729
interface Params {
2830
app: any;
@@ -45,6 +47,7 @@ const GraphsContainer: React.FC = React.memo(props => {
4547
const [chart, setChart] = useState<string>('all');
4648
const [prevRoute, setPrevRoute] = useState<string>('');
4749
const { mode } = useContext(DashboardContext.DashboardContext);
50+
let [inspect, setInspect] = useState<boolean>(false);
4851

4952
useEffect(() => {
5053
const serviceArray = service.split(' ');
@@ -202,8 +205,21 @@ const GraphsContainer: React.FC = React.memo(props => {
202205
>
203206
Modify Metrics
204207
</button>
208+
{/* <Link className="sidebar-link" to="/Inspect" id="Inspect" >
209+
<SettingsIcon
210+
style={{
211+
WebkitBoxSizing: 'content-box',
212+
boxShadow: 'none',
213+
width: '35px',
214+
height: '35px',
215+
}}
216+
/>
217+
&emsp;Inspect
218+
</Link> */}
219+
<button onClick={() => { setInspect(!inspect) }}>Inspect</button>
205220
</nav>
206221
<Header app={app} service={service} live={live} setLive={setLive} />
222+
{inspect && <Inspect />}
207223
<div className="graphs-container">
208224
{chart === 'communications' ? (
209225
<div className="graphs">

app/containers/Inspect.jsx

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import React, { useEffect } from 'react';
2+
import * as d3 from 'd3'; // Import D3 libraries here
3+
import ForceGraph3D from '3d-force-graph'; // Import 3d-force-graph library here
4+
import dat from 'dat.gui'; // Import dat.gui library here
5+
import '../stylesheets/Inspect.scss';
6+
import { CSS2DRenderer, CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer.js';
7+
8+
9+
10+
// currently, Insepect only works statically, but it should be possible to make it dynamic. To do so, we need to make get kubernetes resources information from the backend, and then pass it to the graph.
11+
// It will be great if future iteration group can make it dynamic.
12+
13+
const Inspect = () => {
14+
useEffect(() => {
15+
// controls
16+
const controls = { 'DAG Orientation': 'td' };
17+
const gui = new dat.GUI();
18+
gui.add(controls, 'DAG Orientation', ['td', 'bu', 'lr', 'rl', 'zout', 'zin', 'radialout', 'radialin', null])
19+
.onChange(orientation => graph && graph.dagMode(orientation));
20+
21+
// graph config
22+
const NODE_REL_SIZE = 7;
23+
const graph = ForceGraph3D({
24+
extraRenderers: [new CSS2DRenderer()]
25+
})
26+
.width(1000)
27+
.height(500)
28+
.dagMode('td')
29+
.dagLevelDistance(100)
30+
.backgroundColor('#101020')
31+
.linkColor(() => 'rgba(255,255,255,0.2)')
32+
.nodeRelSize(NODE_REL_SIZE)
33+
.nodeId('path')
34+
.nodeVal('size')
35+
.nodeLabel('path')
36+
.nodeAutoColorBy('module')
37+
.nodeOpacity(0.9)
38+
.nodeLabel('path')
39+
.linkDirectionalParticles(2)
40+
.linkDirectionalParticleWidth(1)
41+
.linkDirectionalParticleSpeed(0.006)
42+
.linkWidth(5)
43+
.d3Force('collision', d3.forceCollide(node => Math.cbrt(node.size) * NODE_REL_SIZE))
44+
.d3VelocityDecay(0.3);
45+
46+
// Decrease repel intensity
47+
graph.d3Force('charge').strength(-500);
48+
49+
50+
51+
fetch('http://localhost:1111/api/kuberData')
52+
.then(r => r.text())
53+
.then(d3.csvParse)
54+
.then(data => {
55+
console.log(data)
56+
const nodes = [], links = [];
57+
data.forEach(({ size, path }) => {
58+
const levels = path.split('/'),
59+
level = levels.length - 1,
60+
module = level > 0 ? levels[1] : null,
61+
leaf = levels.pop(),
62+
parent = levels.join('/');
63+
64+
const node = {
65+
path,
66+
leaf,
67+
module,
68+
size: +size || 20,
69+
level
70+
};
71+
72+
nodes.push(node);
73+
74+
if (parent) {
75+
links.push({ source: parent, target: path, targetNode: node });
76+
}
77+
});
78+
79+
80+
graph(document.getElementById('graph'))
81+
.graphData({ nodes, links })
82+
.onNodeDragEnd(node => {
83+
node.fx = node.x;
84+
node.fy = node.y;
85+
node.fz = node.z;
86+
})
87+
.onNodeClick(node => {
88+
// Aim at node from outside it
89+
const distance = 40;
90+
const distRatio = 1 + distance / Math.hypot(node.x, node.y, node.z);
91+
92+
const newPos = node.x || node.y || node.z
93+
? { x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio }
94+
: { x: 0, y: 0, z: distance }; // special case if node is in (0,0,0)
95+
96+
graph.cameraPosition(
97+
newPos, // new position
98+
node, // lookAt ({ x, y, z })
99+
3000 // ms transition duration
100+
);
101+
102+
// Show label
103+
const nodeEl = document.createElement('div');
104+
nodeEl.innerHTML = node.path;
105+
nodeEl.style.color = node.color;
106+
nodeEl.className = 'node-label';
107+
return new CSS2DObject(nodeEl);
108+
})
109+
.nodeThreeObject((node) => {
110+
const nodeEl = document.createElement('div');
111+
nodeEl.textContent = node.path.split('/').pop().replace(/:.*/, '');
112+
nodeEl.style.color = node.color;
113+
nodeEl.className = 'node-label';
114+
return new CSS2DObject(nodeEl);
115+
})
116+
.nodeThreeObjectExtend(true);
117+
118+
119+
});
120+
}, []);
121+
122+
123+
return <div id="Infrastructure">
124+
<h2>Infrastructure</h2>
125+
<div id="graph" />;
126+
</div>
127+
// <div id="graph" />;
128+
};
129+
130+
export default Inspect;

app/containers/Resource.html

Whitespace-only changes.

app/stylesheets/Inspect.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
h2 {
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
}
6+
7+
#graph {
8+
display: flex;
9+
justify-content: center;
10+
align-items: center;
11+
}
12+
13+
.node-label {
14+
font-size: 12px;
15+
padding: 1px 4px;
16+
border-radius: 4px;
17+
background-color: rgba(0, 0, 0, 0.5);
18+
user-select: none;
19+
}

chronos_npm_package/server/data.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
size,path
2+
,default
3+
,default/service-backend
4+
,default/service-backend/pod
5+
,default/service-frontend
6+
,default/service-frontend/pod1
7+
,default/service-frontend/pod2
8+
,default/service-grafana
9+
,default/service-grafana/pod
10+
,default/service-kubernetes
11+
,default/service-kubernetes/pod
12+
,default/service-prometheus
13+
,default/service-prometheus/pod
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const { Parser } = require('@json2csv/plainjs');
2+
const fs = require('fs');
3+
const { convertArrayToCSV } = require('convert-array-to-csv');
4+
const converter = require('convert-array-to-csv');
5+
6+
const fileControllers = {};
7+
8+
fileControllers.saveCSV = (req, res, next) => {
9+
console.log('saveCSV endpoint hit');
10+
const data = res.locals.data;
11+
12+
try {
13+
// const parser = new Parser();
14+
// const csv = parser.parse(data);
15+
const csv = convertArrayToCSV(data);
16+
console.log(csv);
17+
18+
fs.writeFile('./output.csv', csv, (err) => {
19+
if (err) {
20+
console.log('error: ', err);
21+
return res.status(500).send('Error');
22+
}
23+
console.log('data saved');
24+
next();
25+
26+
})
27+
} catch (err) {
28+
console.log('error: ', err);
29+
return next(err);
30+
};
31+
}
32+
33+
34+
35+
module.exports = fileControllers;

0 commit comments

Comments
 (0)