Skip to content

Commit

Permalink
Merge pull request #817 from mountaindude/815
Browse files Browse the repository at this point in the history
815
  • Loading branch information
mountaindude authored Jun 4, 2024
2 parents eba6da8 + 45312d7 commit eced8dc
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Show github.ref
run: echo "$GITHUB_REF"

- uses: google-github-actions/release-please-action@v4
- uses: googleapis/release-please-action@v4
id: release
if: github.repository_owner == 'ptarmiganlabs'
with:
Expand Down
24 changes: 22 additions & 2 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ const tagValuesLogEventLogDb = tagValues.slice();
tagValuesLogEventLogDb.push('source_process');
tagValuesLogEventLogDb.push('log_level');

// Create tags for user sessions
const tagValuesUserProxySessions = tagValues.slice();
tagValuesUserProxySessions.push('user_session_virtual_proxy');
tagValuesUserProxySessions.push('user_session_host');

// Show Influxdb config
if (config.get('Butler-SOS.influxdbConfig.enable') === true) {
logger.info(`CONFIG: Influxdb enabled: true`);
Expand Down Expand Up @@ -358,7 +363,7 @@ if (config.get('Butler-SOS.influxdbConfig.enable') === true) {

// Set up Influxdb client
let influx;
let influxWriteApi = [];
const influxWriteApi = [];
if (config.get('Butler-SOS.influxdbConfig.enable') === true) {
if (config.get('Butler-SOS.influxdbConfig.version') === 1) {
// Set up Influxdb v1 client
Expand Down Expand Up @@ -483,6 +488,21 @@ if (config.get('Butler-SOS.influxdbConfig.enable') === true) {
},
tags: ['butler_sos_instance', 'version'],
},
{
measurement: 'user_session_summary',
fields: {
session_count: Influx.FieldType.INTEGER,
session_user_id_list: Influx.FieldType.STRING,
},
tags: tagValuesUserProxySessions,
},
{
measurement: 'user_session_list',
fields: {
session_user_id_list: Influx.FieldType.STRING,
},
tags: tagValuesUserProxySessions,
},
// {
// measurement: 'user_events',
// fields: {
Expand Down Expand Up @@ -661,7 +681,7 @@ async function initInfluxDB() {
defaultTags: tags,

/* maximum time in millis to keep points in an unflushed batch, 0 means don't periodically flush */
flushInterval: 1000,
flushInterval: 5000,

/* maximum size of the retry buffer - it contains items that could not be sent for the first time */
// maxBufferLines: 30_000,
Expand Down
55 changes: 55 additions & 0 deletions src/lib/config-file-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,61 @@ async function verifyConfigFile() {
}
}

// Verify that server tags are correctly defined
// In the config file section `Butler-SOS.serversToMonitor.serverTagsDefinition` it's possible to define zero or more tags that can be set for each server that is to be monitored.
// When Butler SOS is started, do the following checks:
// 1. All tags present in `Butler-SOS.serversToMonitor.serverTagsDefinition` must be set for each server in `SOS.serversToMonitor.servers[]`
// 2. The tags specified for each server in `SOS.serversToMonitor.servers[].serverTags` must be present in `Butler-SOS.serversToMonitor.serverTagsDefinition`
// If either of the conditions above is false, an error should be logged and Butler SOS should not start.
try {

// Loop over all defined server tags
const serverTagsDefinition = config.get(
'Butler-SOS.serversToMonitor.serverTagsDefinition'
);
// eslint-disable-next-line no-restricted-syntax
for (const tag of serverTagsDefinition) {
// Check that all servers have this tag
const servers = config.get('Butler-SOS.serversToMonitor.servers');
// eslint-disable-next-line no-restricted-syntax
for (const server of servers) {
// Check if server.serverTags.tag is defined
if (server?.serverTags === null || !server?.serverTags[tag]) {
logger.error(
`VERIFY CONFIG FILE: Server tag "${tag}" is not defined for server "${server.serverName}". Exiting.`
);
process.exit(1);
} else {
logger.verbose(
`VERIFY CONFIG FILE: Server tag "${tag}" is defined for server "${server.serverName}".`
);
}
}
}

// Now ensure that the tags defined for each server are valid and that there are no extra tags there
const servers = config.get('Butler-SOS.serversToMonitor.servers');
// eslint-disable-next-line no-restricted-syntax
for (const server of servers) {
// eslint-disable-next-line no-restricted-syntax
for (const tag in server.serverTags) {
if (!serverTagsDefinition.includes(tag)) {
logger.error(
`VERIFY CONFIG FILE: Server tag "${tag}" for server "${server.serverName}" is not defined in Butler-SOS.serversToMonitor.serverTagsDefinition. Exiting.`
);
process.exit(1);
} else {
logger.verbose(
`VERIFY CONFIG FILE: Server tag "${tag}" is defined in Butler-SOS.serversToMonitor.serverTagsDefinition.`
);
}
}
}
} catch (err) {
logger.error(`VERIFY CONFIG FILE: Server tags verification failed. ${err}`);
process.exit(1);
}

logger.info(`VERIFY CONFIG FILE: Your config file at ${configFile} is valid, good work!`);

return 'boolean';
Expand Down
6 changes: 3 additions & 3 deletions src/lib/post-to-influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ async function postButlerSOSMemoryUsageToInfluxdb(memory) {
// },

/* maximum time in millis to keep points in an unflushed batch, 0 means don't periodically flush */
flushInterval: 1000,
flushInterval: 5000,

/* maximum size of the retry buffer - it contains items that could not be sent for the first time */
// maxBufferLines: 30_000,
Expand Down Expand Up @@ -778,7 +778,7 @@ async function postUserEventToInfluxdb(msg) {
// },

/* maximum time in millis to keep points in an unflushed batch, 0 means don't periodically flush */
flushInterval: 1000,
flushInterval: 5000,

/* maximum size of the retry buffer - it contains items that could not be sent for the first time */
// maxBufferLines: 30_000,
Expand Down Expand Up @@ -1060,7 +1060,7 @@ async function postLogEventToInfluxdb(msg) {
// },

/* maximum time in millis to keep points in an unflushed batch, 0 means don't periodically flush */
flushInterval: 1000,
flushInterval: 5000,

/* maximum size of the retry buffer - it contains items that could not be sent for the first time */
// maxBufferLines: 30_000,
Expand Down
7 changes: 2 additions & 5 deletions src/lib/proxysessionmetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ function prepUserSessionMetrics(serverName, host, virtualProxy, body, tags) {
// Build tags structure, adding tags for virtual proxy and host the session is associated with
// Start with common/shared set of tags, then add user session specific tags
userProxySessionsData.tags = { ...tags };
// Esnure the virtual proxy does not begin or end with a slash or backslash
userProxySessionsData.tags.user_session_virtual_proxy = virtualProxy.replace(
/^[/\\]+|[/\\]+$/g,
''
);

userProxySessionsData.tags.user_session_virtual_proxy = virtualProxy;
userProxySessionsData.tags.user_session_host = host;

// Build comma separated list of all user IDs connected via the current virtual proxy
Expand Down
31 changes: 25 additions & 6 deletions src/lib/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ const callRemoteURL = async function reportTelemetry() {
let heartbeat = false;
let dockerHealthCheck = false;
let uptimeMonitor = false;
let uptimeMonitorNewRelic = false;
let userEventsEnable = false;
let userEventsMQTTEnable = false;
let userEventsInfluxDBEnable = false;
let userEventsNewRelicEnable = false;
let logEventsProxyEnable = false;
let logEventsSchedulerEnable = false;
let logEventsRepositoryEnable = false;
let logEventsMQTTEnable = false;
let logEventsInfluxDBEnable = false;
let logEventsNewRelicEnable = false;
let logdbEnable = false;
let mqttEnable = false;
let newRelicEnable = false;
Expand All @@ -39,6 +42,10 @@ const callRemoteURL = async function reportTelemetry() {
uptimeMonitor = true;
}

if (globals.config.get('Butler-SOS.uptimeMonitor.storeNewRelic.enable') === true) {
uptimeMonitorNewRelic = true;
}

if (globals.config.get('Butler-SOS.userEvents.enable') === true) {
userEventsEnable = true;
}
Expand All @@ -51,6 +58,10 @@ const callRemoteURL = async function reportTelemetry() {
userEventsInfluxDBEnable = true;
}

if (globals.config.get('Butler-SOS.userEvents.sendToNewRelic.enable') === true) {
userEventsNewRelicEnable = true;
}

if (globals.config.get('Butler-SOS.logEvents.source.proxy.enable') === true) {
logEventsProxyEnable = true;
}
Expand All @@ -71,6 +82,10 @@ const callRemoteURL = async function reportTelemetry() {
logEventsInfluxDBEnable = true;
}

if (globals.config.get('Butler-SOS.logEvents.sendToNewRelic.enable') === true) {
logEventsNewRelicEnable = true;
}

if (globals.config.get('Butler-SOS.logdb.enable') === true) {
logdbEnable = true;
}
Expand Down Expand Up @@ -122,23 +137,24 @@ const callRemoteURL = async function reportTelemetry() {
feature_heartbeat: heartbeat,
feature_dockerHealthCheck: dockerHealthCheck,
feature_uptimeMonitor: uptimeMonitor,
feature_uptimeMonitor_storeInInfluxdb: globals.config.get(
'Butler-SOS.uptimeMonitor.storeInInfluxdb.butlerSOSMemoryUsage'
),
feature_uptimeMonitor_storeNewRelic: uptimeMonitorNewRelic,
feature_udpServer: globals.config.get('Butler-SOS.userEvents.enable'),
feature_userEvents: userEventsEnable,
feature_userEventsMQTT: userEventsMQTTEnable,
feature_userEventsInfluxdb: userEventsInfluxDBEnable,
feature_userEventsNewRelic: userEventsNewRelicEnable,
feature_logEventsProxy: logEventsProxyEnable,
feature_logEventsScheduler: logEventsSchedulerEnable,
feature_logEventsRepository: logEventsRepositoryEnable,
feature_logEventsMQTT: logEventsMQTTEnable,
feature_logEventsInfluxdb: logEventsInfluxDBEnable,
feature_logEventsNewRelic: logEventsNewRelicEnable,
feature_logdb: logdbEnable,
feature_mqtt: mqttEnable,
feature_newRelic: newRelicEnable,
feature_prometheus: prometheusEnable,
feature_influxdb: influxdbEnable,
feature_influxdb_version: globals.config.get('Butler-SOS.influxdbConfig.version'),
feature_appNames: appNamesExtractEnable,
feature_userSessions: userSessionsEnable,

Expand All @@ -159,23 +175,26 @@ const callRemoteURL = async function reportTelemetry() {
heartbeat,
dockerHealthCheck,
uptimeMonitor,
uptimeMonitor_storeInInfluxdb: globals.config.get(
'Butler-SOS.uptimeMonitor.storeInInfluxdb.butlerSOSMemoryUsage'
),
uptimeMonitorNewRelic,
udpServer: globals.config.get('Butler-SOS.userEvents.enable'),
userEvents: userEventsEnable,
userEventsMQTT: userEventsMQTTEnable,
userEventsInfluxdb: userEventsInfluxDBEnable,
userEventsNewRelic: userEventsNewRelicEnable,
logEventsProxy: logEventsProxyEnable,
logEventsScheduler: logEventsSchedulerEnable,
logEventsRepository: logEventsRepositoryEnable,
logEventsMQTT: logEventsMQTTEnable,
logEventsInfluxdb: logEventsInfluxDBEnable,
logEventsNewRelic: logEventsNewRelicEnable,
logdb: logdbEnable,
mqtt: mqttEnable,
newRelic: newRelicEnable,
prometheus: prometheusEnable,
influxdb: influxdbEnable,
influxdbVersion: globals.config.get(
'Butler-SOS.influxdbConfig.version'
),
appNames: appNamesExtractEnable,
userSessions: userSessionsEnable,
},
Expand Down

0 comments on commit eced8dc

Please sign in to comment.