ruby_for_grafana_loki 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/README.md +13 -6
- data/lib/ruby_for_grafana_loki/client.rb +18 -11
- data/lib/ruby_for_grafana_loki/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '008364bfc6b1bf0553546183972f87eb93794364317f2cc6a56b944c14a4deb8'
|
|
4
|
+
data.tar.gz: 00affa1f6564765b4ad1211e1c3efdae57e2e7c7202f9049e75c572772d237ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: af9ed24b5ba9981b6cf927928779e33b8e0129a72280acdbc673f712cd33e4c3a98292204abaf7881897635e897b459d61ba024a98cee2a9e0d2df78ec1f3d3d
|
|
7
|
+
data.tar.gz: d67fd43f8db4dce356f9bbcf65c6da681b330b9d8ca140aea08ccf78a30b13875c00ce0655328c41bcb8f2bd00ab3c80d704e18ead795934235c09ffe02c15aa
|
data/README.md
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
# Usage in your gem or application
|
|
3
3
|
<pre>
|
|
4
|
+
|
|
5
|
+
- add gem "ruby_for_grafana_loki-0.0.5.gem" //to the Gemfile
|
|
6
|
+
- bundle install
|
|
7
|
+
|
|
8
|
+
in the project:
|
|
9
|
+
- logs_type = %w(ERROR WARN FATAL) // Use custom logs type: ERROR, WARN, FATAL, INFO, DEBUG
|
|
10
|
+
- log_file_path = "log/#{Rails.env}.log"
|
|
11
|
+
- client = RubyForGrafanaLoki.client(log_file_path, logs_type)
|
|
12
|
+
- client.jobName = "job name" // your job name
|
|
13
|
+
- client.hostName = "host name" // your host name
|
|
14
|
+
- client.sourceName = "source name" // your source name
|
|
15
|
+
- client.send_all_logs
|
|
16
|
+
- client.send_log("This is a test log message.")
|
|
4
17
|
|
|
5
|
-
|
|
6
|
-
logs_type = %w(ERROR WARN) # Use custom logs type: ERROR, WARN, FATAL, INFO, DEBUG
|
|
7
|
-
log_file_path = "log/#{Rails.env}.log"
|
|
8
|
-
client = RubyForGrafanaLoki.client(log_file_path, logs_type)
|
|
9
|
-
client.send_all_logs
|
|
10
|
-
client.send_log("This is a log message.") # not required
|
|
11
18
|
</pre>
|
|
@@ -3,9 +3,16 @@ module RubyForGrafanaLoki
|
|
|
3
3
|
class Client
|
|
4
4
|
include RubyForGrafanaLoki::Request
|
|
5
5
|
|
|
6
|
+
attr_accessor :job_name
|
|
7
|
+
attr_accessor :host_name
|
|
8
|
+
attr_accessor :source_name
|
|
9
|
+
|
|
6
10
|
def initialize(log_file_path, allowed_logs_type = LOGS_TYPE)
|
|
7
11
|
@log_file_path = log_file_path
|
|
8
12
|
@allowed_logs_type = allowed_logs_type
|
|
13
|
+
@job_name = "job_name"
|
|
14
|
+
@host_name = "host_name"
|
|
15
|
+
@source_name = "source_name"
|
|
9
16
|
end
|
|
10
17
|
|
|
11
18
|
def send_all_logs
|
|
@@ -15,25 +22,25 @@ module RubyForGrafanaLoki
|
|
|
15
22
|
end
|
|
16
23
|
end
|
|
17
24
|
end
|
|
25
|
+
|
|
18
26
|
def send_log(log_message)
|
|
19
27
|
curr_datetime = Time.now.to_i * 1_000_000_000
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
msg = "On server #{host} detected error"
|
|
29
|
+
msg = "On server #{@host_name} detected error"
|
|
23
30
|
|
|
24
31
|
payload = {
|
|
25
|
-
|
|
32
|
+
'streams' => [
|
|
26
33
|
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
'stream' => {
|
|
35
|
+
'source' => @source_name,
|
|
36
|
+
'job' => @job_name,
|
|
37
|
+
'host' => @host_name
|
|
31
38
|
},
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
'values' => [[curr_datetime.to_s, log_message]],
|
|
40
|
+
'entries' => [
|
|
34
41
|
{
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
'ts' => curr_datetime,
|
|
43
|
+
'line' => "[WARN] " + msg
|
|
37
44
|
}
|
|
38
45
|
]
|
|
39
46
|
}
|