@nsshunt/stsappframework 3.1.52 → 3.1.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/influxdb/influxDBManager.js +0 -661
- package/dist/influxdb/influxDBManager.js.map +1 -1
- package/dist/influxdb/influxDBManagerAgent.js +0 -108
- package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
- package/dist/influxdb/influxDBManagerBase.js +0 -57
- package/dist/influxdb/influxDBManagerBase.js.map +1 -1
- package/dist/influxdb/influxDBManagerService.js +0 -14
- package/dist/influxdb/influxDBManagerService.js.map +1 -1
- package/package.json +1 -1
- package/src/influxdb/influxDBManager.ts +0 -669
- package/src/influxdb/influxDBManagerAgent.ts +1 -271
- package/src/influxdb/influxDBManagerBase.ts +0 -65
- package/src/influxdb/influxDBManagerService.ts +1 -296
- package/types/influxdb/influxDBManager.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerAgent.d.ts +0 -1
- package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerBase.d.ts +0 -4
- package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerService.d.ts +0 -1
- package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
|
@@ -1,124 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
// https://www.influxdata.com/blog/tldr-influxdb-tech-tips-multiple-aggregations-yield-flux/
|
|
3
|
-
// https://www.influxdata.com/blog/top-5-hurdles-for-intermediate-flux-users-and-resources-for-optimizing-flux/
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
option task = {name: "task-sts-agent-stats", every: 1s}
|
|
7
|
-
|
|
8
|
-
data =
|
|
9
|
-
from(bucket: "TestBucket01")
|
|
10
|
-
|> range(start: -5s)
|
|
11
|
-
|> last()
|
|
12
|
-
|> filter(fn: (r) => r["_measurement"] == "agent")
|
|
13
|
-
|
|
14
|
-
r1 =
|
|
15
|
-
data
|
|
16
|
-
|> filter(fn: (r) => r["_field"] == "requestCount"
|
|
17
|
-
or r["_field"] == "errorCount"
|
|
18
|
-
or r["_field"] == "retryCount"
|
|
19
|
-
or r["_field"] == "authenticationCount"
|
|
20
|
-
or r["_field"] == "authenticationErrorCount"
|
|
21
|
-
or r["_field"] == "authenticationRetryCount"
|
|
22
|
-
or r["_field"] == "activeRequestCount"
|
|
23
|
-
or r["_field"] == "coreCount"
|
|
24
|
-
or r["_field"] == "velocity"
|
|
25
|
-
or r["_field"] == "rx"
|
|
26
|
-
or r["_field"] == "tx"
|
|
27
|
-
or r["_field"] == "childCount"
|
|
28
|
-
or r["_field"] == "timer")
|
|
29
|
-
|
|
30
|
-
r2 =
|
|
31
|
-
data
|
|
32
|
-
|> filter(fn: (r) => float(v: r["_value"]) > 0.0 and (r["_field"] == "duration"
|
|
33
|
-
or r["_field"] == "latency"))
|
|
34
|
-
|
|
35
|
-
byagentthreadasyncunnersum =
|
|
36
|
-
r1
|
|
37
|
-
|> group(columns: ["agentName", "threadId", "asyncRunnerId", "_field"])
|
|
38
|
-
|> sum()
|
|
39
|
-
|> toFloat()
|
|
40
|
-
|
|
41
|
-
byagentthreadasyncunnermean =
|
|
42
|
-
r2
|
|
43
|
-
|> group(columns: ["agentName", "threadId", "asyncRunnerId", "_field"])
|
|
44
|
-
|> mean()
|
|
45
|
-
|> toFloat()
|
|
46
|
-
|
|
47
|
-
union(tables: [byagentthreadasyncunnersum, byagentthreadasyncunnermean])
|
|
48
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-by-agentthreadasyncunner"}))
|
|
49
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
50
|
-
|
|
51
|
-
byagentthreadsum =
|
|
52
|
-
r1
|
|
53
|
-
|> group(columns: ["agentName", "threadId", "_field"])
|
|
54
|
-
|> sum()
|
|
55
|
-
|> toFloat()
|
|
56
|
-
|
|
57
|
-
byagentthreadmean =
|
|
58
|
-
r2
|
|
59
|
-
|> group(columns: ["agentName", "threadId", "_field"])
|
|
60
|
-
|> mean()
|
|
61
|
-
|> toFloat()
|
|
62
|
-
|
|
63
|
-
union(tables: [byagentthreadsum, byagentthreadmean])
|
|
64
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-by-agentthread"}))
|
|
65
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
66
|
-
|
|
67
|
-
byagentsum =
|
|
68
|
-
r1
|
|
69
|
-
|> group(columns: ["agentName", "_field"])
|
|
70
|
-
|> sum()
|
|
71
|
-
|> toFloat()
|
|
72
|
-
|
|
73
|
-
byagentmean =
|
|
74
|
-
r2
|
|
75
|
-
|> group(columns: ["agentName", "_field"])
|
|
76
|
-
|> mean()
|
|
77
|
-
|> toFloat()
|
|
78
|
-
|
|
79
|
-
union(tables: [byagentsum, byagentmean])
|
|
80
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-by-agent"}))
|
|
81
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
82
|
-
|
|
83
|
-
globalagentsum =
|
|
84
|
-
r1
|
|
85
|
-
|> group(columns: ["_field"])
|
|
86
|
-
|> sum()
|
|
87
|
-
|> toFloat()
|
|
88
|
-
|
|
89
|
-
globalagentmean =
|
|
90
|
-
r2
|
|
91
|
-
|> group(columns: ["_field"])
|
|
92
|
-
|> mean()
|
|
93
|
-
|> toFloat()
|
|
94
|
-
|
|
95
|
-
union(tables: [globalagentsum, globalagentmean])
|
|
96
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-globalagent"}))
|
|
97
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
import debugModule from 'debug'
|
|
102
|
-
const debug = debugModule(`proc:${process.pid}`);
|
|
103
|
-
|
|
104
|
-
import { Point, WriteApi, QueryApi } from '@influxdata/influxdb-client'
|
|
105
|
-
|
|
106
|
-
import { Gauge, InstrumentVelocity } from '@nsshunt/stsinstrumentation'
|
|
107
|
-
|
|
1
|
+
import { QueryApi } from '@influxdata/influxdb-client'
|
|
108
2
|
import { InfluxDBManagerBase } from './influxDBManagerBase'
|
|
109
|
-
|
|
110
3
|
import { IInfluxDBManagerOptions } from './../commonTypes'
|
|
111
|
-
import { ISubscriptionPayload, ISubscriptionKey } from '@nsshunt/stssocketio-client'
|
|
112
|
-
import { IInstrumentPayload } from '@nsshunt/stspublisherserver'
|
|
113
|
-
|
|
114
|
-
import chalk from 'chalk';
|
|
115
|
-
|
|
116
|
-
const AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER = "sts-stats-by-agentthreadasyncunner";
|
|
117
|
-
const AGENT_STATS_BY_AGENT_THREAD = "sts-stats-by-agentthread";
|
|
118
|
-
const AGENT_STATS_BY_AGENT = "sts-stats-by-agent";
|
|
119
|
-
const AGENT_STATS_GLOBALAGENT = "sts-stats-globalagent";
|
|
120
|
-
|
|
121
|
-
const _logPrefix = 'InfluxDBManagerService:'
|
|
122
4
|
|
|
123
5
|
export class InfluxDBManagerAgent extends InfluxDBManagerBase
|
|
124
6
|
{
|
|
@@ -129,156 +11,4 @@ export class InfluxDBManagerAgent extends InfluxDBManagerBase
|
|
|
129
11
|
override get modelType(): string {
|
|
130
12
|
return 'agent'
|
|
131
13
|
}
|
|
132
|
-
|
|
133
|
-
/*
|
|
134
|
-
|
|
135
|
-
#LogErrorMessage(message: any) {
|
|
136
|
-
this.options.logger.error(message);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
#LogDebugMessage(message: any) {
|
|
140
|
-
this.options.logger.debug(message);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Queries --------------------------------------------------------------------------------------------------------
|
|
144
|
-
|
|
145
|
-
// Counter metrics
|
|
146
|
-
#GetSTSCountGenericAgent = async (measurement: string, filterClause: string, showOutput: boolean = false) => {
|
|
147
|
-
try {
|
|
148
|
-
const query = `from(bucket: "${this.options.bucket}")
|
|
149
|
-
|> range(start: -5s)
|
|
150
|
-
|> last()
|
|
151
|
-
|> filter(fn: (r) => r["_measurement"] == "${measurement}" ${filterClause})`;
|
|
152
|
-
|
|
153
|
-
if (showOutput) {
|
|
154
|
-
this.#LogDebugMessage(`GetSTSCountGenericAgent(): query: [${query}]`);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return this.queryApi.collectRows(query)
|
|
158
|
-
} catch (error) {
|
|
159
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}#GetSTSCountGeneric: Error: [${error}]`));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Histo metrics
|
|
164
|
-
#GetSTSHistoGenericService = async (measurement: string, filterClause: string): Promise<any> => {
|
|
165
|
-
try {
|
|
166
|
-
const query = `import "math"
|
|
167
|
-
from(bucket: "${this.options.bucket}")
|
|
168
|
-
|> range(start: -10m)
|
|
169
|
-
|> filter(fn: (r) => r["_measurement"] == "${measurement}" and (r["_field"] =="latency"
|
|
170
|
-
or r["_field"] =="duration") ${filterClause})
|
|
171
|
-
|> histogram(bins: [0.0, 10.0, 20.0, 50.0, 100.0, 1000.0, 50000.0, math.mInf(sign: 1) ])
|
|
172
|
-
|> difference()`;
|
|
173
|
-
return this.queryApi.collectRows(query)
|
|
174
|
-
} catch (error) {
|
|
175
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}#GetSTSHistoGeneric: Error: [${error}]`));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Quantile metrics
|
|
180
|
-
#GetSTSQuantileGenericAgent = async (measurement: string, filterClause: string) => {
|
|
181
|
-
try {
|
|
182
|
-
const query = `data = from(bucket: "${this.options.bucket}")
|
|
183
|
-
|> range(start: -10m)
|
|
184
|
-
|> filter(fn: (r) => r["_measurement"] == "${measurement}" and (r["_field"] == "latency"
|
|
185
|
-
or r["_field"] == "duration") ${filterClause})
|
|
186
|
-
|> aggregateWindow(every: 5s, fn: max, createEmpty: false)
|
|
187
|
-
|
|
188
|
-
dostsquantileex = (q) =>
|
|
189
|
-
data
|
|
190
|
-
|> quantile(q: q, method: "estimate_tdigest", compression: 1000.0)
|
|
191
|
-
|> set(key: "quantile", value: string(v:q))
|
|
192
|
-
|> group(columns: ["quantile"])
|
|
193
|
-
|
|
194
|
-
union(tables: [
|
|
195
|
-
dostsquantileex(q: 0.5),
|
|
196
|
-
dostsquantileex(q: 0.8),
|
|
197
|
-
dostsquantileex(q: 0.9),
|
|
198
|
-
dostsquantileex(q: 0.95),
|
|
199
|
-
dostsquantileex(q: 0.99)
|
|
200
|
-
])`;
|
|
201
|
-
|
|
202
|
-
return this.queryApi.collectRows(query)
|
|
203
|
-
} catch (error) {
|
|
204
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}#GetSTSQuantileGeneric: Error: [${error}]`));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Metric queries -------------------------------------------------------------------------------------------------
|
|
209
|
-
// Root level metrics
|
|
210
|
-
async GetInfluxDBResultsRootAgent(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> { // ISubscriptionPayload
|
|
211
|
-
let retVal = null;
|
|
212
|
-
try {
|
|
213
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
214
|
-
this.#GetSTSCountGenericAgent(AGENT_STATS_GLOBALAGENT, ''),
|
|
215
|
-
this.#GetSTSQuantileGenericAgent(AGENT_STATS_GLOBALAGENT, ''),
|
|
216
|
-
this.#GetSTSHistoGenericService(AGENT_STATS_GLOBALAGENT, '')],
|
|
217
|
-
[ ])
|
|
218
|
-
} catch (error) {
|
|
219
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}GetInfluxDBResultsRootAgent: Error: [${error}]`));
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
subscriptionKey,
|
|
223
|
-
data: retVal
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Service level metrics
|
|
228
|
-
async GetInfluxDBResultsAgent(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
229
|
-
let retVal = null;
|
|
230
|
-
try {
|
|
231
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
232
|
-
this.#GetSTSCountGenericAgent(AGENT_STATS_BY_AGENT, ''),
|
|
233
|
-
this.#GetSTSQuantileGenericAgent(AGENT_STATS_BY_AGENT, ''),
|
|
234
|
-
this.#GetSTSHistoGenericService(AGENT_STATS_BY_AGENT, '')],
|
|
235
|
-
['agentName'])
|
|
236
|
-
} catch (error) {
|
|
237
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}GetInfluxDBResultsAgent: Error: [${error}]`));
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
subscriptionKey,
|
|
241
|
-
data: retVal
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Service instance metrics for a particular service type
|
|
246
|
-
async GetInfluxDBResultsAgentThreads(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
247
|
-
let retVal = null;
|
|
248
|
-
try {
|
|
249
|
-
const agentName = subscriptionKey.key as string;
|
|
250
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
251
|
-
this.#GetSTSCountGenericAgent(AGENT_STATS_BY_AGENT_THREAD, `and r["agentName"] == "${agentName}"`),
|
|
252
|
-
this.#GetSTSQuantileGenericAgent(AGENT_STATS_BY_AGENT_THREAD, `and r["agentName"] == "${agentName}"`),
|
|
253
|
-
this.#GetSTSHistoGenericService(AGENT_STATS_BY_AGENT_THREAD, `and r["agentName"] == "${agentName}"`)],
|
|
254
|
-
['agentName', 'threadId'])
|
|
255
|
-
} catch (error) {
|
|
256
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}GetInfluxDBResultsAgentThreads: Error: [${error}]`));
|
|
257
|
-
}
|
|
258
|
-
return {
|
|
259
|
-
subscriptionKey,
|
|
260
|
-
data: retVal
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Service instance thread metrics for a particular service instance
|
|
265
|
-
async GetInfluxDBResultsAgentThread(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
266
|
-
let retVal = null;
|
|
267
|
-
try {
|
|
268
|
-
const agentName = subscriptionKey.key as string;
|
|
269
|
-
const threadId = subscriptionKey.subkey as string;
|
|
270
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
271
|
-
this.#GetSTSCountGenericAgent(AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER, `and r["agentName"] == "${agentName}" and r["threadId"] == "${threadId}"`),
|
|
272
|
-
this.#GetSTSQuantileGenericAgent(AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER, `and r["agentName"] == "${agentName}" and r["threadId"] == "${threadId}"`),
|
|
273
|
-
this.#GetSTSHistoGenericService(AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER, `and r["agentName"] == "${agentName}" and r["threadId"] == "${threadId}"`)],
|
|
274
|
-
['agentName', 'threadId', 'asyncRunnerId'])
|
|
275
|
-
} catch (error) {
|
|
276
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}GetInfluxDBResultsAgentThread: Error: [${error}]`));
|
|
277
|
-
}
|
|
278
|
-
return {
|
|
279
|
-
subscriptionKey,
|
|
280
|
-
data: retVal
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
*/
|
|
284
14
|
}
|
|
@@ -6,8 +6,6 @@ import { Point, WriteApi, QueryApi } from '@influxdata/influxdb-client'
|
|
|
6
6
|
import { IInfluxDBManagerOptions } from './../commonTypes'
|
|
7
7
|
import { IInstrumentPayload } from '@nsshunt/stspublisherserver'
|
|
8
8
|
|
|
9
|
-
import { JSONObject } from '@nsshunt/stsutils'
|
|
10
|
-
|
|
11
9
|
import chalk from 'chalk';
|
|
12
10
|
|
|
13
11
|
import { globalServiceDefinitions, IServiceDefinition, IFieldRecord, influxDBDataType } from './../globalServiceDefinitions'
|
|
@@ -47,69 +45,6 @@ export class InfluxDBManagerBase
|
|
|
47
45
|
throw new Error('modelType(): Must override in sub-class')
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
// Helpers --------------------------------------------------------------------------------------------------------
|
|
51
|
-
async ProcessInfluxDBResults(promArray: Promise<any>[], fields: string[]) {
|
|
52
|
-
try {
|
|
53
|
-
const promRetVal: any[] = await Promise.all(promArray).catch(error => {
|
|
54
|
-
this.#LogErrorMessage(chalk.red(`InfluxDBManagerBase:ProcessInfluxDBResults(): Error: [${error}]`));
|
|
55
|
-
}) as any[];
|
|
56
|
-
|
|
57
|
-
const combinedResults: any = { };
|
|
58
|
-
|
|
59
|
-
if (promRetVal) {
|
|
60
|
-
const stscount: any[] = promRetVal[0];
|
|
61
|
-
const stsquantile: any[] = promRetVal[1];
|
|
62
|
-
const stshisto: any[] = promRetVal[2];
|
|
63
|
-
|
|
64
|
-
stscount.forEach((countRecord) => {
|
|
65
|
-
const values: any[] = fields.map(field => countRecord[field])
|
|
66
|
-
const { _field, _value } = countRecord;
|
|
67
|
-
this.CreateNestedObject(combinedResults, values)[_field] = _value;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
stsquantile.forEach((stsquantileRecord) => {
|
|
71
|
-
const values: any[] = fields.map(field => stsquantileRecord[field])
|
|
72
|
-
const { _field, quantile, _value} = stsquantileRecord;
|
|
73
|
-
const useField = _field + '_quantile'
|
|
74
|
-
this.CreateNestedObject(combinedResults, [...values, useField])[quantile] = _value;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
stshisto.forEach((stshistoRecord) => {
|
|
78
|
-
const values: any[] = fields.map(field => stshistoRecord[field])
|
|
79
|
-
const { _field, le, _value} = stshistoRecord;
|
|
80
|
-
const useField = _field + '_histo'
|
|
81
|
-
this.CreateNestedObject(combinedResults, [...values, useField])[le] = _value;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return combinedResults;
|
|
85
|
-
} catch (error) {
|
|
86
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}ProcessInfluxDBResults: Error: [${error}]`));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
CreateGlobalCountModel = (stscount: any[]) => {
|
|
91
|
-
try {
|
|
92
|
-
const results: any = { };
|
|
93
|
-
stscount.forEach((o: any) => {
|
|
94
|
-
results[o._field] = o._value;
|
|
95
|
-
});
|
|
96
|
-
return results;
|
|
97
|
-
} catch (error) {
|
|
98
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}#CreateGlobalCountModel: Error: [${error}]`));
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
CreateNestedObject(combinedResults: JSONObject, keyList: string[]): JSONObject {
|
|
103
|
-
let workingObject = combinedResults;
|
|
104
|
-
keyList.forEach((key) => {
|
|
105
|
-
if (!workingObject[key]) {
|
|
106
|
-
workingObject[key] = { };
|
|
107
|
-
}
|
|
108
|
-
workingObject = workingObject[key];
|
|
109
|
-
});
|
|
110
|
-
return workingObject;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
48
|
// Agent context payload
|
|
114
49
|
// {"nid":"somehost@e58f5d75-6ff6-4e04-92a4-f2bcd722fec0-someuseragent|MainProcess|0","id":"somehost@e58f5d75-6ff6-4e04-92a4-f2bcd722fec0-someuseragent|MainProcess|0","hostName":"somehost","agentName":"e58f5d75-6ff6-4e04-92a4-f2bcd722fec0-someuseragent","threadId":"MainProcess","asyncRunnerId":"0"}
|
|
115
50
|
async OutputInfluxDB(writeApi: WriteApi, instrumentPayload: IInstrumentPayload, serviceType: string): Promise<boolean> {
|
|
@@ -1,143 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
// https://www.influxdata.com/blog/tldr-influxdb-tech-tips-multiple-aggregations-yield-flux/
|
|
3
|
-
// https://www.influxdata.com/blog/top-5-hurdles-for-intermediate-flux-users-and-resources-for-optimizing-flux/
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
option task = {
|
|
7
|
-
name: "task-sts-service-stats",
|
|
8
|
-
every: 1s,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
data =
|
|
12
|
-
from(bucket: "TestBucket01")
|
|
13
|
-
|> range(start: -5s)
|
|
14
|
-
|> last()
|
|
15
|
-
|> filter(fn: (r) => r["_measurement"] == "service" and r["_field"] != "memory")
|
|
16
|
-
|
|
17
|
-
r1 =
|
|
18
|
-
data
|
|
19
|
-
|> filter(fn: (r) => r["_field"] == "requestCount"
|
|
20
|
-
or r["_field"] == "errorCount"
|
|
21
|
-
or r["_field"] == "retryCount"
|
|
22
|
-
or r["_field"] == "authenticationCount"
|
|
23
|
-
or r["_field"] == "authenticationErrorCount"
|
|
24
|
-
or r["_field"] == "authenticationRetryCount"
|
|
25
|
-
or r["_field"] == "activeRequestCount"
|
|
26
|
-
or r["_field"] == "connectionCount"
|
|
27
|
-
or r["_field"] == "connectionPoolCount"
|
|
28
|
-
or r["_field"] == "connectionIdleCount"
|
|
29
|
-
or r["_field"] == "connectionWaitingCount"
|
|
30
|
-
or r["_field"] == "coreCount"
|
|
31
|
-
or r["_field"] == "cpu"
|
|
32
|
-
or r["_field"] == "systemcpu"
|
|
33
|
-
or r["_field"] == "velocity"
|
|
34
|
-
or r["_field"] == "timer"
|
|
35
|
-
or r["_field"] == "rx"
|
|
36
|
-
or r["_field"] == "tx")
|
|
37
|
-
|> group(columns: ["serviceId", "serviceInstanceId", "serviceInstanceProcessId", "_field"])
|
|
38
|
-
|
|
39
|
-
r2 =
|
|
40
|
-
data
|
|
41
|
-
|> filter(
|
|
42
|
-
fn: (r) =>
|
|
43
|
-
float(v: r["_value"]) > 0.0 and (r["_field"] == "duration" or r["_field"]
|
|
44
|
-
==
|
|
45
|
-
"latency"),
|
|
46
|
-
)
|
|
47
|
-
|> group(columns: ["serviceId", "serviceInstanceId", "serviceInstanceProcessId", "_field"])
|
|
48
|
-
|
|
49
|
-
serviceInstanceProcessSum =
|
|
50
|
-
r1
|
|
51
|
-
|> sum()
|
|
52
|
-
|> toFloat()
|
|
53
|
-
|
|
54
|
-
serviceInstanceProcessMean =
|
|
55
|
-
r2
|
|
56
|
-
|> mean()
|
|
57
|
-
|> toFloat()
|
|
58
|
-
|
|
59
|
-
union(tables: [serviceInstanceProcessSum, serviceInstanceProcessMean])
|
|
60
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-by-serviceinstanceprocess"}))
|
|
61
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
62
|
-
|
|
63
|
-
serviceInstanceSum =
|
|
64
|
-
r1
|
|
65
|
-
|> group(columns: ["serviceId", "serviceInstanceId", "_field"])
|
|
66
|
-
|> sum()
|
|
67
|
-
|> toFloat()
|
|
68
|
-
|
|
69
|
-
serviceInstanceMean =
|
|
70
|
-
r2
|
|
71
|
-
|> group(columns: ["serviceId", "serviceInstanceId", "_field"])
|
|
72
|
-
|> mean()
|
|
73
|
-
|> toFloat()
|
|
74
|
-
|
|
75
|
-
union(tables: [serviceInstanceSum, serviceInstanceMean])
|
|
76
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-by-serviceinstance"}))
|
|
77
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
78
|
-
|
|
79
|
-
serviceSum =
|
|
80
|
-
r1
|
|
81
|
-
|> group(columns: ["serviceId", "_field"])
|
|
82
|
-
|> sum()
|
|
83
|
-
|> toFloat()
|
|
84
|
-
|
|
85
|
-
serviceMean =
|
|
86
|
-
r2
|
|
87
|
-
|> group(columns: ["serviceId", "_field"])
|
|
88
|
-
|> mean()
|
|
89
|
-
|> toFloat()
|
|
90
|
-
|
|
91
|
-
union(tables: [serviceSum, serviceMean])
|
|
92
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-by-service"}))
|
|
93
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
94
|
-
|
|
95
|
-
globalServiceSum =
|
|
96
|
-
r1
|
|
97
|
-
|> group(columns: ["_field"])
|
|
98
|
-
|> sum()
|
|
99
|
-
|> toFloat()
|
|
100
|
-
|
|
101
|
-
globalServiceMean =
|
|
102
|
-
r2
|
|
103
|
-
|> group(columns: ["_field"])
|
|
104
|
-
|> mean()
|
|
105
|
-
|> toFloat()
|
|
106
|
-
|
|
107
|
-
union(tables: [globalServiceSum, globalServiceMean])
|
|
108
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-globalservice"}))
|
|
109
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
110
|
-
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
|
-
import { Point, WriteApi, QueryApi } from '@influxdata/influxdb-client'
|
|
114
|
-
|
|
115
|
-
import { Gauge, InstrumentVelocity } from '@nsshunt/stsinstrumentation'
|
|
116
|
-
|
|
1
|
+
import { QueryApi } from '@influxdata/influxdb-client'
|
|
117
2
|
import { InfluxDBManagerBase } from './influxDBManagerBase'
|
|
118
|
-
|
|
119
3
|
import { IInfluxDBManagerOptions } from './../commonTypes'
|
|
120
|
-
import { ISubscriptionPayload, ISubscriptionKey } from '@nsshunt/stssocketio-client'
|
|
121
|
-
import { IInstrumentPayload } from '@nsshunt/stspublisherserver'
|
|
122
|
-
|
|
123
|
-
import chalk from 'chalk';
|
|
124
|
-
|
|
125
|
-
const _logPrefix = 'InfluxDBManagerService:'
|
|
126
|
-
|
|
127
|
-
/*
|
|
128
|
-
const SERVICE_STATS_BY_SERVICE_INSTANCE_PROCESS = "sts-stats-sum-byserviceInstanceprocessid";
|
|
129
|
-
const SERVICE_STATS_BY_SERVICE_INSTANCE = "sts-stats-sum-byserviceinstance";
|
|
130
|
-
const SERVICE_STATS_BY_SERVICE = "sts-stats-sum-byservice";
|
|
131
|
-
const SERVICE_STATS_GLOBAL = "sts-stats-sum";
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
const SERVICE_STATS_BY_SERVICE_INSTANCE_PROCESS = "sts-stats-by-serviceinstanceprocess";
|
|
135
|
-
const SERVICE_STATS_BY_SERVICE_INSTANCE = "sts-stats-by-serviceinstance";
|
|
136
|
-
const SERVICE_STATS_BY_SERVICE = "sts-stats-by-service";
|
|
137
|
-
const SERVICE_STATS_GLOBAL = "sts-stats-globalservice";
|
|
138
|
-
|
|
139
|
-
import { globalServiceDefinitions, IServiceDefinition, IFieldRecord, influxDBDataType } from './../globalServiceDefinitions'
|
|
140
|
-
import { validateServiceConfig } from '@grpc/grpc-js/build/src/service-config'
|
|
141
4
|
|
|
142
5
|
export class InfluxDBManagerService extends InfluxDBManagerBase
|
|
143
6
|
{
|
|
@@ -148,162 +11,4 @@ export class InfluxDBManagerService extends InfluxDBManagerBase
|
|
|
148
11
|
override get modelType(): string {
|
|
149
12
|
return 'service'
|
|
150
13
|
}
|
|
151
|
-
|
|
152
|
-
/*
|
|
153
|
-
#LogErrorMessage(message: any) {
|
|
154
|
-
this.options.logger.error(message);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
#LogDebugMessage(message: any) {
|
|
158
|
-
this.options.logger.debug(message);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
#GetSTSCountGenericService = async (measurement: string, filterClause: string, showOutput: boolean = false): Promise<any> => {
|
|
162
|
-
try {
|
|
163
|
-
const query = `r1 = from(bucket: "${this.options.bucket}")
|
|
164
|
-
|> range(start: -5s)
|
|
165
|
-
|> last()
|
|
166
|
-
|> filter(fn: (r) => r["_measurement"] == "${measurement}" ${filterClause})
|
|
167
|
-
|
|
168
|
-
r2 = from(bucket: "${this.options.bucket}")
|
|
169
|
-
|> range(start: -5s)
|
|
170
|
-
|> last()
|
|
171
|
-
|> filter(fn: (r) => r["_measurement"] == "service" ${filterClause} and r["_field"] == "memory")
|
|
172
|
-
|
|
173
|
-
union(tables: [r1, r2])`;
|
|
174
|
-
|
|
175
|
-
if (showOutput) {
|
|
176
|
-
this.#LogDebugMessage(`InfluxDBManagerService:GetSTSCountGenericService(): query: [${query}]`);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return this.queryApi.collectRows(query)
|
|
180
|
-
} catch (error) {
|
|
181
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}#GetSTSCountGeneric: Error: [${error}]`));
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Histo metrics
|
|
186
|
-
#GetSTSHistoGenericService = async (measurement: string, filterClause: string): Promise<any> => {
|
|
187
|
-
try {
|
|
188
|
-
const query = `import "math"
|
|
189
|
-
from(bucket: "${this.options.bucket}")
|
|
190
|
-
|> range(start: -10m)
|
|
191
|
-
|> filter(fn: (r) => r["_measurement"] == "${measurement}" and (r["_field"] =="latency" or
|
|
192
|
-
r["_field"] =="duration") ${filterClause})
|
|
193
|
-
|> histogram(bins: [0.0, 10.0, 20.0, 50.0, 100.0, 1000.0, 50000.0, math.mInf(sign: 1) ])
|
|
194
|
-
|> difference()`;
|
|
195
|
-
return this.queryApi.collectRows(query)
|
|
196
|
-
} catch (error) {
|
|
197
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}#GetSTSHistoGeneric: Error: [${error}]`));
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Quantile metrics
|
|
202
|
-
#GetSTSQuantileGenericService = async (measurement: string, filterClause: string): Promise<any> => {
|
|
203
|
-
try {
|
|
204
|
-
const query = `data = from(bucket: "${this.options.bucket}")
|
|
205
|
-
|> range(start: -10m)
|
|
206
|
-
|> filter(fn: (r) => r["_measurement"] == "${measurement}" and (r["_field"] == "latency" or
|
|
207
|
-
r["_field"] == "duration" or
|
|
208
|
-
r["_field"] == "cpu" or
|
|
209
|
-
r["_field"] == "systemcpu") ${filterClause})
|
|
210
|
-
|> aggregateWindow(every: 5s, fn: max, createEmpty: false)
|
|
211
|
-
|
|
212
|
-
dostsquantileex = (q) =>
|
|
213
|
-
data
|
|
214
|
-
|> quantile(q: q, method: "estimate_tdigest", compression: 1000.0)
|
|
215
|
-
|> set(key: "quantile", value: string(v:q))
|
|
216
|
-
|> group(columns: ["quantile"])
|
|
217
|
-
|
|
218
|
-
union(tables: [
|
|
219
|
-
dostsquantileex(q: 0.5),
|
|
220
|
-
dostsquantileex(q: 0.8),
|
|
221
|
-
dostsquantileex(q: 0.9),
|
|
222
|
-
dostsquantileex(q: 0.95),
|
|
223
|
-
dostsquantileex(q: 0.99)
|
|
224
|
-
])`;
|
|
225
|
-
|
|
226
|
-
return this.queryApi.collectRows(query)
|
|
227
|
-
} catch (error) {
|
|
228
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}#GetSTSQuantileGeneric: Error: [${error}]`));
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Metric queries -------------------------------------------------------------------------------------------------
|
|
233
|
-
// Root level metrics
|
|
234
|
-
async GetInfluxDBResultsRootService(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
235
|
-
let retVal = null;
|
|
236
|
-
try {
|
|
237
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
238
|
-
this.#GetSTSCountGenericService(SERVICE_STATS_GLOBAL, ''),
|
|
239
|
-
this.#GetSTSQuantileGenericService(SERVICE_STATS_GLOBAL, ''),
|
|
240
|
-
this.#GetSTSHistoGenericService(SERVICE_STATS_GLOBAL, '')],
|
|
241
|
-
[ ])
|
|
242
|
-
} catch (error) {
|
|
243
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}GetInfluxDBResultsRoot: Error: [${error}]`));
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
subscriptionKey,
|
|
247
|
-
data: retVal
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Service level metrics
|
|
252
|
-
async GetInfluxDBResultsService(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
253
|
-
let retVal = null;
|
|
254
|
-
try {
|
|
255
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
256
|
-
this.#GetSTSCountGenericService(SERVICE_STATS_BY_SERVICE, ''),
|
|
257
|
-
this.#GetSTSQuantileGenericService(SERVICE_STATS_BY_SERVICE, ''),
|
|
258
|
-
this.#GetSTSHistoGenericService(SERVICE_STATS_BY_SERVICE, '')],
|
|
259
|
-
['serviceId'])
|
|
260
|
-
} catch (error) {
|
|
261
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}GetInfluxDBResultsService: Error: [${error}]`));
|
|
262
|
-
}
|
|
263
|
-
return {
|
|
264
|
-
subscriptionKey,
|
|
265
|
-
data: retVal
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Service instance metrics for a particular service type
|
|
271
|
-
async GetInfluxDBResultsServiceInstances(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
272
|
-
let retVal = null;
|
|
273
|
-
try {
|
|
274
|
-
const serviceId = subscriptionKey.key as string;
|
|
275
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
276
|
-
this.#GetSTSCountGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE, `and r["serviceId"] == "${serviceId}"`),
|
|
277
|
-
this.#GetSTSQuantileGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE, `and r["serviceId"] == "${serviceId}"`),
|
|
278
|
-
this.#GetSTSHistoGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE, `and r["serviceId"] == "${serviceId}"`)],
|
|
279
|
-
['serviceId', 'serviceInstanceId'])
|
|
280
|
-
} catch (error) {
|
|
281
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}GetInfluxDBResultsServiceInstances: Error: [${error}]`));
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
subscriptionKey,
|
|
285
|
-
data: retVal
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Service instance thread metrics for a particular service instance
|
|
290
|
-
async GetInfluxDBResultsServiceInstance(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
291
|
-
let retVal = null;
|
|
292
|
-
try {
|
|
293
|
-
//const serviceId = subscriptionKey.key as string; // Not required for the query
|
|
294
|
-
const serviceInstanceId = subscriptionKey.subkey as string;
|
|
295
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
296
|
-
this.#GetSTSCountGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE_PROCESS, `and r["serviceInstanceId"] == "${serviceInstanceId}"`),
|
|
297
|
-
this.#GetSTSQuantileGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE_PROCESS, `and r["serviceInstanceId"] == "${serviceInstanceId}"`),
|
|
298
|
-
this.#GetSTSHistoGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE_PROCESS, `and r["serviceInstanceId"] == "${serviceInstanceId}"`)],
|
|
299
|
-
['serviceId', 'serviceInstanceId', 'serviceInstanceProcessId'])
|
|
300
|
-
} catch (error) {
|
|
301
|
-
this.#LogErrorMessage(chalk.red(`${_logPrefix}GetInfluxDBResultsServiceInstance: Error: [${error}]`));
|
|
302
|
-
}
|
|
303
|
-
return {
|
|
304
|
-
subscriptionKey,
|
|
305
|
-
data: retVal
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
*/
|
|
309
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"influxDBManager.d.ts","sourceRoot":"","sources":["../../src/influxdb/influxDBManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,QAAQ,EAAgD,MAAM,6BAA6B,CAAA;AAQ9G,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAI1D,OAAO,EAAE,sBAAsB,EAAC,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"influxDBManager.d.ts","sourceRoot":"","sources":["../../src/influxdb/influxDBManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,QAAQ,EAAgD,MAAM,6BAA6B,CAAA;AAQ9G,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAI1D,OAAO,EAAE,sBAAsB,EAAC,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAShE,qBAAa,eAAe;;gBAiBZ,MAAM,EAAE,UAAU;IAiF9B,2BAA2B,CAAC,SAAS,EAAE,MAAM;IAgB7C,IAAI,cAAc,IAAI,sBAAsB,CAE3C;IAED,IAAI,YAAY,IAAI,oBAAoB,CAEvC;IAED,IAAI,aAAa,IAAI,qBAAqB,CAEzC;IAED,KAAK,sBAEJ;IAED,SAAS,sBA2BR;IAED,sBAAsB,aAAc,GAAG,EAAE,SAUxC;IAGD,kBAAkB,CAAC,eAAe,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU;IAW9E,IAAI,WAAW,IAAI,QAAQ,CAwG1B;IAIK,cAAc,CAAC,iBAAiB,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;CAmBhF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"influxDBManagerAgent.d.ts","sourceRoot":"","sources":["../../src/influxdb/influxDBManagerAgent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"influxDBManagerAgent.d.ts","sourceRoot":"","sources":["../../src/influxdb/influxDBManagerAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAE1D,qBAAa,oBAAqB,SAAQ,mBAAmB;gBAE7C,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,QAAQ;IAIhE,IAAa,SAAS,IAAI,MAAM,CAE/B;CACJ"}
|