├── debian ├── compat ├── source │ └── format ├── changelog ├── service ├── rules └── control ├── img ├── io-req-latency-hist.png └── io-req-latency-heatmap.png ├── .gitignore ├── go.mod ├── Dockerfile ├── main.go ├── bpf.go ├── README.md ├── collector.go ├── go.sum └── LICENSE /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /img/io-req-latency-hist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dswarbrick/ebpf_exporter/HEAD/img/io-req-latency-hist.png -------------------------------------------------------------------------------- /img/io-req-latency-heatmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dswarbrick/ebpf_exporter/HEAD/img/io-req-latency-heatmap.png -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | prometheus-ebpf-exporter (0.0.1) UNRELEASED; urgency=low 2 | 3 | * Initial packaged version 4 | 5 | -- Daniel Swarbrick Wed, 13 Jun 2018 16:52:34 +0200 6 | -------------------------------------------------------------------------------- /debian/service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=ebpf-exporter is a Prometheus exporter which uses eBPF kprobes 3 | After=network.target 4 | 5 | [Service] 6 | ExecStart=/usr/bin/ebpf-exporter 7 | 8 | [Install] 9 | WantedBy=multi-user.target 10 | Alias=ebpf-exporter.service 11 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | #export DH_VERBOSE := 1 4 | export DH_GOPKG := github.com/dswarbrick/ebpf_exporter 5 | 6 | %: 7 | dh $@ --buildsystem=golang --with=golang,systemd --builddirectory=_build 8 | 9 | override_dh_auto_install: 10 | dh_auto_install -- --no-source 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | 7 | # Test binary, build with `go test -c` 8 | *.test 9 | 10 | # Output of the go coverage tool, specifically when used with LiteIDE 11 | *.out 12 | 13 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 14 | .glide/ 15 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: prometheus-ebpf-exporter 2 | Section: net 3 | Priority: optional 4 | Maintainer: Daniel Swarbrick 5 | Build-Depends: debhelper (>= 10), 6 | dh-golang, 7 | dh-systemd, 8 | golang-go, 9 | golang-github-go-kit-kit-dev, 10 | golang-github-prometheus-client-golang-dev, 11 | golang-github-prometheus-client-model-dev, 12 | golang-github-prometheus-common-dev (>= 0+git20171117), 13 | golang-gopkg-alecthomas-kingpin.v2-dev, 14 | libbpfcc-dev (>= 0.6.0) 15 | Standards-Version: 4.1.2 16 | Homepage: https://github.com/dswarbrick/ebpf_exporter 17 | Vcs-Browser: https://github.com/dswarbrick/ebpf_exporter 18 | Vcs-Git: git@github.com:dswarbrick/ebpf_exporter.git 19 | 20 | Package: prometheus-ebpf-exporter 21 | Architecture: any 22 | Depends: ${shlibs:Depends}, 23 | ${misc:Depends}, 24 | libbpfcc (>= 0.6.0) 25 | Built-Using: ${misc:Built-Using} 26 | Description: Prometheus exporter which uses eBPF kprobes 27 | ebpf_exporter is an experimental Prometheus exporter which uses eBPF kprobes 28 | to efficiently record a histogram of Linux bio request latencies and sizes. 29 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/dswarbrick/ebpf_exporter 2 | 3 | go 1.24 4 | 5 | toolchain go1.24.2 6 | 7 | require ( 8 | github.com/iovisor/gobpf v0.2.0 9 | github.com/prometheus/client_golang v1.21.1 10 | github.com/prometheus/common v0.66.1 11 | github.com/prometheus/exporter-toolkit v0.14.1 12 | gopkg.in/alecthomas/kingpin.v2 v2.2.6 13 | ) 14 | 15 | require ( 16 | github.com/alecthomas/kingpin/v2 v2.4.0 // indirect 17 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect 18 | github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect 19 | github.com/beorn7/perks v1.0.1 // indirect 20 | github.com/cespare/xxhash/v2 v2.3.0 // indirect 21 | github.com/coreos/go-systemd/v22 v22.6.0 // indirect 22 | github.com/jpillora/backoff v1.0.0 // indirect 23 | github.com/klauspost/compress v1.17.11 // indirect 24 | github.com/mdlayher/socket v0.4.1 // indirect 25 | github.com/mdlayher/vsock v1.2.1 // indirect 26 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 27 | github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect 28 | github.com/prometheus/client_model v0.6.2 // indirect 29 | github.com/prometheus/procfs v0.15.1 // indirect 30 | github.com/xhit/go-str2duration/v2 v2.1.0 // indirect 31 | go.yaml.in/yaml/v2 v2.4.2 // indirect 32 | golang.org/x/crypto v0.41.0 // indirect 33 | golang.org/x/net v0.43.0 // indirect 34 | golang.org/x/oauth2 v0.30.0 // indirect 35 | golang.org/x/sync v0.16.0 // indirect 36 | golang.org/x/sys v0.35.0 // indirect 37 | golang.org/x/text v0.28.0 // indirect 38 | google.golang.org/protobuf v1.36.8 // indirect 39 | ) 40 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:edge 2 | 3 | RUN apk add --update \ 4 | git \ 5 | llvm-dev \ 6 | llvm-static \ 7 | clang-dev \ 8 | clang-static \ 9 | cmake \ 10 | flex-dev \ 11 | bison \ 12 | luajit-dev \ 13 | build-base \ 14 | iperf \ 15 | linux-headers \ 16 | elfutils-dev \ 17 | zlib-dev \ 18 | python-dev 19 | 20 | RUN ln -s /usr/lib/cmake/llvm5/ /usr/lib/cmake/llvm; \ 21 | ln -s /usr/include/llvm5/llvm-c/ /usr/include/llvm-c; \ 22 | ln -s /usr/include/llvm5/llvm/ /usr/include/llvm 23 | 24 | RUN git clone https://github.com/iovisor/bcc.git 25 | 26 | WORKDIR /bcc 27 | 28 | # Specific patches 29 | RUN git config --global user.email "build@example.com" && \ 30 | git checkout v0.5.0 && \ 31 | git cherry-pick -m 1 b44d705657d24a54605e10da1bd92a2d8b13b908 && \ 32 | git cherry-pick -m 1 3dbb0db486b155fb2ce6850d8d9c69bd9974a0db && \ 33 | git cherry-pick -m 1 04ec1fa84a669dbf7f48728237f8d24c32a38803 34 | 35 | WORKDIR /bcc/build 36 | 37 | RUN cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release 38 | RUN make -j$(nproc) 39 | RUN make install 40 | RUN echo -e "#include \n$(cat /usr/include/bcc/libbpf.h)" > /usr/include/bcc/libbpf.h 41 | RUN strip /usr/lib64/libbcc.so.0.5.0 42 | 43 | FROM golang:1.10-alpine 44 | RUN wget -O /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 && chmod +x /usr/local/bin/dep 45 | RUN apk add --update --no-cache git gcc musl-dev linux-headers elfutils-libelf zlib libstdc++ libgcc 46 | WORKDIR $GOPATH/src/github.com/dswarbrick/ebpf_exporter 47 | COPY Gopkg.lock Gopkg.toml ./ 48 | RUN dep ensure --vendor-only 49 | COPY . . 50 | COPY --from=0 /usr/lib64/libbcc.so.0.5.0 /usr/lib/ 51 | RUN ln -s /usr/lib/libbcc.so.0.5.0 /usr/lib/libbcc.so.0 && \ 52 | ln -s /usr/lib/libbcc.so.0.5.0 /usr/lib/libbcc.so 53 | COPY --from=0 /usr/include/bcc /usr/include/bcc 54 | COPY --from=0 /usr/lib64/pkgconfig/libbcc.pc /usr/lib64/pkgconfig/ 55 | RUN go install -ldflags="-s -w" . 56 | 57 | FROM alpine:edge 58 | RUN apk --no-cache --update add elfutils-libelf zlib libstdc++ libgcc 59 | COPY --from=0 /usr/lib64/libbcc.so.0.5.0 /usr/lib/ 60 | RUN ln -s /usr/lib/libbcc.so.0.5.0 /usr/lib/libbcc.so.0 && \ 61 | ln -s /usr/lib/libbcc.so.0.5.0 /usr/lib/libbcc.so 62 | COPY --from=1 /go/bin/ebpf_exporter / 63 | CMD ["/ebpf_exporter"] 64 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | //go:build linux 2 | // +build linux 3 | 4 | // ebpf_exporter - A Prometheus exporter for Linux block IO statistics. 5 | // 6 | // Copyright 2018 Daniel Swarbrick 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | 19 | package main 20 | 21 | import ( 22 | "fmt" 23 | "net/http" 24 | "os" 25 | 26 | "github.com/iovisor/gobpf/bcc" 27 | "github.com/prometheus/client_golang/prometheus" 28 | "github.com/prometheus/client_golang/prometheus/promhttp" 29 | "github.com/prometheus/common/promslog" 30 | "github.com/prometheus/common/promslog/flag" 31 | "github.com/prometheus/common/version" 32 | "github.com/prometheus/exporter-toolkit/web" 33 | "github.com/prometheus/exporter-toolkit/web/kingpinflag" 34 | "gopkg.in/alecthomas/kingpin.v2" 35 | ) 36 | 37 | const namespace = "ebpf" 38 | 39 | func main() { 40 | toolkitFlags := kingpinflag.AddFlags(kingpin.CommandLine, ":9123") 41 | promlogConfig := &promslog.Config{} 42 | flag.AddFlags(kingpin.CommandLine, promlogConfig) 43 | kingpin.Version(version.Print("ebpf_exporter")) 44 | kingpin.HelpFlag.Short('h') 45 | kingpin.Parse() 46 | 47 | logger := promslog.New(promlogConfig) 48 | 49 | logger.Info("Starting ebpf_exporter", "version", version.Info()) 50 | logger.Info("Build context", version.BuildContext()) 51 | 52 | // Compile BPF code and return new module 53 | m := bcc.NewModule(bpfSource, []string{}) 54 | defer m.Close() 55 | 56 | // Map of kprobe names from our BPF program to kernel function names, to which to attach. 57 | kprobes := map[string]string{ 58 | "trace_req_start": "blk_account_io_start", 59 | "trace_req_completion": "blk_account_io_completion", 60 | } 61 | 62 | // Load kprobes and attach them to kernel functions 63 | for kpName, fnName := range kprobes { 64 | if kp, err := m.LoadKprobe(kpName); err == nil { 65 | if err := m.AttachKprobe(fnName, kp, 10); err != nil { 66 | fmt.Fprintf(os.Stderr, "Failed to attach %q to %q: %s\n", kpName, fnName, err) 67 | os.Exit(1) 68 | } 69 | } else { 70 | fmt.Fprintf(os.Stderr, "Failed to load %q: %s\n", kpName, err) 71 | os.Exit(1) 72 | } 73 | } 74 | 75 | prometheus.MustRegister(newExporter(m)) 76 | 77 | landingConfig := web.LandingConfig{ 78 | Name: "eBPF Exporter", 79 | Description: "eBPF Exporter", 80 | Version: version.Info(), 81 | Links: []web.LandingLinks{ 82 | { 83 | Address: "/metrics", 84 | Text: "Metrics", 85 | }, 86 | }, 87 | } 88 | landingPage, err := web.NewLandingPage(landingConfig) 89 | if err != nil { 90 | logger.Error(err.Error()) 91 | os.Exit(1) 92 | } 93 | http.Handle("/", landingPage) 94 | http.Handle("/metrics", promhttp.Handler()) 95 | 96 | server := &http.Server{} 97 | if err := web.ListenAndServe(server, toolkitFlags, logger); err != nil { 98 | logger.Error(err.Error()) 99 | os.Exit(1) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /bpf.go: -------------------------------------------------------------------------------- 1 | // ebpf_exporter - A Prometheus exporter for Linux block IO statistics. 2 | // 3 | // Copyright 2018 Daniel Swarbrick 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package main 17 | 18 | const bpfSource string = ` 19 | #include 20 | #include 21 | #include 22 | 23 | typedef struct disk_key { 24 | char disk[DISK_NAME_LEN]; // 32 bytes 25 | u8 req_op; 26 | u64 slot; 27 | } disk_key_t; // 48 bytes, with padding 28 | 29 | const u8 max_io_lat_slot = 28; // log2 range 1 us to ~2 mins 30 | const u8 max_io_req_sz_slot = 16; // log2 range 1 KiB to 32 MiB 31 | 32 | // Hash to temporily hold the start time of each bio request - macro for 33 | // BPF_TABLE("hash", _key_type, u64, _name, 10240). Increase if you expect 34 | // more than 10K IO requests in flight. 35 | BPF_HASH(start, struct request *); 36 | 37 | // Histograms to hold IO request latency / size bucket values - macro for 38 | // BPF_TABLE("histogram", _key_type, u64, _name, _size). Total number of 39 | // buckets are shared amongst all devices and all request operation types. 40 | // Unlike Prometheus histograms, these are sparse, so will only use a bucket 41 | // if required. Since most request operations will be read or write, a good 42 | // rule of thumb is: num_devices * 2 req_op types * 20 buckets each. Bear in 43 | // mind that the amount of memory used will be (sizeof(_key_type) + 44 | // sizeof(u64)) * _size, so the following will use 560 KiB each. 45 | BPF_HISTOGRAM(io_lat, disk_key_t, 10240); 46 | BPF_HISTOGRAM(io_req_sz, disk_key_t, 10240); 47 | 48 | // Record start time of a request 49 | int trace_req_start(struct pt_regs *ctx, struct request *req) 50 | { 51 | u64 ts = bpf_ktime_get_ns(); 52 | start.update(&req, &ts); 53 | return 0; 54 | } 55 | 56 | // Calculate request duration and store in appropriate histogram bucket 57 | int trace_req_completion(struct pt_regs *ctx, struct request *req, unsigned int bytes) 58 | { 59 | u64 *tsp, delta, slot; 60 | u8 req_op; 61 | 62 | // Fetch timestamp and calculate delta 63 | tsp = start.lookup(&req); 64 | if (tsp == 0) { 65 | return 0; // missed issue 66 | } 67 | 68 | // Request duration, in microseconds 69 | delta = (bpf_ktime_get_ns() - *tsp) / 1000; 70 | 71 | // Request operation, e.g. REQ_OP_READ, REQ_OP_WRITE, etc. 72 | req_op = req->cmd_flags & REQ_OP_MASK; 73 | 74 | // Latency histogram key 75 | slot = bpf_log2l(delta); 76 | if (slot >= max_io_lat_slot) 77 | slot = max_io_lat_slot - 1; 78 | disk_key_t lat_key = {.slot = slot, .req_op = req_op}; 79 | bpf_probe_read(&lat_key.disk, sizeof(lat_key.disk), req->rq_disk->disk_name); 80 | 81 | // Request size histogram key 82 | slot = bpf_log2(bytes / 1024); 83 | if (slot >= max_io_req_sz_slot) 84 | slot = max_io_req_sz_slot - 1; 85 | disk_key_t req_sz_key = {.slot = slot, .req_op = req_op}; 86 | bpf_probe_read(&req_sz_key.disk, sizeof(req_sz_key.disk), req->rq_disk->disk_name); 87 | 88 | io_lat.increment(lat_key); 89 | io_req_sz.increment(req_sz_key); 90 | 91 | start.delete(&req); 92 | return 0; 93 | } 94 | ` 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ebpf_exporter 2 | 3 | ebpf_exporter is an experimental Prometheus exporter which uses eBPF kprobes to efficiently record 4 | a histogram of Linux bio request latencies and sizes. 5 | 6 | The included BPF program is loosely based on the examples shipped with [IO Visor's BPF Compiler 7 | Collection](https://github.com/iovisor/bcc), specifically the bitehist and disksnoop examples. 8 | 9 | ## Sample Output 10 | 11 | Linux bio request latencies for each block device are recorded in log2 buckets separately for each 12 | request operation type (read, write, flush, discard, etc), in microseconds. This should cover use 13 | cases ranging from high speed flash-based devices, to legacy HDD devices. 14 | 15 | ``` 16 | # HELP ebpf_bio_req_latency A histogram of bio request latencies in microseconds. 17 | # TYPE ebpf_bio_req_latency histogram 18 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="1"} 0 19 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="2"} 0 20 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="4"} 0 21 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="8"} 0 22 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="16"} 0 23 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="32"} 0 24 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="64"} 40 25 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="128"} 219 26 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="256"} 335 27 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="512"} 363 28 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="1024"} 428 29 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="2048"} 1649 30 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="4096"} 3498 31 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="8192"} 3614 32 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="16384"} 3760 33 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="32768"} 3777 34 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="65536"} 3780 35 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="131072"} 3780 36 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="262144"} 3780 37 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="524288"} 3780 38 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="1.048576e+06"} 3780 39 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="2.097152e+06"} 3780 40 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="4.194304e+06"} 3780 41 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="8.388608e+06"} 3780 42 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="1.6777216e+07"} 3780 43 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="3.3554432e+07"} 3780 44 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="6.7108864e+07"} 3780 45 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="1.34217728e+08"} 3780 46 | ebpf_bio_req_latency_bucket{device="sda",operation="write",le="+Inf"} 3780 47 | ebpf_bio_req_latency_sum{device="sda",operation="write"} 1.4306176e+07 48 | ebpf_bio_req_latency_count{device="sda",operation="write"} 3780 49 | ``` 50 | 51 | Request sizes (in KiB) are also recorded in log2 buckets for each device: 52 | 53 | ``` 54 | # HELP ebpf_bio_req_size A histogram of bio request sizes in KiB. 55 | # TYPE ebpf_bio_req_size histogram 56 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="1"} 8 57 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="2"} 8 58 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="4"} 2450 59 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="8"} 3050 60 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="16"} 3347 61 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="32"} 3602 62 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="64"} 3698 63 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="128"} 3714 64 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="256"} 3732 65 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="512"} 3777 66 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="1024"} 3780 67 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="2048"} 3780 68 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="4096"} 3780 69 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="8192"} 3780 70 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="16384"} 3780 71 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="32768"} 3780 72 | ebpf_bio_req_size_bucket{device="sda",operation="write",le="+Inf"} 3780 73 | ebpf_bio_req_size_sum{device="sda",operation="write"} 66400 74 | ebpf_bio_req_size_count{device="sda",operation="write"} 3780 75 | ``` 76 | 77 | Note that histograms will only be exposed for devices that have actually performed IO since the BPF 78 | program was loaded. If a device is only performing writes, no histogram will be present for reads, 79 | and vice versa. 80 | 81 | ## Grafana Panel Samples 82 | 83 | Grafana 5.1 and later supports Prometheus histograms, either as bar / line / point graphs, or as 84 | heatmaps. See Grafana's [heatmap panel](http://docs.grafana.org/features/panels/heatmap/) guide for 85 | more information. 86 | 87 | ![IO request latency histogram](img/io-req-latency-hist.png) 88 | 89 | ![IO request latency heatmap](img/io-req-latency-heatmap.png) 90 | -------------------------------------------------------------------------------- /collector.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | // ebpf_exporter - A Prometheus exporter for Linux block IO statistics. 4 | // 5 | // Copyright 2018 Daniel Swarbrick 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "bytes" 22 | "encoding/binary" 23 | "math" 24 | 25 | "github.com/iovisor/gobpf/bcc" 26 | "github.com/prometheus/client_golang/prometheus" 27 | ) 28 | 29 | const ( 30 | latTableLen = 28 // Must match max_io_lat_slot in BPF program. 31 | reqSzTableLen = 16 // Must match max_io_req_sz_slot in BPF program. 32 | 33 | // cf. 34 | DISK_NAME_LEN = 32 35 | 36 | // Linux req_opf enums, cf. 37 | REQ_OP_READ = 0 38 | REQ_OP_WRITE = 1 39 | REQ_OP_FLUSH = 2 40 | REQ_OP_DISCARD = 3 41 | REQ_OP_ZONE_REPORT = 4 42 | REQ_OP_SECURE_ERASE = 5 43 | REQ_OP_ZONE_RESET = 6 44 | REQ_OP_WRITE_SAME = 7 45 | REQ_OP_WRITE_ZEROES = 9 46 | REQ_OP_SCSI_IN = 32 47 | REQ_OP_SCSI_OUT = 33 48 | REQ_OP_DRV_IN = 34 49 | REQ_OP_DRV_OUT = 35 50 | ) 51 | 52 | var ( 53 | // Map of request operation enums to human-readable strings. This map does not include all 54 | // possible request operations, but covers the most commonly observed ones. 55 | reqOpStrings = map[uint8]string{ 56 | REQ_OP_READ: "read", 57 | REQ_OP_WRITE: "write", 58 | REQ_OP_FLUSH: "flush", 59 | REQ_OP_DISCARD: "discard", 60 | REQ_OP_WRITE_SAME: "write_same", 61 | REQ_OP_WRITE_ZEROES: "write_zeroes", 62 | } 63 | ) 64 | 65 | type exporter struct { 66 | bpfMod *bcc.Module 67 | ioLat *bcc.Table 68 | ioReqSz *bcc.Table 69 | latency *prometheus.Desc 70 | reqSize *prometheus.Desc 71 | tableEntries *prometheus.GaugeVec 72 | } 73 | 74 | func newExporter(m *bcc.Module) *exporter { 75 | e := exporter{ 76 | bpfMod: m, 77 | ioLat: bcc.NewTable(m.TableId("io_lat"), m), 78 | ioReqSz: bcc.NewTable(m.TableId("io_req_sz"), m), 79 | latency: prometheus.NewDesc( 80 | prometheus.BuildFQName(namespace, "bio", "req_latency"), 81 | "A histogram of bio request latencies in microseconds.", 82 | []string{"device", "operation"}, 83 | nil, 84 | ), 85 | reqSize: prometheus.NewDesc( 86 | prometheus.BuildFQName(namespace, "bio", "req_size"), 87 | "A histogram of bio request sizes in KiB.", 88 | []string{"device", "operation"}, 89 | nil, 90 | ), 91 | tableEntries: prometheus.NewGaugeVec( 92 | prometheus.GaugeOpts{ 93 | Namespace: namespace, 94 | Subsystem: "bio", 95 | Name: "bpf_table_entries", 96 | Help: "The number of BPF table entries used.", 97 | }, 98 | []string{"table"}, 99 | ), 100 | } 101 | 102 | prometheus.MustRegister(e.tableEntries) 103 | 104 | return &e 105 | } 106 | 107 | func (e *exporter) Collect(ch chan<- prometheus.Metric) { 108 | var ( 109 | n uint 110 | tbl map[string]map[uint8][]uint64 111 | ) 112 | 113 | n, tbl = decodeTable(e.ioLat, latTableLen) 114 | e.tableEntries.WithLabelValues("req_latency").Set(float64(n)) 115 | e.emit(ch, e.latency, tbl) 116 | 117 | n, tbl = decodeTable(e.ioReqSz, reqSzTableLen) 118 | e.tableEntries.WithLabelValues("req_size").Set(float64(n)) 119 | e.emit(ch, e.reqSize, tbl) 120 | } 121 | 122 | func (e *exporter) Describe(ch chan<- *prometheus.Desc) { 123 | ch <- e.latency 124 | ch <- e.reqSize 125 | } 126 | 127 | func (e *exporter) emit(ch chan<- prometheus.Metric, hist *prometheus.Desc, devBuckets map[string]map[uint8][]uint64) { 128 | for devName, reqs := range devBuckets { 129 | for reqOp, bpfBuckets := range reqs { 130 | var ( 131 | count uint64 132 | sum float64 133 | ) 134 | 135 | // Skip unrecognized request operations. 136 | if _, ok := reqOpStrings[reqOp]; !ok { 137 | continue 138 | } 139 | 140 | promBuckets := make(map[float64]uint64) 141 | 142 | for k, v := range bpfBuckets { 143 | // Prometheus histograms are cumulative, so count must be a running total of 144 | // previous buckets also. 145 | count += v 146 | 147 | // Sum will not be completely accurate, since the BPF program already discarded 148 | // some resolution when storing occurrences of values in log2 buckets. Count and 149 | // sum are required however to calculate an average from a histogram. 150 | exp2 := math.Exp2(float64(k)) 151 | sum += exp2 * float64(v) 152 | 153 | promBuckets[exp2] = count 154 | } 155 | 156 | ch <- prometheus.MustNewConstHistogram(hist, 157 | count, 158 | sum, 159 | promBuckets, 160 | devName, reqOpStrings[reqOp], 161 | ) 162 | } 163 | } 164 | } 165 | 166 | // decodeTable decodes a BPF table and returns a per-device map of values as ordered buckets. 167 | func decodeTable(table *bcc.Table, tableSize uint) (uint, map[string]map[uint8][]uint64) { 168 | var ( 169 | numEntries uint 170 | 171 | // Struct must match disk_key_t in BPF program 172 | key struct { 173 | Disk [DISK_NAME_LEN]byte 174 | Op uint8 175 | _ [7]byte // padding 176 | Slot uint64 177 | } 178 | ) 179 | 180 | devBuckets := make(map[string]map[uint8][]uint64) 181 | 182 | // bcc.Table.Iter() returns unsorted entries, so write the decoded values into an order- 183 | // preserving slice. 184 | for it := table.Iter(); it.Next(); { 185 | if err := binary.Read(bytes.NewReader(it.Key()), binary.LittleEndian, &key); err != nil { 186 | continue 187 | } 188 | 189 | // key.Disk is a null-terminated char array. 190 | devName := string(key.Disk[:bytes.IndexByte(key.Disk[:], 0)]) 191 | 192 | // First time seeing this device, create map for request operations. 193 | if _, ok := devBuckets[devName]; !ok { 194 | devBuckets[devName] = make(map[uint8][]uint64) 195 | } 196 | 197 | // First time seeing this req op for this device, create slice for buckets. 198 | if _, ok := devBuckets[devName][key.Op]; !ok { 199 | devBuckets[devName][key.Op] = make([]uint64, tableSize) 200 | } 201 | 202 | devBuckets[devName][key.Op][key.Slot] = binary.LittleEndian.Uint64(it.Leaf()) 203 | numEntries++ 204 | } 205 | 206 | return numEntries, devBuckets 207 | } 208 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY= 2 | github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= 3 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= 4 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 5 | github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc= 6 | github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= 7 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 8 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 9 | github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= 10 | github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 11 | github.com/coreos/go-systemd/v22 v22.6.0 h1:aGVa/v8B7hpb0TKl0MWoAavPDmHvobFe5R5zn0bCJWo= 12 | github.com/coreos/go-systemd/v22 v22.6.0/go.mod h1:iG+pp635Fo7ZmV/j14KUcmEyWF+0X7Lua8rrTWzYgWU= 13 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 14 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 15 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 16 | github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= 17 | github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= 18 | github.com/iovisor/gobpf v0.2.0 h1:34xkQxft+35GagXBk3n23eqhm0v7q0ejeVirb8sqEOQ= 19 | github.com/iovisor/gobpf v0.2.0/go.mod h1:WSY9Jj5RhdgC3ci1QaacvbFdQ8cbrEjrpiZbLHLt2s4= 20 | github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= 21 | github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= 22 | github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= 23 | github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= 24 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 25 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 26 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 27 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 28 | github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= 29 | github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 30 | github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= 31 | github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= 32 | github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ= 33 | github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE= 34 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= 35 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= 36 | github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= 37 | github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 38 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 39 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 40 | github.com/prometheus/client_golang v1.21.1 h1:DOvXXTqVzvkIewV/CDPFdejpMCGeMcbGCQ8YOmu+Ibk= 41 | github.com/prometheus/client_golang v1.21.1/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg= 42 | github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= 43 | github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= 44 | github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs= 45 | github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA= 46 | github.com/prometheus/exporter-toolkit v0.14.1 h1:uKPE4ewweVRWFainwvAcHs3uw15pjw2dk3I7b+aNo9o= 47 | github.com/prometheus/exporter-toolkit v0.14.1/go.mod h1:di7yaAJiaMkcjcz48f/u4yRPwtyuxTU5Jr4EnM2mhtQ= 48 | github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= 49 | github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= 50 | github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= 51 | github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= 52 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 53 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 54 | github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= 55 | github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= 56 | github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= 57 | github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= 58 | go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= 59 | go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= 60 | golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4= 61 | golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc= 62 | golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= 63 | golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= 64 | golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI= 65 | golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU= 66 | golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= 67 | golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 68 | golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= 69 | golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 70 | golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= 71 | golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= 72 | google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc= 73 | google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= 74 | gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= 75 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 76 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 77 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 78 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 79 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 80 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 81 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 82 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------