Skip to content

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
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
edsiper committed Jan 27, 2015
0 parents commit 49269c5
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:
$(MAKE) -C src/

clean:
$(MAKE) -C src/ clean
11 changes: 11 additions & 0 deletions README.md
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 added bin/.empty
Empty file.
27 changes: 27 additions & 0 deletions include/fluent-bit/in_kmsg.h
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
10 changes: 10 additions & 0 deletions src/Makefile
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 *~
27 changes: 27 additions & 0 deletions src/fluent-bit.c
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;
}
59 changes: 59 additions & 0 deletions src/in_kmsg.c
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;
}

0 comments on commit 49269c5

Please sign in to comment.