├── .gitignore ├── sample ├── sample.rrd ├── percent-idle.rrd ├── percent-user.rrd └── annotations.csv ├── Makefile ├── rrd ├── zutroy.framasoft.org-proc_pri-high-g.rrd └── zutroy.framasoft.org-threads-threads-g.rrd ├── go.mod ├── Dockerfile ├── go.sum ├── LICENSE ├── .circleci └── config.yml ├── README.md ├── rrdserver_test.go └── rrdserver.go /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | -------------------------------------------------------------------------------- /sample/sample.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doublemarket/grafana-rrd-server/HEAD/sample/sample.rrd -------------------------------------------------------------------------------- /sample/percent-idle.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doublemarket/grafana-rrd-server/HEAD/sample/percent-idle.rrd -------------------------------------------------------------------------------- /sample/percent-user.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doublemarket/grafana-rrd-server/HEAD/sample/percent-user.rrd -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | go test -v -parallel=4 . 3 | 4 | run: 5 | go run rrdserver.go 6 | 7 | deps: 8 | glide i 9 | -------------------------------------------------------------------------------- /rrd/zutroy.framasoft.org-proc_pri-high-g.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doublemarket/grafana-rrd-server/HEAD/rrd/zutroy.framasoft.org-proc_pri-high-g.rrd -------------------------------------------------------------------------------- /rrd/zutroy.framasoft.org-threads-threads-g.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doublemarket/grafana-rrd-server/HEAD/rrd/zutroy.framasoft.org-threads-threads-g.rrd -------------------------------------------------------------------------------- /sample/annotations.csv: -------------------------------------------------------------------------------- 1 | time,title,tags,text 2 | 1480917950000,"Rebooted","system","The server is rebooted." 3 | 1494763899000,"App restarted","app1,app2","The apps are restarted." 4 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/doublemarket/grafana-rrd-server 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/gocarina/gocsv v0.0.0-20200330101823-46266ca37bd3 7 | github.com/mattn/go-zglob v0.0.3 8 | github.com/ziutek/rrd v0.0.3 9 | ) 10 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.16-alpine AS builder 2 | 3 | RUN apk update && apk add pkgconfig rrdtool-dev gcc libc-dev 4 | 5 | WORKDIR /build 6 | COPY . . 7 | RUN go build -o grafana-rrd-server 8 | 9 | FROM alpine 10 | RUN apk add rrdtool rrdtool-dev 11 | COPY --from=builder /build/grafana-rrd-server /grafana-rrd-server 12 | ENTRYPOINT [ "/grafana-rrd-server" ] -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/gocarina/gocsv v0.0.0-20200330101823-46266ca37bd3 h1:B7k6N+JlLM/u1xrIkpifUfE7GRJsZIYHoHbiAa5cSP4= 2 | github.com/gocarina/gocsv v0.0.0-20200330101823-46266ca37bd3/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI= 3 | github.com/mattn/go-zglob v0.0.3 h1:6Ry4EYsScDyt5di4OI6xw1bYhOqfE5S33Z1OPy+d+To= 4 | github.com/mattn/go-zglob v0.0.3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo= 5 | github.com/ziutek/rrd v0.0.3 h1:tGu7Dy0Z2Ij0qF7/7+fqWBZlM0j2Kp/RoTEG3+zHXjQ= 6 | github.com/ziutek/rrd v0.0.3/go.mod h1:PAFbtWhFYrVeILz+2a6OKKdLYk8RlPJotQXlj7O0Z0A= 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Hayato Matsuura 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | jobs: 3 | test: 4 | docker: 5 | - image: golang:1.14-stretch 6 | environment: 7 | GOROOT: "" 8 | SRCPATH: "/root/.go_project" 9 | PATH: "/root/.go_project/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/go/bin" 10 | IMPORT_PATH: "github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME" 11 | steps: 12 | - checkout 13 | - run: 14 | name: Install prerequired packges 15 | command: | 16 | apt update 17 | apt install -y software-properties-common python3-software-properties 18 | apt install -y librrd-dev 19 | mkdir -p $SRCPATH/src/github.com/$CIRCLE_PROJECT_USERNAME 20 | cd $SRCPATH/src/github.com/$CIRCLE_PROJECT_USERNAME 21 | ln -s /root/project $CIRCLE_PROJECT_REPONAME 22 | cd $CIRCLE_PROJECT_REPONAME 23 | - run: 24 | name: Run tests 25 | command: | 26 | cd $SRCPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME 27 | go test 28 | deploy: 29 | docker: 30 | - image: golang:1.14-stretch 31 | environment: 32 | GOROOT: "" 33 | SRCPATH: "/root/.go_project" 34 | PATH: "/root/.go_project/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/go/bin" 35 | IMPORT_PATH: "github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME" 36 | steps: 37 | - checkout 38 | - run: 39 | name: Install prerequired packges 40 | command: | 41 | apt update 42 | apt install -y software-properties-common python3-software-properties 43 | apt install -y librrd-dev 44 | mkdir -p $SRCPATH/src/github.com/$CIRCLE_PROJECT_USERNAME 45 | cd $SRCPATH/src/github.com/$CIRCLE_PROJECT_USERNAME 46 | ln -s /root/project $CIRCLE_PROJECT_REPONAME 47 | cd $CIRCLE_PROJECT_REPONAME 48 | - run: 49 | name: Deploy 50 | command: | 51 | cd $SRCPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME 52 | go get . 53 | gox -osarch "linux/amd64" -ldflags "-X main.Version=$BUILD_VERSION -X main.BuildDate=$BUILD_DATE" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" 54 | gzip dist/* 55 | ghr -t $GITHUB_TOKEN -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME --replace $(git describe --tags) dist/ 56 | workflows: 57 | version: 2 58 | test_and_deploy: 59 | jobs: 60 | - test: 61 | filters: 62 | tags: 63 | only: /.*/ 64 | - deploy: 65 | requires: 66 | - test 67 | filters: 68 | tags: 69 | only: /v[0-9]+(\.[0-9]+)+/ 70 | branches: 71 | ignore: /.*/ 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Grafana RRD Server 2 | 3 | A simple HTTP server that reads RRD files and responds to requests from Grafana with [Grafana Simple JSON Datasource plugin](https://grafana.net/plugins/grafana-simple-json-datasource). 4 | 5 | [![CircleCI](https://img.shields.io/circleci/project/github/doublemarket/grafana-rrd-server.svg)](https://circleci.com/gh/doublemarket/grafana-rrd-server) 6 | [![Coveralls](https://img.shields.io/coveralls/doublemarket/grafana-rrd-server.svg)](https://coveralls.io/github/doublemarket/grafana-rrd-server) 7 | [![GitHub release](https://img.shields.io/github/release/doublemarket/grafana-rrd-server.svg)](https://github.com/doublemarket/grafana-rrd-server/releases) 8 | 9 | This server supports all endpoints (urls) defined in the [Grafana Simple JSON Datasource plugin documentation](https://grafana.net/plugins/grafana-simple-json-datasource) but: 10 | 11 | - You can use `*` as a wildcard in the `target` values (but not for `ds`) for the `/query` endpoint. 12 | 13 | # Requirement 14 | 15 | - librrd-dev (rrdtool) 16 | - Go 17 | - Grafana 3.0 and newer + Simple JSON Datasource plugin 1.0.0 and newer 18 | 19 | # Usage 20 | 21 | 1. Install librrd-dev (rrdtool). 22 | 23 | On Ubuntu/Debian: 24 | 25 | ``` 26 | sudo apt install librrd-dev 27 | ``` 28 | 29 | On CentOS: 30 | 31 | ``` 32 | sudo yum install rrdtool-devel 33 | ``` 34 | 35 | On openSUSE 36 | ``` 37 | sudo zypper in rrdtool-devel 38 | ``` 39 | 40 | On Mac: 41 | 42 | ``` 43 | brew install rrdtool 44 | ``` 45 | 46 | 2. Get the package. 47 | 48 | ``` 49 | go get github.com/doublemarket/grafana-rrd-server 50 | ``` 51 | 52 | Otherwise, download [the latest release](https://github.com/doublemarket/grafana-rrd-server/releases/latest), gunzip it, and put the file in a directory included in `$PATH`: 53 | 54 | ``` 55 | gunzip grafana-rrd-server_linux_amd64.gz 56 | ``` 57 | 58 | 3. Run the server. 59 | 60 | ``` 61 | grafana-rrd-server 62 | ``` 63 | 64 | You can use the following options: 65 | 66 | - `-h` : Shows help messages. 67 | - `-p` : Specifies server port. (default: 9000) 68 | - `-i` : Specifies server listen address. (default: any) 69 | - `-r` : Specifies a directory path keeping RRD files. (default: "./sample/") 70 | - The server recursively searches RRD files under the directory and returns a list of them for the `/search` endpoint. 71 | - `-a` : Specifies the annotations file. It should be a CSV file which has a title line at the top like [the sample file](https://github.com/doublemarket/grafana-rrd-server/tree/master/sample/annotations.csv). 72 | - `-s` : Default graph step in second. (default: 10) 73 | - You can see the step for your RRD file using: 74 | ``` 75 | $ rrdtool info [rrd file] | grep step 76 | step = 300 77 | ``` 78 | 79 | 4. Optionally set up systemd unit: 80 | 81 | ``` 82 | useradd grafanarrd 83 | cat > /etc/systemd/system/grafana-rrd-server.service <