forked from nokute78/fluent-bit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This initial import have a basic routine to read messages from the /dev/kmsg device. Signed-off-by: Eduardo Silva <[email protected]>
- Loading branch information
0 parents
commit 49269c5
Showing
7 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
all: | ||
$(MAKE) -C src/ | ||
|
||
clean: | ||
$(MAKE) -C src/ clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Fluent Bit | ||
|
||
__Fluent-Bit__ is a [Fluentd](http://fluentd.org) collection tool designed for Embedded Linux that collects Kernel messages (Kernel Ring Buffer) and Hardware metrics such as CPU and Memory usage. | ||
|
||
## Build | ||
|
||
The tool do not have any dependency besides the standard C library, to build it just type _make_: | ||
|
||
```bash | ||
$ make | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
||
/* Fluent Bit | ||
* ========== | ||
* Copyright (C) 2015 Treasure Data Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef FLB_IN_KMSG | ||
#define FLB_IN_KMSG | ||
|
||
#define FLB_KMSG_DEV "/dev/kmsg" | ||
|
||
int in_kmsg_start(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CC = gcc | ||
CFLAGS = -g -Wall | ||
INCDIR = -I../include/ | ||
SOURCE = in_kmsg.c fluent-bit.c | ||
|
||
all: | ||
$(CC) $(CFLAGS) $(INCDIR) $(SOURCE) -o ../bin/fluent-bit | ||
|
||
clean: | ||
rm -rf ../bin/fluent-bit *.o *~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
||
/* Fluent Bit | ||
* ========== | ||
* Copyright (C) 2015 Treasure Data Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <fluent-bit/in_kmsg.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
in_kmsg_start(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
||
/* Fluent Bit | ||
* ========== | ||
* Copyright (C) 2015 Treasure Data Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
#include <unistd.h> | ||
|
||
#include <fluent-bit/in_kmsg.h> | ||
|
||
int in_kmsg_start() | ||
{ | ||
int fd; | ||
int bytes; | ||
char line[1024]; | ||
|
||
fd = open(FLB_KMSG_DEV, O_RDONLY); | ||
if (fd == -1) { | ||
perror("open"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
while (1) { | ||
bytes = read(fd, line, sizeof(line) - 1); | ||
|
||
if (bytes == -1) { | ||
if (errno == -EPIPE) { | ||
/* Message overwritten / circular buffer */ | ||
continue; | ||
} | ||
break; | ||
} | ||
else if (bytes > 0) { | ||
line[bytes - 1] = '\0'; | ||
printf("%s\n", line); | ||
} | ||
} | ||
|
||
return 0; | ||
} |