@nsshunt/stsappframework 3.0.104 → 3.0.106
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 +16 -17
- package/dist/influxdb/influxDBManager.js.map +1 -1
- package/dist/influxdb/influxDBManagerAgent.js +9 -13
- package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
- package/dist/influxdb/influxDBManagerBase.js +2 -6
- package/dist/influxdb/influxDBManagerBase.js.map +1 -1
- package/dist/influxdb/influxDBManagerService.js +10 -14
- package/dist/influxdb/influxDBManagerService.js.map +1 -1
- package/dist/instrumentationsubscriber.js +11 -15
- package/dist/instrumentationsubscriber.js.map +1 -1
- package/dist/kafka/IMKafkaManager.js +2 -6
- package/dist/kafka/IMKafkaManager.js.map +1 -1
- package/dist/kafkatesting/produce.js +1 -5
- package/dist/kafkatesting/produce.js.map +1 -1
- package/dist/processbase.js +7 -8
- package/dist/processbase.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tcpclient/app2.js +2 -2
- package/dist/tcpserver/appmaster.js +39 -16
- package/dist/tcpserver/appmaster.js.map +1 -1
- package/package.json +7 -7
- package/src/influxdb/influxDBManager.ts +16 -18
- package/src/influxdb/influxDBManagerAgent.ts +9 -11
- package/src/influxdb/influxDBManagerBase.ts +2 -4
- package/src/influxdb/influxDBManagerService.ts +10 -12
- package/src/instrumentationsubscriber.ts +11 -14
- package/src/kafka/IMKafkaManager.ts +2 -4
- package/src/kafkatesting/produce.ts +1 -3
- package/src/processbase.ts +7 -9
- package/src/server.ts +1 -1
- package/src/tcpclient/app2.ts +2 -2
- package/src/tcpserver/appmaster.ts +39 -17
- package/types/influxdb/influxDBManager.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
- package/types/instrumentationsubscriber.d.ts.map +1 -1
- package/types/kafka/IMKafkaManager.d.ts.map +1 -1
- package/types/processbase.d.ts +2 -2
- package/types/processbase.d.ts.map +1 -1
- package/types/tcpserver/appmaster.d.ts.map +1 -1
- package/src_working/authDefs.ts +0 -37
- package/src_working/authutilsnode.ts +0 -373
- package/src_working/commonTypes.ts +0 -239
- package/src_working/index.ts +0 -22
- package/src_working/influxdb/influxDBManager.ts +0 -970
- package/src_working/influxdb/influxDBManagerAgent.ts +0 -314
- package/src_working/influxdb/influxDBManagerBase.ts +0 -109
- package/src_working/influxdb/influxDBManagerService.ts +0 -373
- package/src_working/instrumentationsubscriber.ts +0 -283
- package/src_working/kafka/IMKafkaManager.ts +0 -152
- package/src_working/kafka/kafkaconsumer.ts +0 -82
- package/src_working/kafka/kafkamanager.ts +0 -186
- package/src_working/kafka/kafkaproducer.ts +0 -58
- package/src_working/kafkatesting/config.ts +0 -10
- package/src_working/kafkatesting/consume.ts +0 -116
- package/src_working/kafkatesting/produce.ts +0 -153
- package/src_working/masterprocessbase.ts +0 -598
- package/src_working/middleware/serverNetworkMiddleware.ts +0 -240
- package/src_working/network.ts +0 -36
- package/src_working/processbase.ts +0 -411
- package/src_working/processoptions.ts +0 -164
- package/src_working/publishertransports/publishTransportDirect.ts +0 -45
- package/src_working/publishertransports/publishTransportUtils.ts +0 -53
- package/src_working/server.ts +0 -141
- package/src_working/serverprocessbase.ts +0 -393
- package/src_working/singleprocessbase.ts +0 -121
- package/src_working/socketIoServerHelper.ts +0 -177
- package/src_working/stscontrollerbase.ts +0 -15
- package/src_working/stslatencycontroller.ts +0 -27
- package/src_working/stslatencyroute.ts +0 -16
- package/src_working/stsrouterbase.ts +0 -22
- package/src_working/tcpclient/app.ts +0 -19
- package/src_working/tcpclient/app2.ts +0 -56
- package/src_working/tcpserver/app.ts +0 -11
- package/src_working/tcpserver/appConfig.ts +0 -65
- package/src_working/tcpserver/appmaster.ts +0 -544
- package/src_working/validation/errors.ts +0 -6
- package/src_working/webworkertesting/app.ts +0 -49
- package/src_working/webworkertesting/worker.ts +0 -24
- package/src_working/workerprocessbase.test.ts +0 -47
- package/src_working/workerprocessbase.ts +0 -185
- package/src_working2/authDefs.ts +0 -37
- package/src_working2/authutilsnode.ts +0 -375
- package/src_working2/commonTypes.ts +0 -239
- package/src_working2/index.ts +0 -22
- package/src_working2/influxdb/influxDBManager.ts +0 -972
- package/src_working2/influxdb/influxDBManagerAgent.ts +0 -316
- package/src_working2/influxdb/influxDBManagerBase.ts +0 -111
- package/src_working2/influxdb/influxDBManagerService.ts +0 -375
- package/src_working2/instrumentationsubscriber.ts +0 -286
- package/src_working2/kafka/IMKafkaManager.ts +0 -154
- package/src_working2/kafka/kafkaconsumer.ts +0 -82
- package/src_working2/kafka/kafkamanager.ts +0 -186
- package/src_working2/kafka/kafkaproducer.ts +0 -58
- package/src_working2/kafkatesting/config.ts +0 -10
- package/src_working2/kafkatesting/consume.ts +0 -116
- package/src_working2/kafkatesting/produce.ts +0 -155
- package/src_working2/masterprocessbase.ts +0 -590
- package/src_working2/middleware/serverNetworkMiddleware.ts +0 -240
- package/src_working2/network.ts +0 -36
- package/src_working2/processbase.ts +0 -415
- package/src_working2/processoptions.ts +0 -164
- package/src_working2/publishertransports/publishTransportDirect.ts +0 -45
- package/src_working2/publishertransports/publishTransportUtils.ts +0 -53
- package/src_working2/server.ts +0 -141
- package/src_working2/serverprocessbase.ts +0 -393
- package/src_working2/singleprocessbase.ts +0 -123
- package/src_working2/socketIoServerHelper.ts +0 -177
- package/src_working2/stscontrollerbase.ts +0 -15
- package/src_working2/stslatencycontroller.ts +0 -27
- package/src_working2/stslatencyroute.ts +0 -16
- package/src_working2/stsrouterbase.ts +0 -22
- package/src_working2/tcpclient/app.ts +0 -19
- package/src_working2/tcpclient/app2.ts +0 -56
- package/src_working2/tcpserver/app.ts +0 -11
- package/src_working2/tcpserver/appConfig.ts +0 -65
- package/src_working2/tcpserver/appmaster.ts +0 -522
- package/src_working2/validation/errors.ts +0 -6
- package/src_working2/webworkertesting/app.ts +0 -49
- package/src_working2/webworkertesting/worker.ts +0 -24
- package/src_working2/workerprocessbase.test.ts +0 -47
- package/src_working2/workerprocessbase.ts +0 -187
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
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"] == "activeRequestCount"
|
|
21
|
-
or r["_field"] == "coreCount"
|
|
22
|
-
or r["_field"] == "velocity"
|
|
23
|
-
or r["_field"] == "rx"
|
|
24
|
-
or r["_field"] == "tx"
|
|
25
|
-
or r["_field"] == "childCount"
|
|
26
|
-
or r["_field"] == "timer")
|
|
27
|
-
|
|
28
|
-
r2 =
|
|
29
|
-
data
|
|
30
|
-
|> filter(fn: (r) => float(v: r["_value"]) > 0.0 and (r["_field"] == "duration"
|
|
31
|
-
or r["_field"] == "latency"))
|
|
32
|
-
|
|
33
|
-
byagentthreadasyncunnersum =
|
|
34
|
-
r1
|
|
35
|
-
|> group(columns: ["agentName", "threadId", "asyncRunnerId", "_field"])
|
|
36
|
-
|> sum()
|
|
37
|
-
|> toFloat()
|
|
38
|
-
|
|
39
|
-
byagentthreadasyncunnermean =
|
|
40
|
-
r2
|
|
41
|
-
|> group(columns: ["agentName", "threadId", "asyncRunnerId", "_field"])
|
|
42
|
-
|> mean()
|
|
43
|
-
|> toFloat()
|
|
44
|
-
|
|
45
|
-
union(tables: [byagentthreadasyncunnersum, byagentthreadasyncunnermean])
|
|
46
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-by-agentthreadasyncunner"}))
|
|
47
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
48
|
-
|
|
49
|
-
byagentthreadsum =
|
|
50
|
-
r1
|
|
51
|
-
|> group(columns: ["agentName", "threadId", "_field"])
|
|
52
|
-
|> sum()
|
|
53
|
-
|> toFloat()
|
|
54
|
-
|
|
55
|
-
byagentthreadmean =
|
|
56
|
-
r2
|
|
57
|
-
|> group(columns: ["agentName", "threadId", "_field"])
|
|
58
|
-
|> mean()
|
|
59
|
-
|> toFloat()
|
|
60
|
-
|
|
61
|
-
union(tables: [byagentthreadsum, byagentthreadmean])
|
|
62
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-by-agentthread"}))
|
|
63
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
64
|
-
|
|
65
|
-
byagentsum =
|
|
66
|
-
r1
|
|
67
|
-
|> group(columns: ["agentName", "_field"])
|
|
68
|
-
|> sum()
|
|
69
|
-
|> toFloat()
|
|
70
|
-
|
|
71
|
-
byagentmean =
|
|
72
|
-
r2
|
|
73
|
-
|> group(columns: ["agentName", "_field"])
|
|
74
|
-
|> mean()
|
|
75
|
-
|> toFloat()
|
|
76
|
-
|
|
77
|
-
union(tables: [byagentsum, byagentmean])
|
|
78
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-by-agent"}))
|
|
79
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
80
|
-
|
|
81
|
-
globalagentsum =
|
|
82
|
-
r1
|
|
83
|
-
|> group(columns: ["_field"])
|
|
84
|
-
|> sum()
|
|
85
|
-
|> toFloat()
|
|
86
|
-
|
|
87
|
-
globalagentmean =
|
|
88
|
-
r2
|
|
89
|
-
|> group(columns: ["_field"])
|
|
90
|
-
|> mean()
|
|
91
|
-
|> toFloat()
|
|
92
|
-
|
|
93
|
-
union(tables: [globalagentsum, globalagentmean])
|
|
94
|
-
|> map(fn: (r) => ({r with _time: now(), _measurement: "sts-stats-globalagent"}))
|
|
95
|
-
|> to(org: "my-org", bucket: "TestBucket01")
|
|
96
|
-
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
import { Point, WriteApi, QueryApi } from '@influxdata/influxdb-client'
|
|
100
|
-
|
|
101
|
-
import { Gauge, InstrumentVelocity } from '@nsshunt/stsinstrumentation'
|
|
102
|
-
|
|
103
|
-
import { InfluxDBManagerBase } from './influxDBManagerBase'
|
|
104
|
-
|
|
105
|
-
import { IInfluxDBManagerOptions, InstrumentPayload } from './../commonTypes'
|
|
106
|
-
import { ISubscriptionPayload, ISubscriptionKey } from '@nsshunt/stssocketio-client'
|
|
107
|
-
|
|
108
|
-
import chalk from 'chalk';
|
|
109
|
-
|
|
110
|
-
const AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER = "sts-stats-by-agentthreadasyncunner";
|
|
111
|
-
const AGENT_STATS_BY_AGENT_THREAD = "sts-stats-by-agentthread";
|
|
112
|
-
const AGENT_STATS_BY_AGENT = "sts-stats-by-agent";
|
|
113
|
-
const AGENT_STATS_GLOBALAGENT = "sts-stats-globalagent";
|
|
114
|
-
|
|
115
|
-
const _logPrefix = 'InfluxDBManagerService:'
|
|
116
|
-
|
|
117
|
-
export class InfluxDBManagerAgent extends InfluxDBManagerBase
|
|
118
|
-
{
|
|
119
|
-
constructor(options: IInfluxDBManagerOptions, queryApi: QueryApi) {
|
|
120
|
-
super(options, queryApi);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
override get modelType(): string {
|
|
124
|
-
return 'agent'
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Queries --------------------------------------------------------------------------------------------------------
|
|
128
|
-
|
|
129
|
-
// Counter metrics
|
|
130
|
-
#GetSTSCountGenericAgent = async (measurement: string, filterClause: string, showOutput: boolean = false) => {
|
|
131
|
-
try {
|
|
132
|
-
const query = `from(bucket: "${this.options.bucket}")
|
|
133
|
-
|> range(start: -5s)
|
|
134
|
-
|> last()
|
|
135
|
-
|> filter(fn: (r) => r["_measurement"] == "${measurement}" ${filterClause})`;
|
|
136
|
-
|
|
137
|
-
if (showOutput) {
|
|
138
|
-
console.log(query);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return this.queryApi.collectRows(query)
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.error(chalk.red(`${_logPrefix}#GetSTSCountGeneric: Error: [${error}]`));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Histo metrics
|
|
148
|
-
#GetSTSHistoGenericService = async (measurement: string, filterClause: string): Promise<any> => {
|
|
149
|
-
try {
|
|
150
|
-
const query = `import "math"
|
|
151
|
-
from(bucket: "${this.options.bucket}")
|
|
152
|
-
|> range(start: -10m)
|
|
153
|
-
|> filter(fn: (r) => r["_measurement"] == "${measurement}" and (r["_field"] =="latency"
|
|
154
|
-
or r["_field"] =="duration") ${filterClause})
|
|
155
|
-
|> histogram(bins: [0.0, 10.0, 20.0, 50.0, 100.0, 1000.0, 50000.0, math.mInf(sign: 1) ])
|
|
156
|
-
|> difference()`;
|
|
157
|
-
return this.queryApi.collectRows(query)
|
|
158
|
-
} catch (error) {
|
|
159
|
-
console.error(chalk.red(`${_logPrefix}#GetSTSHistoGeneric: Error: [${error}]`));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Quantile metrics
|
|
164
|
-
#GetSTSQuantileGenericAgent = async (measurement: string, filterClause: string) => {
|
|
165
|
-
try {
|
|
166
|
-
const query = `data = from(bucket: "${this.options.bucket}")
|
|
167
|
-
|> range(start: -10m)
|
|
168
|
-
|> filter(fn: (r) => r["_measurement"] == "${measurement}" and (r["_field"] == "latency"
|
|
169
|
-
or r["_field"] == "duration") ${filterClause})
|
|
170
|
-
|> aggregateWindow(every: 5s, fn: max, createEmpty: false)
|
|
171
|
-
|
|
172
|
-
dostsquantileex = (q) =>
|
|
173
|
-
data
|
|
174
|
-
|> quantile(q: q, method: "estimate_tdigest", compression: 1000.0)
|
|
175
|
-
|> set(key: "quantile", value: string(v:q))
|
|
176
|
-
|> group(columns: ["quantile"])
|
|
177
|
-
|
|
178
|
-
union(tables: [
|
|
179
|
-
dostsquantileex(q: 0.5),
|
|
180
|
-
dostsquantileex(q: 0.8),
|
|
181
|
-
dostsquantileex(q: 0.9),
|
|
182
|
-
dostsquantileex(q: 0.95),
|
|
183
|
-
dostsquantileex(q: 0.99)
|
|
184
|
-
])`;
|
|
185
|
-
|
|
186
|
-
return this.queryApi.collectRows(query)
|
|
187
|
-
} catch (error) {
|
|
188
|
-
console.error(chalk.red(`${_logPrefix}#GetSTSQuantileGeneric: Error: [${error}]`));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Metric queries -------------------------------------------------------------------------------------------------
|
|
193
|
-
// Root level metrics
|
|
194
|
-
async GetInfluxDBResultsRootAgent(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> { // ISubscriptionPayload
|
|
195
|
-
let retVal = null;
|
|
196
|
-
try {
|
|
197
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
198
|
-
this.#GetSTSCountGenericAgent(AGENT_STATS_GLOBALAGENT, ''),
|
|
199
|
-
this.#GetSTSQuantileGenericAgent(AGENT_STATS_GLOBALAGENT, ''),
|
|
200
|
-
this.#GetSTSHistoGenericService(AGENT_STATS_GLOBALAGENT, '')],
|
|
201
|
-
[ ])
|
|
202
|
-
} catch (error) {
|
|
203
|
-
console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsRootAgent: Error: [${error}]`));
|
|
204
|
-
}
|
|
205
|
-
return {
|
|
206
|
-
subscriptionKey,
|
|
207
|
-
data: retVal
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Service level metrics
|
|
212
|
-
async GetInfluxDBResultsAgent(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
213
|
-
let retVal = null;
|
|
214
|
-
try {
|
|
215
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
216
|
-
this.#GetSTSCountGenericAgent(AGENT_STATS_BY_AGENT, ''),
|
|
217
|
-
this.#GetSTSQuantileGenericAgent(AGENT_STATS_BY_AGENT, ''),
|
|
218
|
-
this.#GetSTSHistoGenericService(AGENT_STATS_BY_AGENT, '')],
|
|
219
|
-
['agentName'])
|
|
220
|
-
} catch (error) {
|
|
221
|
-
console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsAgent: Error: [${error}]`));
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
subscriptionKey,
|
|
225
|
-
data: retVal
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Service instance metrics for a particular service type
|
|
230
|
-
async GetInfluxDBResultsAgentThreads(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
231
|
-
let retVal = null;
|
|
232
|
-
try {
|
|
233
|
-
const agentName = subscriptionKey.key as string;
|
|
234
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
235
|
-
this.#GetSTSCountGenericAgent(AGENT_STATS_BY_AGENT_THREAD, `and r["agentName"] == "${agentName}"`),
|
|
236
|
-
this.#GetSTSQuantileGenericAgent(AGENT_STATS_BY_AGENT_THREAD, `and r["agentName"] == "${agentName}"`),
|
|
237
|
-
this.#GetSTSHistoGenericService(AGENT_STATS_BY_AGENT_THREAD, `and r["agentName"] == "${agentName}"`)],
|
|
238
|
-
['agentName', 'threadId'])
|
|
239
|
-
} catch (error) {
|
|
240
|
-
console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsAgentThreads: Error: [${error}]`));
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
subscriptionKey,
|
|
244
|
-
data: retVal
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Service instance thread metrics for a particular service instance
|
|
249
|
-
async GetInfluxDBResultsAgentThread(subscriptionKey: ISubscriptionKey): Promise<ISubscriptionPayload> {
|
|
250
|
-
let retVal = null;
|
|
251
|
-
try {
|
|
252
|
-
const agentName = subscriptionKey.key as string;
|
|
253
|
-
const threadId = subscriptionKey.subkey as string;
|
|
254
|
-
retVal = await this.ProcessInfluxDBResults([
|
|
255
|
-
this.#GetSTSCountGenericAgent(AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER, `and r["agentName"] == "${agentName}" and r["threadId"] == "${threadId}"`),
|
|
256
|
-
this.#GetSTSQuantileGenericAgent(AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER, `and r["agentName"] == "${agentName}" and r["threadId"] == "${threadId}"`),
|
|
257
|
-
this.#GetSTSHistoGenericService(AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER, `and r["agentName"] == "${agentName}" and r["threadId"] == "${threadId}"`)],
|
|
258
|
-
['agentName', 'threadId', 'asyncRunnerId'])
|
|
259
|
-
} catch (error) {
|
|
260
|
-
console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsAgentThread: Error: [${error}]`));
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
subscriptionKey,
|
|
264
|
-
data: retVal
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// Agent context payload
|
|
269
|
-
// {"nid":"somehost@e58f5d75-6ff6-4e04-92a4-f2bcd722fec0-someuseragent|MainProcess|0","id":"somehost@e58f5d75-6ff6-4e04-92a4-f2bcd722fec0-someuseragent|MainProcess|0","hostName":"somehost"
|
|
270
|
-
// ,"agentName":"e58f5d75-6ff6-4e04-92a4-f2bcd722fec0-someuseragent","threadId":"MainProcess","asyncRunnerId":"0"}
|
|
271
|
-
async OutputInfluxDB(writeApi: WriteApi, instrumentPayload: InstrumentPayload): Promise<boolean> {
|
|
272
|
-
if (writeApi) {
|
|
273
|
-
try {
|
|
274
|
-
const { nid, id, hostName, agentName, threadId, asyncRunnerId } = instrumentPayload.context;
|
|
275
|
-
|
|
276
|
-
let systemcpu = 0.0;
|
|
277
|
-
if (instrumentPayload.instruments[Gauge.CPU_SYSTEM_LOAD_GAUGE]) {
|
|
278
|
-
systemcpu = (instrumentPayload.instruments[Gauge.CPU_SYSTEM_LOAD_GAUGE].val as number);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const point = new Point('all')
|
|
282
|
-
.measurement('agent')
|
|
283
|
-
// Context settings
|
|
284
|
-
.tag('id', id as string) // Must be unique (uuid)
|
|
285
|
-
.tag('hostName', hostName as string) // Must be unique (uuid)
|
|
286
|
-
.tag('agentName', agentName as string) // Must be unique (uuid)
|
|
287
|
-
.tag('threadId', threadId as string) // Must be unique (uuid)
|
|
288
|
-
.tag('asyncRunnerId', asyncRunnerId as string)
|
|
289
|
-
// Data fields
|
|
290
|
-
.intField('requestCount', instrumentPayload.instruments[Gauge.REQUEST_COUNT_GAUGE].val) // q
|
|
291
|
-
.intField('errorCount', instrumentPayload.instruments[Gauge.ERROR_COUNT_GAUGE].val) // j
|
|
292
|
-
.intField('retryCount', instrumentPayload.instruments[Gauge.RETRY_COUNT_GAUGE].val) // r
|
|
293
|
-
.intField('authenticationCount', instrumentPayload.instruments[Gauge.AUTHENTICATION_COUNT_GAUGE].val) // b
|
|
294
|
-
.floatField('velocity', (instrumentPayload.instruments[Gauge.VELOCITY_GAUGE] as InstrumentVelocity).va) // t - Note: Using va not val here
|
|
295
|
-
.intField('coreCount', instrumentPayload.instruments[Gauge.CORE_COUNT_GAUGE].val) // x
|
|
296
|
-
.floatField('rx', (instrumentPayload.instruments[Gauge.NETWORK_RX_GAUGE] as InstrumentVelocity).va) // Note: Using va not val here
|
|
297
|
-
.floatField('tx', (instrumentPayload.instruments[Gauge.NETWORK_TX_GAUGE] as InstrumentVelocity).va) // Note: Using va not val here
|
|
298
|
-
.floatField('timer', instrumentPayload.instruments[Gauge.TIMER_GAUGE].val) // s
|
|
299
|
-
.floatField('duration', instrumentPayload.instruments[Gauge.DURATION_GAUGE].val) // h
|
|
300
|
-
.floatField('latency', instrumentPayload.instruments[Gauge.LATENCY_GAUGE].val) // h
|
|
301
|
-
.intField('activeRequestCount', instrumentPayload.instruments[Gauge.ACTIVE_REQUEST_GAUGE].val) // a
|
|
302
|
-
.intField('childCount', instrumentPayload.instruments[Gauge.CHILD_COUNT].val) // y
|
|
303
|
-
// logger // m
|
|
304
|
-
// duration histo // i
|
|
305
|
-
writeApi.writePoint(point);
|
|
306
|
-
return true;
|
|
307
|
-
} catch (error: any) {
|
|
308
|
-
console.error(chalk.red(`${_logPrefix}OutputInfluxDBAgent: Could not write data point: [${error}]`));
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
} else {
|
|
312
|
-
console.error(chalk.red(`${_logPrefix}OutputInfluxDBAgent: Could not write data point as writeClient is null`));
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
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
|
-
import { WriteApi, QueryApi } from '@influxdata/influxdb-client'
|
|
5
|
-
|
|
6
|
-
import { IInfluxDBManagerOptions, InstrumentPayload } from './../commonTypes'
|
|
7
|
-
|
|
8
|
-
import { JSONObject } from '@nsshunt/stsutils'
|
|
9
|
-
|
|
10
|
-
import chalk from 'chalk';
|
|
11
|
-
|
|
12
|
-
const _logPrefix = 'InfluxDBManager:'
|
|
13
|
-
|
|
14
|
-
export class InfluxDBManagerBase
|
|
15
|
-
{
|
|
16
|
-
#queryApi: QueryApi;
|
|
17
|
-
#shuttingDown: boolean = false;
|
|
18
|
-
#options: IInfluxDBManagerOptions;
|
|
19
|
-
|
|
20
|
-
constructor(options: IInfluxDBManagerOptions, queryApi: QueryApi) {
|
|
21
|
-
this.#queryApi = queryApi;
|
|
22
|
-
this.#options = options;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get options() {
|
|
26
|
-
return this.#options;
|
|
27
|
-
}
|
|
28
|
-
get queryApi() {
|
|
29
|
-
return this.#queryApi;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get shuttingDown() {
|
|
33
|
-
return this.#shuttingDown;
|
|
34
|
-
}
|
|
35
|
-
set shuttingDown(val: boolean) {
|
|
36
|
-
this.#shuttingDown = val;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get modelType(): string {
|
|
40
|
-
throw new Error('modelType(): Must override in sub-class')
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Helpers --------------------------------------------------------------------------------------------------------
|
|
44
|
-
async ProcessInfluxDBResults(promArray: Promise<any>[], fields: string[]) {
|
|
45
|
-
try {
|
|
46
|
-
const promRetVal: any[] = await Promise.all(promArray).catch(error => {
|
|
47
|
-
console.error(error)
|
|
48
|
-
}) as any[];
|
|
49
|
-
|
|
50
|
-
const combinedResults: any = { };
|
|
51
|
-
|
|
52
|
-
if (promRetVal) {
|
|
53
|
-
const stscount: any[] = promRetVal[0];
|
|
54
|
-
const stsquantile: any[] = promRetVal[1];
|
|
55
|
-
const stshisto: any[] = promRetVal[2];
|
|
56
|
-
|
|
57
|
-
stscount.forEach((countRecord) => {
|
|
58
|
-
const values: any[] = fields.map(field => countRecord[field])
|
|
59
|
-
const { _field, _value } = countRecord;
|
|
60
|
-
this.CreateNestedObject(combinedResults, values)[_field] = _value;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
stsquantile.forEach((stsquantileRecord) => {
|
|
64
|
-
const values: any[] = fields.map(field => stsquantileRecord[field])
|
|
65
|
-
const { _field, quantile, _value} = stsquantileRecord;
|
|
66
|
-
const useField = _field + '_quantile'
|
|
67
|
-
this.CreateNestedObject(combinedResults, [...values, useField])[quantile] = _value;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
stshisto.forEach((stshistoRecord) => {
|
|
71
|
-
const values: any[] = fields.map(field => stshistoRecord[field])
|
|
72
|
-
const { _field, le, _value} = stshistoRecord;
|
|
73
|
-
const useField = _field + '_histo'
|
|
74
|
-
this.CreateNestedObject(combinedResults, [...values, useField])[le] = _value;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return combinedResults;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.error(chalk.red(`${_logPrefix}ProcessInfluxDBResults: Error: [${error}]`));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
CreateGlobalCountModel = (stscount: any[]) => {
|
|
84
|
-
try {
|
|
85
|
-
const results: any = { };
|
|
86
|
-
stscount.forEach((o: any) => {
|
|
87
|
-
results[o._field] = o._value;
|
|
88
|
-
});
|
|
89
|
-
return results;
|
|
90
|
-
} catch (error) {
|
|
91
|
-
console.error(chalk.red(`${_logPrefix}#CreateGlobalCountModel: Error: [${error}]`));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
CreateNestedObject(combinedResults: JSONObject, keyList: string[]): JSONObject {
|
|
96
|
-
let workingObject = combinedResults;
|
|
97
|
-
keyList.forEach((key) => {
|
|
98
|
-
if (!workingObject[key]) {
|
|
99
|
-
workingObject[key] = { };
|
|
100
|
-
}
|
|
101
|
-
workingObject = workingObject[key];
|
|
102
|
-
});
|
|
103
|
-
return workingObject;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Agent context payload
|
|
107
|
-
// {"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"}
|
|
108
|
-
async OutputInfluxDB(writeApi: WriteApi, instrumentPayload: InstrumentPayload): Promise<boolean> {
|
|
109
|
-
throw new Error('Must override in sub-class');
|
|
110
|
-
}
|
|
111
|
-
}
|