Skip to content

Commit e6e8f3d

Browse files
committed
merge
Merge branch 'dev' into front_test_with_chronos_tranck
2 parents 1e40949 + 4a71046 commit e6e8f3d

File tree

5 files changed

+109
-58
lines changed

5 files changed

+109
-58
lines changed

chronos_npm_package/controllers/healthHelpers.js

+87-16
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,57 @@ healthHelpers.collectHealthData = () => {
1313
// for use with every object
1414
const time = Date.now();
1515
// Fill the array of promises
16+
promises.push(
17+
si
18+
.cpu()
19+
.then(data => ({
20+
speed_in_GHz: data.speed,
21+
speedMax_in_GHz: data.speedMax,
22+
num_of_cores: data.cores,
23+
num_of_processors: data.processors,
24+
'cache.l1d in bytes': data.cache.l1d,
25+
'cache.l1i in bytes': data.cache.l1i,
26+
'cache.l2 in bytes': data.cache.l2,
27+
'cache.l3 in bytes': data.cache.l3,
28+
}))
29+
.then(data => {
30+
const cpuMetrics = [];
31+
for (const metric in data) {
32+
cpuMetrics.push({
33+
metric,
34+
value: data[metric],
35+
category: 'CPU',
36+
time,
37+
});
38+
}
39+
return cpuMetrics;
40+
})
41+
.catch(err => {
42+
if (err) {
43+
throw err;
44+
}
45+
})
46+
);
1647
promises.push(
1748
si
1849
.cpuCurrentspeed()
1950
.then(data => ({
20-
metric: 'cpuspeed',
21-
value: data.avg,
22-
category: 'CPU',
23-
time,
51+
average_CPU_speed_in_GHz: data.avg,
52+
minimum_CPU_speed_in_GHz: data.min,
53+
maximum_CPU_speed_in_GHz: data.max,
2454
}))
55+
.then(data => {
56+
const cpuSpeedMetrics = [];
57+
for (const metric in data) {
58+
cpuSpeedMetrics.push({
59+
metric,
60+
value: data[metric],
61+
category: 'CPU',
62+
time,
63+
});
64+
}
65+
return cpuSpeedMetrics;
66+
})
2567
.catch(err => {
2668
if (err) {
2769
throw err;
@@ -33,11 +75,21 @@ healthHelpers.collectHealthData = () => {
3375
si
3476
.cpuTemperature()
3577
.then(data => ({
36-
metric: 'cputemp',
37-
value: data.main,
38-
category: 'CPU',
39-
time,
78+
average_temperature: data.main,
79+
max_temperature: data.max,
4080
}))
81+
.then(data => {
82+
const cpuTemperatureMetrics = [];
83+
for (const metric in data) {
84+
cpuTemperatureMetrics.push({
85+
metric,
86+
value: data[metric],
87+
category: 'CPU',
88+
time,
89+
});
90+
}
91+
return cpuTemperatureMetrics;
92+
})
4193
.catch(err => {
4294
if (err) {
4395
throw err;
@@ -49,11 +101,26 @@ healthHelpers.collectHealthData = () => {
49101
si
50102
.currentLoad()
51103
.then(data => ({
52-
metric: 'cpuloadpercent',
53-
value: data.currentload,
54-
category: 'CPU',
55-
time,
104+
average_CPU_load_percent: data.avg,
105+
current_CPU_load_percent: data.currentLoad,
106+
current_CPU_load_user_percent: data.currentLoadUser,
107+
current_CPU_load__system_percent: data.currentLoadSystem,
108+
current_CPU_load_nice_percent: data.currentLoadNice,
109+
current_CPU_load_idle_percent: data.currentLoadIdle,
110+
current_CPU_load_raw_ticks: data.rawCurrentLoad,
56111
}))
112+
.then(data => {
113+
const cpuLoadMetrics = [];
114+
for (const metric in data) {
115+
cpuLoadMetrics.push({
116+
metric,
117+
value: data[metric],
118+
category: 'CPU',
119+
time,
120+
});
121+
}
122+
return cpuLoadMetrics;
123+
})
57124
.catch(err => {
58125
throw err;
59126
})
@@ -63,10 +130,12 @@ healthHelpers.collectHealthData = () => {
63130
si
64131
.mem()
65132
.then(data => ({
66-
totalmemory: data.total,
67-
freememory: data.free,
68-
usedmemory: data.used,
69-
activememory: data.active,
133+
totalmemory_in_bytes: data.total,
134+
freememory_in_bytes: data.free,
135+
usedmemory_in_bytes: data.used,
136+
activememory_in_bytes: data.active,
137+
buffers_plus_cache_in_bytes: data.buffcache,
138+
available_memory: data.available,
70139
}))
71140
.then(data => {
72141
const memMetrics = [];
@@ -87,6 +156,8 @@ healthHelpers.collectHealthData = () => {
87156
})
88157
);
89158

159+
160+
90161
promises.push(
91162
si
92163
.processes()

chronos_npm_package/controllers/mongo.js

+9
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ chronos.health = ({ microservice, interval }) => {
110110
setInterval(() => {
111111
collectHealthData()
112112
.then(healthMetrics => {
113+
console.log('HEALTH METRICS: ', healthMetrics);
113114
const HealthModel = HealthModelFunc(`${microservice}`);
114115
return HealthModel.insertMany(healthMetrics);
115116
})
@@ -217,6 +218,14 @@ It then takes the returned array of metrics, turns them into documents based on
217218
KafkaModel.js, and inserts them into the db at the provided uri with insertMany()
218219
*/
219220
chronos.kafka = function (userConfig) {
221+
// ensure that kafkametrics exists in the services table
222+
const service = new ServicesModel({ service: 'kafkametrics', interval: userConfig.interval });
223+
224+
service
225+
.save()
226+
.then(() => console.log(`Adding "kafkametrics" to the services table`))
227+
.catch(err => console.log(`Error saving "kafkametrics" to the services table: `, err.message));
228+
220229
// fetch the data from Kafka with kafkaFetch()
221230
// then take turn each result in the returned array into a kafkaModel doc
222231
// insertMany into the the KafkaModel

chronos_npm_package/controllers/postgres.js

+2
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ chronos.docker = function ({ microservice, interval }) {
298298
};
299299

300300
chronos.kafka = function (userConfig) {
301+
// Ensure that kafkametrics are a part of the services table
302+
chronos.services({ microservice: 'kafkametrics', interval: userConfig.interval });
301303
// create kafkametrics table if it does not exist
302304
const createTableQuery = `
303305
CREATE TABLE IF NOT EXISTS kafkametrics (

electron/routes/data.ts

+4-39
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import DockerModelFunc from '../models/DockerModel';
1212
import KafkaModel from '../models/KafkaModel';
1313
import fetch, { FetchError } from 'electron-fetch';
1414
import { lightWhite } from 'material-ui/styles/colors';
15-
import {fetchData} from './dataHelpers';
15+
//import { postgresFetch, mongoFetch } from './dataHelpers';
16+
import { fetchData } from './dataHelpers';
1617

17-
const postgresFetch = fetchData.postgresFetch;
1818
const mongoFetch = fetchData.mongoFetch;
19+
const postgresFetch = fetchData.postgresFetch;
1920

2021
require('dotenv').config();
2122
console.log('test console log work');
@@ -133,48 +134,12 @@ ipcMain.on('healthRequest', async (message: Electron.IpcMainEvent, service: stri
133134

134135
// Mongo Database
135136
if (currentDatabaseType === 'MongoDB') {
136-
// // Get document count
137-
let num = await HealthModelFunc(service).countDocuments({});
138-
// Get last 50 documents. If less than 50 documents, get all
139-
num = Math.max(num, 10);
140-
result = await HealthModelFunc(service)
141-
.find(
142-
{},
143-
{
144-
cpuspeed: 1,
145-
cputemp: 1,
146-
cpuloadpercent: 1,
147-
totalmemory: 1,
148-
freememory: 1,
149-
usedmemory: 1,
150-
activememory: 1,
151-
totalprocesses: 1,
152-
runningprocesses: 1,
153-
blockedprocesses: 1,
154-
sleepingprocesses: 1,
155-
latency: 1,
156-
time: 1,
157-
__v: 1,
158-
service,
159-
}
160-
)
161-
.skip(num - 50);
162-
137+
result = await mongoFetch(service);
163138
}
164139

165-
/**
166-
* `
167-
SELECT *, 'customers' as service FROM customers
168-
ORDER BY _id DESC
169-
LIMIT 50
170-
`;
171-
*
172-
*/
173-
174140
// SQL Database
175141
if (currentDatabaseType === 'SQL') {
176142
// Get last 50 documents. If less than 50 get all
177-
178143
result = await postgresFetch(service, pool);
179144
console.log("result-health in data.ts:", JSON.stringify(result));
180145
}

electron/routes/dataHelpers.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ const aggregator = [
2626
// TCreate a model based on the serviceName
2727
// Create an aggregator based on the aggregator variable
2828
// return the result
29-
fetchData.mongoFetch = function (serviceName) {
30-
29+
fetchData.mongoFetch = async function (serviceName) {
30+
const testModel = HealthModelFunc(serviceName);
31+
let result = await testModel.aggregate(aggregator);
32+
result = [{ [serviceName]: result }];
33+
return result;
3134
};
3235

3336
fetchData.postgresFetch = async function (serviceName, pool) {
@@ -57,4 +60,5 @@ fetchData.postgresFetch = async function (serviceName, pool) {
5760
return result;
5861
};
5962

60-
export {fetchData};
63+
export { fetchData };
64+

0 commit comments

Comments
 (0)