Browse Source

System info: Hastic instance name (#558)

pull/1/head
Evgeny Smyshlyaev 6 years ago committed by rozetko
parent
commit
0fcee80dcf
  1. 1
      server/src/config.ts
  2. 3
      server/src/index.ts
  3. 4
      server/src/services/notification_service.ts
  4. 13
      tools/prometheus-hastic-exporter/prometheus-hastic-exporter.py

1
server/src/config.ts

@ -35,6 +35,7 @@ export const INSIDE_DOCKER = process.env.INSIDE_DOCKER !== undefined;
export const PRODUCTION_MODE = process.env.NODE_ENV !== 'development'; export const PRODUCTION_MODE = process.env.NODE_ENV !== 'development';
export const ZMQ_CONNECTION_STRING = createZMQConnectionString(); export const ZMQ_CONNECTION_STRING = createZMQConnectionString();
export const HASTIC_INSTANCE_NAME = getConfigField('HASTIC_INSTANCE_NAME', os.hostname());
function getConfigField(field: string, defaultVal?: any) { function getConfigField(field: string, defaultVal?: any) {

3
server/src/index.ts

@ -6,7 +6,7 @@ import * as AnalyticsController from './controllers/analytics_controller';
import * as ProcessService from './services/process_service'; import * as ProcessService from './services/process_service';
import { HASTIC_PORT, PACKAGE_VERSION, GIT_INFO, ZMQ_CONNECTION_STRING } from './config'; import { HASTIC_PORT, PACKAGE_VERSION, GIT_INFO, ZMQ_CONNECTION_STRING, HASTIC_INSTANCE_NAME } from './config';
import { convertPanelUrlToPanelId } from './migrations/0.3.2-beta'; import { convertPanelUrlToPanelId } from './migrations/0.3.2-beta';
@ -66,6 +66,7 @@ async function init() {
lastAlive: AnalyticsController.analyticsLastAlive(), lastAlive: AnalyticsController.analyticsLastAlive(),
tasksQueueLength: AnalyticsController.getQueueLength() tasksQueueLength: AnalyticsController.getQueueLength()
}, },
instanceName: HASTIC_INSTANCE_NAME,
awaitedTasksNumber: AnalyticsController.getTaskResolversLength(), awaitedTasksNumber: AnalyticsController.getTaskResolversLength(),
detectionsCount: AnalyticsController.getDetectionsCount(), detectionsCount: AnalyticsController.getDetectionsCount(),
nodeVersion: process.version, nodeVersion: process.version,

4
server/src/services/notification_service.ts

@ -1,6 +1,6 @@
import { Segment } from '../models/segment_model'; import { Segment } from '../models/segment_model';
import * as AnalyticUnit from '../models/analytic_unit_model'; import * as AnalyticUnit from '../models/analytic_unit_model';
import { HASTIC_WEBHOOK_URL, HASTIC_WEBHOOK_TYPE, HASTIC_WEBHOOK_SECRET } from '../config'; import { HASTIC_WEBHOOK_URL, HASTIC_WEBHOOK_TYPE, HASTIC_WEBHOOK_SECRET, HASTIC_INSTANCE_NAME } from '../config';
import axios from 'axios'; import axios from 'axios';
import * as querystring from 'querystring'; import * as querystring from 'querystring';
@ -68,6 +68,8 @@ export async function sendWebhook(payload: any, contentType = HASTIC_WEBHOOK_TYP
throw new Error(`Can't send alert, HASTIC_WEBHOOK_URL is undefined`); throw new Error(`Can't send alert, HASTIC_WEBHOOK_URL is undefined`);
} }
payload.instanceName = HASTIC_INSTANCE_NAME;
// TODO: use HASTIC_WEBHOOK_SECRET // TODO: use HASTIC_WEBHOOK_SECRET
const options = { const options = {
method: 'POST', method: 'POST',

13
tools/prometheus-hastic-exporter/prometheus-hastic-exporter.py

@ -21,9 +21,16 @@ class JsonCollector(object):
print('got exception, skip polling loop {}'.format(e)) print('got exception, skip polling loop {}'.format(e))
return return
commitHash = response.get('git', {}).get('commitHash') labels_values = {
packageVersion = response.get('packageVersion') 'commitHash': response.get('git', {}).get('commitHash'),
labels={'commitHash': commitHash, 'packageVersion': packageVersion} 'packageVersion': response.get('packageVersion'),
'instanceName': response.get('instanceName1')
}
labels = {}
for k, v in labels_values.items():
if v is not None:
labels[k] = v
metrics = { metrics = {
'activeWebhooks': response.get('activeWebhooks'), 'activeWebhooks': response.get('activeWebhooks'),

Loading…
Cancel
Save