move credentials to settings.json, use RVExtensionArgs call

adds value type definitions for float/int, adds mission, server name, world name to sent metrics
This commit is contained in:
2023-04-04 15:18:44 -07:00
parent 6044126e86
commit cc6f6b911c
3 changed files with 66 additions and 42 deletions

View File

@@ -1,23 +1,47 @@
// function adapted from YAINA by MartinCo at http://yaina.eu
if !(isServer || !hasInterface) exitWith {};
// if (!isServer) exitWith {};
_cba = (isClass(configFile >> "CfgPatches" >> "cba_main"));
RangerMetrics_debug = true;
[format ["Instance name: %1", profileName]] call RangerMetrics_fnc_log;
[format ["CBA detected: %1", _cba]] call RangerMetrics_fnc_log;
["Initializing v1.1"] call RangerMetrics_fnc_log;
RangerMetrics_run = true;
// _extData = "RangerMetrics" callExtension "loadSettings";
// if (_extData == "0") exitWith {
// ["Extension not found, disabling"] call RangerMetrics_fnc_log;
// RangerMetrics_run = false;
// };
if(_cba) then { // CBA is running, use PFH
[RangerMetrics_fnc_run, 10, [_cba]] call CBA_fnc_addPerFrameHandler;
} else { // CBA isn't running, use sleep
[_cba] spawn {
params ["_cba"];
while{true} do {
[[_cba]] call RangerMetrics_fnc_run; // nested to match CBA PFH signature
sleep 10;
// _extData = parseSimpleArray _extData;
// RangerMetrics_settingsDir = _extData select 0;
// RangerMetrics_settingsLoaded = _extData select 1;
// RangerMetrics_influxURL = _extData select 2;
// [format["InfluxDB URL: %1", RangerMetrics_influxURL]] call RangerMetrics_fnc_log;
// _extVersion = "RangerMetrics" callExtension "version";
// ["Extension version: " + _extVersion] call RangerMetrics_fnc_log;
addMissionEventHandler ["ExtensionCallback", {
params ["_name", "_function", "_data"];
if (_name == "RangerMetrics") then {
[parseSimpleArray _data] call RangerMetrics_fnc_log;
};
};
};
}];
// RangerMetrics_run = true;
// if(_cba) then { // CBA is running, use PFH
// [RangerMetrics_fnc_run, 10, [_cba]] call CBA_fnc_addPerFrameHandler;
// } else { // CBA isn't running, use sleep
// [_cba] spawn {
// params ["_cba"];
// while{true} do {
// [[_cba]] call RangerMetrics_fnc_run; // nested to match CBA PFH signature
// sleep 10;
// };
// };
// };

View File

@@ -46,7 +46,7 @@ if(missionNamespace getVariable ["RangerMetrics_run",false]) then {
private _headlessClients = entities "HeadlessClient_F";
{
{
private _stats_fps = round diag_fps;
private _stats_fps = diag_fps;
["stats.HCfps", "float", _stats_fps] remoteExec ["RangerMetrics_fnc_send", 2];
} remoteExecCall ["bis_fnc_call", owner _x];

View File

@@ -1,38 +1,37 @@
params ["_metric", "_value", ["_global", false]];
params ["_metric", "_valueType", "_value", ["_global", false]];
private _profileName = profileName;
private _prefix = "Arma3";
private _locality = [profileName, "global"] select _global;
// InfluxDB settings
// private _connection = "http://indifox.info:8086";
// private _token = "BwOzapPBLZ-lhtrcs3PC2Jk2p7plCC0UckHKxe8AxulYkk9St1q2aloXMW2rDD4X2ufIkx3fwSbEe6ZeJo8ljg==";
// private _org = "ranger-metrics";
// private _bucket = "ranger-metrics";
private _environmentMeta = [missionName, worldName, serverName];
private _metricPath = [
format["%1,%2,%3,%4,%5",
// private _extSend = format["%1,%2", format["%1,%2,%3,%4,%5,%6", _connection, _token, _org, _bucket, _metricPath, _metric], _value];
private _extSend = [
// _connection,
// _token,
// _org,
// _bucket,
_profileName,
profileName,
missionName, worldName, serverName
],
format["%1,%2,%3,%4,%5",
_profileName,
"global",
missionName, worldName, serverName
]
] select _global;
// InfluDB settings
private _connection = "http://INFLUX_URL:8086";
private _token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX_AUTH_TOKEN_XXXXXXXXXXXXXXXXXXXXXXXXXXX";
private _org = "XXX_INFLUX_ORG_XXXXXX";
private _bucket = "XXX_BUCKET_NAME";
private _extSend = format["%1,%2", format["%1,%2,%3,%4,%5,%6", _connection, _token, _org, _bucket, _metricPath, _metric], _value];
_locality,
missionName,
worldName,
serverName,
_metric,
_valueType,
_value
];
if(missionNamespace getVariable ["RangerMetrics_debug",false]) then {
[format ["Sending a3influx data: %1", _extSend], "DEBUG"] call RangerMetrics_fnc_log;
};
// send the data
private _return = "RangerMetrics" callExtension _extSend;
private _return = "RangerMetrics" callExtension ["sendToInflux", _extSend];
// shouldn't be possible, the extension should always return even if error
if(isNil "_return") exitWith {
@@ -41,14 +40,15 @@ if(isNil "_return") exitWith {
};
// extension error codes
if(_return in ["invalid metric value","malformed, could not find separator"] ) exitWith {
[format ["%1 (%2)", _return, _extSend], "ERROR"] call RangerMetrics_fnc_log;
false
};
// if(_return in ["invalid metric value","malformed, could not find separator"] ) exitWith {
// [format ["%1 (%2)", _return, _extSend], "ERROR"] call RangerMetrics_fnc_log;
// false
// };
// success, only show if debug is set
if(missionNamespace getVariable ["RangerMetrics_debug",false]) then {
_returnArgs = _return splitString (toString [10,32]);
// _returnArgs = _return splitString (toString [10,32]);
_returnArgs = parseSimpleArray _return;
[format ["a3influx return data: %1",_returnArgs], "DEBUG"] call RangerMetrics_fnc_log;
};