@paimaexample/grafana-alloy 0.3.105
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/alloy-config +45 -0
- package/index.js +118 -0
- package/package.json +15 -0
package/alloy-config
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Example config file for Alloy.
|
|
2
|
+
// Set the agent's global log level
|
|
3
|
+
logging {
|
|
4
|
+
level = "info"
|
|
5
|
+
format = "logfmt"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
otelcol.receiver.otlp "default" {
|
|
9
|
+
grpc {}
|
|
10
|
+
http {}
|
|
11
|
+
|
|
12
|
+
output {
|
|
13
|
+
// Send metrics/traces to debug
|
|
14
|
+
// metrics = [otelcol.exporter.debug.default.input,]
|
|
15
|
+
// traces = [otelcol.exporter.debug.default.input,]
|
|
16
|
+
|
|
17
|
+
logs = [
|
|
18
|
+
otelcol.processor.batch.default.input,
|
|
19
|
+
// otelcol.exporter.debug.default.input,
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// This processor receives from the receiver's output
|
|
25
|
+
otelcol.processor.batch "default" {
|
|
26
|
+
output {
|
|
27
|
+
logs = [otelcol.exporter.otlphttp.default.input]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// This exporter receives from the receiver's output
|
|
32
|
+
otelcol.exporter.debug "default" {
|
|
33
|
+
verbosity = "normal"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// This exporter receives from the batch processor's output
|
|
37
|
+
otelcol.exporter.otlphttp "default" {
|
|
38
|
+
client {
|
|
39
|
+
endpoint = "http://localhost:3100/otlp"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
livedebugging {
|
|
44
|
+
enabled = true
|
|
45
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { platform, arch } from 'node:os';
|
|
3
|
+
import BinWrapper from '@xhmikosr/bin-wrapper';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
|
|
8
|
+
console.log(`Starting Grafana Alloy on ${platform()} ${arch()}`);
|
|
9
|
+
|
|
10
|
+
// Get binary name.
|
|
11
|
+
// This is the default name after the binary is downloaded and extracted.
|
|
12
|
+
function getBinaryName() {
|
|
13
|
+
const os = arch();
|
|
14
|
+
switch (platform()) {
|
|
15
|
+
case 'win32':
|
|
16
|
+
return (os === 'x64') ? 'alloy-windows-amd64.exe' :
|
|
17
|
+
undefined;
|
|
18
|
+
|
|
19
|
+
case 'darwin':
|
|
20
|
+
return (os === 'arm64') ? 'alloy-darwin-arm64' :
|
|
21
|
+
(os === 'x64') ? 'alloy-darwin-amd64' :
|
|
22
|
+
undefined;
|
|
23
|
+
case 'linux':
|
|
24
|
+
return (os === 'arm64') ? 'alloy-linux-arm64' :
|
|
25
|
+
(os === 'x64') ? 'alloy-linux-amd64' :
|
|
26
|
+
undefined;
|
|
27
|
+
}
|
|
28
|
+
// Throw error if binary name is not found, we don't have the binary for this platform.
|
|
29
|
+
throw new Error(`Unsupported platform: ${platform} - ${os}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function cleanBinary() {
|
|
33
|
+
console.log(`Cleaning binary folder: ${path.join(import.meta.dirname, 'vendor')}`);
|
|
34
|
+
fs.rmSync(path.join(import.meta.dirname, 'vendor'), { recursive: true, force: true });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function cleanData() {
|
|
38
|
+
console.log(`Cleaning data folder: ${path.join(import.meta.dirname, 'data')}`);
|
|
39
|
+
fs.rmSync(path.join(import.meta.dirname, 'data'), { recursive: true, force: true });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const binaryName = getBinaryName();
|
|
43
|
+
|
|
44
|
+
// Download the binary from the GitHub releases page.
|
|
45
|
+
const version = '1.11.3';
|
|
46
|
+
const base = `https://github.com/grafana/alloy/releases/download/v${version}/`;
|
|
47
|
+
|
|
48
|
+
const bin = new BinWrapper()
|
|
49
|
+
.src(`${base}/alloy-darwin-arm64.zip`, 'darwin', 'arm64')
|
|
50
|
+
.src(`${base}/alloy-darwin-amd64.zip`, 'darwin', 'x64')
|
|
51
|
+
.src(`${base}/alloy-linux-arm64.zip`, 'linux', 'arm64')
|
|
52
|
+
.src(`${base}/alloy-linux-amd64.zip`, 'linux', 'x64')
|
|
53
|
+
.src(`${base}/alloy-windows-amd64.exe.zip`, 'win32', 'x64')
|
|
54
|
+
.dest(path.join(import.meta.dirname, 'vendor'))
|
|
55
|
+
.use(binaryName)
|
|
56
|
+
.version(`>=${version}`)
|
|
57
|
+
;
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async function runBinary(args = []) {
|
|
61
|
+
// Check if the binary is installed working.
|
|
62
|
+
await bin.run(['--version']);
|
|
63
|
+
|
|
64
|
+
const message = `Alloy Web URL: http://localhost:12345`
|
|
65
|
+
// Binary command to launch.
|
|
66
|
+
const command = {
|
|
67
|
+
bin: bin.path(),
|
|
68
|
+
args: [
|
|
69
|
+
'run', path.join(import.meta.dirname, 'alloy-config'),
|
|
70
|
+
'--storage.path', path.join(import.meta.dirname, 'data'),
|
|
71
|
+
'--stability.level=experimental',
|
|
72
|
+
...args
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
const line = Array(80).fill('=').join('');
|
|
76
|
+
console.log(`${line}\nLaunching command:\n${command.bin} ${command.args.join(' ')}\n\n${message}\n${line}`);
|
|
77
|
+
const child = spawn(command.bin, command.args);
|
|
78
|
+
|
|
79
|
+
child.stdout.setEncoding('utf8');
|
|
80
|
+
child.stdout.on('data', (chunk) => {
|
|
81
|
+
console.log(chunk.toString());
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
child.stderr.setEncoding('utf8');
|
|
85
|
+
child.stderr.on('data', (chunk) => {
|
|
86
|
+
console.error(chunk.toString());
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
child.on('close', (code) => {
|
|
90
|
+
console.log(`child process exited with code ${code}`);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return child;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Launch the binary.
|
|
97
|
+
// Custom options:
|
|
98
|
+
// --no-clean-data to not remove the data storage folder.
|
|
99
|
+
// --clean-binary to remove the binary folder.
|
|
100
|
+
(async () => {
|
|
101
|
+
// This script is launched with:
|
|
102
|
+
// deno -A @paimaexample/grafana-alloy grafana-alloy <optional-args>
|
|
103
|
+
const optionalArgs = process.argv.slice(3);
|
|
104
|
+
|
|
105
|
+
// Clean the data if the flag is not present.
|
|
106
|
+
if (!optionalArgs.includes('--no-clean-data')) cleanData();
|
|
107
|
+
|
|
108
|
+
// Clean the binary folder if the flag is present.
|
|
109
|
+
if (optionalArgs.includes('--clean-binary')) cleanBinary();
|
|
110
|
+
|
|
111
|
+
optionalArgs.indexOf('--no-clean-data') !== -1 && optionalArgs.splice(optionalArgs.indexOf('--no-clean-data'), 1);
|
|
112
|
+
optionalArgs.indexOf('--clean-binary') !== -1 && optionalArgs.splice(optionalArgs.indexOf('--clean-binary'), 1);
|
|
113
|
+
|
|
114
|
+
// Run the binary with the remaining optional arguments.
|
|
115
|
+
await runBinary(optionalArgs);
|
|
116
|
+
})();
|
|
117
|
+
|
|
118
|
+
export default runBinary;
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@paimaexample/grafana-alloy",
|
|
3
|
+
"version": "0.3.105",
|
|
4
|
+
"description": "A wrapper for the Grafana Alloy OTEL binary",
|
|
5
|
+
"main": "install.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"grafana-alloy": "index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node install.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xhmikosr/bin-wrapper": "^13.2.0"
|
|
14
|
+
}
|
|
15
|
+
}
|