├── .gitignore ├── vendor ├── golang.org │ └── x │ │ └── sys │ │ ├── unix │ │ ├── .gitignore │ │ ├── asm.s │ │ ├── export_test.go │ │ ├── constants.go │ │ ├── syscall_no_getwd.go │ │ ├── zsysnum_solaris_amd64.go │ │ ├── env_unset.go │ │ ├── flock_linux_32bit.go │ │ ├── syscall_freebsd_test.go │ │ ├── asm_solaris_amd64.s │ │ ├── gccgo_linux_amd64.go │ │ ├── race0.go │ │ ├── mmap_unix_test.go │ │ ├── env_unix.go │ │ ├── asm_linux_arm64.s │ │ ├── str.go │ │ ├── race.go │ │ ├── asm_linux_ppc64x.s │ │ ├── asm_linux_arm.s │ │ ├── asm_freebsd_arm.s │ │ ├── asm_netbsd_arm.s │ │ ├── asm_darwin_386.s │ │ ├── asm_freebsd_386.s │ │ ├── asm_netbsd_386.s │ │ ├── asm_openbsd_386.s │ │ ├── asm_darwin_amd64.s │ │ ├── asm_dragonfly_386.s │ │ ├── asm_freebsd_amd64.s │ │ ├── asm_linux_amd64.s │ │ ├── asm_netbsd_amd64.s │ │ ├── asm_openbsd_amd64.s │ │ ├── asm_dragonfly_amd64.s │ │ ├── asm_darwin_arm.s │ │ ├── asm_darwin_arm64.s │ │ ├── flock.go │ │ ├── mksysnum_darwin.pl │ │ ├── asm_linux_386.s │ │ ├── syscall_bsd_test.go │ │ ├── syscall_solaris_amd64.go │ │ ├── gccgo_c.c │ │ ├── syscall_openbsd_amd64.go │ │ ├── sockcmsg_linux.go │ │ ├── syscall_netbsd_386.go │ │ ├── syscall_netbsd_arm.go │ │ ├── syscall_openbsd_386.go │ │ ├── syscall_netbsd_amd64.go │ │ ├── mksysnum_dragonfly.pl │ │ ├── mksysnum_openbsd.pl │ │ ├── syscall_test.go │ │ ├── mksysnum_netbsd.pl │ │ ├── mksysnum_linux.pl │ │ ├── gccgo.go │ │ ├── syscall_freebsd_amd64.go │ │ ├── syscall_dragonfly_amd64.go │ │ ├── syscall_freebsd_arm.go │ │ ├── syscall_freebsd_386.go │ │ ├── syscall_dragonfly_386.go │ │ ├── mksysnum_freebsd.pl │ │ ├── syscall_darwin_arm.go │ │ ├── syscall_darwin_arm64.go │ │ ├── syscall_darwin_386.go │ │ ├── syscall_darwin_amd64.go │ │ └── syscall.go │ │ ├── PATENTS │ │ └── LICENSE ├── github.com │ ├── Sirupsen │ │ └── logrus │ │ │ ├── .gitignore │ │ │ ├── .travis.yml │ │ │ ├── terminal_bsd.go │ │ │ ├── terminal_solaris.go │ │ │ ├── terminal_linux.go │ │ │ ├── terminal_notwindows.go │ │ │ ├── doc.go │ │ │ ├── writer.go │ │ │ ├── terminal_windows.go │ │ │ ├── json_formatter.go │ │ │ ├── LICENSE │ │ │ ├── hooks.go │ │ │ ├── formatter.go │ │ │ ├── entry_test.go │ │ │ ├── CHANGELOG.md │ │ │ ├── text_formatter_test.go │ │ │ ├── formatter_bench_test.go │ │ │ └── hook_test.go │ ├── lib │ │ └── pq │ │ │ ├── .gitignore │ │ │ ├── oid │ │ │ ├── doc.go │ │ │ └── gen.go │ │ │ ├── user_posix.go │ │ │ ├── user_windows.go │ │ │ ├── LICENSE.md │ │ │ ├── conn_xact_test.go │ │ │ ├── CONTRIBUTING.md │ │ │ ├── url_test.go │ │ │ ├── buf.go │ │ │ ├── url.go │ │ │ └── README.md │ ├── prometheus │ │ ├── client_golang │ │ │ ├── prometheus │ │ │ │ ├── .gitignore │ │ │ │ ├── metric_test.go │ │ │ │ ├── go_collector.go │ │ │ │ ├── README.md │ │ │ │ ├── process_collector_test.go │ │ │ │ ├── counter_test.go │ │ │ │ ├── example_selfcollector_test.go │ │ │ │ ├── push.go │ │ │ │ ├── go_collector_test.go │ │ │ │ └── example_memstats_test.go │ │ │ ├── model │ │ │ │ ├── model.go │ │ │ │ ├── labelvalue.go │ │ │ │ ├── samplevalue.go │ │ │ │ ├── labelname_test.go │ │ │ │ ├── labelvalue_test.go │ │ │ │ ├── sample.go │ │ │ │ ├── labelset.go │ │ │ │ ├── timestamp_test.go │ │ │ │ ├── sample_test.go │ │ │ │ └── fingerprinting.go │ │ │ ├── NOTICE │ │ │ └── text │ │ │ │ └── proto.go │ │ ├── log │ │ │ ├── NOTICE │ │ │ ├── AUTHORS.md │ │ │ ├── README.md │ │ │ ├── CONTRIBUTING.md │ │ │ └── log_test.go │ │ ├── procfs │ │ │ ├── .travis.yml │ │ │ ├── Makefile │ │ │ ├── NOTICE │ │ │ ├── stat_test.go │ │ │ ├── fs_test.go │ │ │ ├── README.md │ │ │ ├── AUTHORS.md │ │ │ ├── proc_limits_test.go │ │ │ ├── CONTRIBUTING.md │ │ │ ├── proc_io_test.go │ │ │ ├── fs.go │ │ │ ├── mdstat_test.go │ │ │ ├── proc_io.go │ │ │ ├── stat.go │ │ │ ├── doc.go │ │ │ └── proc_stat_test.go │ │ └── client_model │ │ │ └── NOTICE │ ├── matttproud │ │ └── golang_protobuf_extensions │ │ │ ├── NOTICE │ │ │ └── pbutil │ │ │ ├── doc.go │ │ │ ├── encode.go │ │ │ └── decode.go │ ├── beorn7 │ │ └── perks │ │ │ ├── LICENSE │ │ │ └── quantile │ │ │ └── bench_test.go │ └── golang │ │ └── protobuf │ │ ├── LICENSE │ │ └── proto │ │ ├── Makefile │ │ ├── size2_test.go │ │ └── message_set_test.go ├── gopkg.in │ └── yaml.v2 │ │ ├── suite_test.go │ │ ├── LICENSE.libyaml │ │ ├── writerc.go │ │ └── sorter.go └── bitbucket.org │ └── ww │ └── goautoneg │ ├── Makefile │ ├── autoneg_test.go │ └── README.txt ├── Godeps ├── Readme └── Godeps.json ├── .travis.yml ├── queries.yaml ├── queries.go ├── LICENSE └── metrics ├── base.go ├── buffer.go ├── custom_query.go └── slow_query.go /.gitignore: -------------------------------------------------------------------------------- 1 | postgresql_exporter 2 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/.gitignore: -------------------------------------------------------------------------------- 1 | _obj/ 2 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/.gitignore: -------------------------------------------------------------------------------- 1 | logrus 2 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/.gitignore: -------------------------------------------------------------------------------- 1 | .db 2 | *.test 3 | *~ 4 | *.swp 5 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/.gitignore: -------------------------------------------------------------------------------- 1 | command-line-arguments.test 2 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2012 Matt T. Proud (matt.proud@gmail.com) 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/log/NOTICE: -------------------------------------------------------------------------------- 1 | Standard logging library for Go-based Prometheus components. 2 | Copyright 2015 The Prometheus Authors 3 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | go: 4 | - 1.3 5 | - 1.4 6 | - 1.5 7 | - tip 8 | -------------------------------------------------------------------------------- /Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/Makefile: -------------------------------------------------------------------------------- 1 | ci: 2 | ! gofmt -l *.go | read nothing 3 | go vet 4 | go test -v ./... 5 | go get github.com/golang/lint/golint 6 | golint *.go 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | env: 4 | - GO15VENDOREXPERIMENT=1 5 | 6 | go: 7 | - 1.5.3 8 | - 1.6 9 | - tip 10 | 11 | install: true 12 | 13 | script: go install -v 14 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/oid/doc.go: -------------------------------------------------------------------------------- 1 | // Package oid contains OID constants 2 | // as defined by the Postgres server. 3 | package oid 4 | 5 | // Oid is a Postgres Object ID. 6 | type Oid uint32 7 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.3 4 | - 1.4 5 | - 1.5 6 | - tip 7 | install: 8 | - go get -t ./... 9 | script: GOMAXPROCS=4 GORACE="halt_on_error=1" go test -race -v ./... 10 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/NOTICE: -------------------------------------------------------------------------------- 1 | Data model artifacts for Prometheus. 2 | Copyright 2012-2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/suite_test.go: -------------------------------------------------------------------------------- 1 | package yaml_test 2 | 3 | import ( 4 | . "gopkg.in/check.v1" 5 | "testing" 6 | ) 7 | 8 | func Test(t *testing.T) { TestingT(t) } 9 | 10 | type S struct{} 11 | 12 | var _ = Suite(&S{}) 13 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_bsd.go: -------------------------------------------------------------------------------- 1 | // +build darwin freebsd openbsd netbsd dragonfly 2 | 3 | package logrus 4 | 5 | import "syscall" 6 | 7 | const ioctlReadTermios = syscall.TIOCGETA 8 | 9 | type Termios syscall.Termios 10 | -------------------------------------------------------------------------------- /queries.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: assets_by_kind_count 3 | help: Count of assets by kind. 4 | query: "SELECT COUNT(*), kind FROM assets GROUP BY kind" 5 | 6 | - name: assets_count 7 | help: Overal count of assets. 8 | query: "SELECT COUNT(*) FROM assets" 9 | 10 | -------------------------------------------------------------------------------- /vendor/bitbucket.org/ww/goautoneg/Makefile: -------------------------------------------------------------------------------- 1 | include $(GOROOT)/src/Make.inc 2 | 3 | TARG=bitbucket.org/ww/goautoneg 4 | GOFILES=autoneg.go 5 | 6 | include $(GOROOT)/src/Make.pkg 7 | 8 | format: 9 | gofmt -w *.go 10 | 11 | docs: 12 | gomake clean 13 | godoc ${TARG} > README.txt 14 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/NOTICE: -------------------------------------------------------------------------------- 1 | procfs provides functions to retrieve system, kernel and process 2 | metrics from the pseudo-filesystem proc. 3 | 4 | Copyright 2014-2015 The Prometheus Authors 5 | 6 | This product includes software developed at 7 | SoundCloud Ltd. (http://soundcloud.com/). 8 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | TEXT ·use(SB),NOSPLIT,$0 10 | RET 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 | 7 | package unix 8 | 9 | var Itoa = itoa 10 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/stat_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import "testing" 4 | 5 | func TestStat(t *testing.T) { 6 | s, err := FS("fixtures").NewStat() 7 | if err != nil { 8 | t.Fatal(err) 9 | } 10 | 11 | if want, have := int64(1418183276), s.BootTime; want != have { 12 | t.Errorf("want boot time %d, have %d", want, have) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_solaris.go: -------------------------------------------------------------------------------- 1 | // +build solaris 2 | 3 | package logrus 4 | 5 | import ( 6 | "os" 7 | 8 | "golang.org/x/sys/unix" 9 | ) 10 | 11 | // IsTerminal returns true if the given file descriptor is a terminal. 12 | func IsTerminal() bool { 13 | _, err := unix.IoctlGetTermios(int(os.Stdout.Fd()), unix.TCGETA) 14 | return err == nil 15 | } 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 | 7 | package unix 8 | 9 | const ( 10 | R_OK = 0x4 11 | W_OK = 0x2 12 | X_OK = 0x1 13 | ) 14 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/log/AUTHORS.md: -------------------------------------------------------------------------------- 1 | The Prometheus project was started by Matt T. Proud (emeritus) and 2 | Julius Volz in 2012. 3 | 4 | Maintainers of this repository: 5 | 6 | * Julius Volz 7 | 8 | The following individuals have contributed code to this repository 9 | (listed in alphabetical order): 10 | 11 | * Julius Volz 12 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_linux.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2013 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | package logrus 7 | 8 | import "syscall" 9 | 10 | const ioctlReadTermios = syscall.TCGETS 11 | 12 | type Termios syscall.Termios 13 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/user_posix.go: -------------------------------------------------------------------------------- 1 | // Package pq is a pure Go Postgres driver for the database/sql package. 2 | 3 | // +build darwin freebsd linux nacl netbsd openbsd solaris 4 | 5 | package pq 6 | 7 | import "os/user" 8 | 9 | func userCurrent() (string, error) { 10 | u, err := user.Current() 11 | if err != nil { 12 | return "", err 13 | } 14 | return u.Username, nil 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/fs_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import "testing" 4 | 5 | func TestNewFS(t *testing.T) { 6 | if _, err := NewFS("foobar"); err == nil { 7 | t.Error("want NewFS to fail for non-existing mount point") 8 | } 9 | 10 | if _, err := NewFS("procfs.go"); err == nil { 11 | t.Error("want NewFS to fail if mount point is not a directory") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_no_getwd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build dragonfly freebsd netbsd openbsd 6 | 7 | package unix 8 | 9 | const ImplementsGetwd = false 10 | 11 | func Getwd() (string, error) { return "", ENOTSUP } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/zsysnum_solaris_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,solaris 6 | 7 | package unix 8 | 9 | // TODO(aram): remove these before Go 1.3. 10 | const ( 11 | SYS_EXECVE = 59 12 | SYS_FCNTL = 62 13 | ) 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/env_unset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.4 6 | 7 | package unix 8 | 9 | import "syscall" 10 | 11 | func Unsetenv(key string) error { 12 | // This was added in Go 1.4. 13 | return syscall.Unsetenv(key) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/flock_linux_32bit.go: -------------------------------------------------------------------------------- 1 | // +build linux,386 linux,arm 2 | 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | package unix 8 | 9 | func init() { 10 | // On 32-bit Linux systems, the fcntl syscall that matches Go's 11 | // Flock_t type is SYS_FCNTL64, not SYS_FCNTL. 12 | fcntl64Syscall = SYS_FCNTL64 13 | } 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_freebsd_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build freebsd 6 | 7 | package unix_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "golang.org/x/sys/unix" 13 | ) 14 | 15 | func TestSysctUint64(t *testing.T) { 16 | _, err := unix.SysctlUint64("vm.max_kernel_address") 17 | if err != nil { 18 | t.Fatal(err) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/log/README.md: -------------------------------------------------------------------------------- 1 | # Prometheus Logging Library 2 | 3 | **Deprecated: This repository is superseded by [common/log](https://github.com/prometheus/common/tree/master/log).** 4 | 5 | Standard logging library for Go-based Prometheus components. 6 | 7 | This library wraps 8 | [https://github.com/Sirupsen/logrus](https://github.com/Sirupsen/logrus) in 9 | order to add line:file annotations to log lines, as well as to provide common 10 | command-line flags for Prometheus components using it. 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_solaris_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System calls for amd64, Solaris are implemented in runtime/syscall_solaris.go 11 | // 12 | 13 | TEXT ·sysvicall6(SB),NOSPLIT,$0-64 14 | JMP syscall·sysvicall6(SB) 15 | 16 | TEXT ·rawSysvicall6(SB),NOSPLIT,$0-64 17 | JMP syscall·rawSysvicall6(SB) 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build gccgo,linux,amd64 6 | 7 | package unix 8 | 9 | import "syscall" 10 | 11 | //extern gettimeofday 12 | func realGettimeofday(*Timeval, *byte) int32 13 | 14 | func gettimeofday(tv *Timeval) (err syscall.Errno) { 15 | r := realGettimeofday(tv, nil) 16 | if r < 0 { 17 | return syscall.GetErrno() 18 | } 19 | return 0 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/README.md: -------------------------------------------------------------------------------- 1 | # procfs 2 | 3 | This procfs package provides functions to retrieve system, kernel and process 4 | metrics from the pseudo-filesystem proc. 5 | 6 | *WARNING*: This package is a work in progress. Its API may still break in 7 | backwards-incompatible ways without warnings. Use it at your own risk. 8 | 9 | [![GoDoc](https://godoc.org/github.com/prometheus/procfs?status.png)](https://godoc.org/github.com/prometheus/procfs) 10 | [![Build Status](https://travis-ci.org/prometheus/procfs.svg?branch=master)](https://travis-ci.org/prometheus/procfs) 11 | -------------------------------------------------------------------------------- /queries.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io/ioutil" 5 | "os" 6 | 7 | "github.com/prometheus/log" 8 | "gopkg.in/yaml.v2" 9 | 10 | "github.com/mc2soft/postgresql_exporter/metrics" 11 | ) 12 | 13 | func parseQueries(queriesPath string) (cq []metrics.CustomQuery) { 14 | if queriesPath == "" { 15 | return 16 | } 17 | 18 | f, err := os.Open(queriesPath) 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | defer f.Close() 23 | 24 | b, err := ioutil.ReadAll(f) 25 | if err != nil { 26 | log.Fatal(err) 27 | } 28 | 29 | err = yaml.Unmarshal(b, &cq) 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | 34 | return 35 | } 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/race0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin,!race linux,!race freebsd,!race netbsd openbsd solaris dragonfly 6 | 7 | package unix 8 | 9 | import ( 10 | "unsafe" 11 | ) 12 | 13 | const raceenabled = false 14 | 15 | func raceAcquire(addr unsafe.Pointer) { 16 | } 17 | 18 | func raceReleaseMerge(addr unsafe.Pointer) { 19 | } 20 | 21 | func raceReadRange(addr unsafe.Pointer, len int) { 22 | } 23 | 24 | func raceWriteRange(addr unsafe.Pointer, len int) { 25 | } 26 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/mmap_unix_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 | 7 | package unix_test 8 | 9 | import ( 10 | "testing" 11 | 12 | "golang.org/x/sys/unix" 13 | ) 14 | 15 | func TestMmap(t *testing.T) { 16 | b, err := unix.Mmap(-1, 0, unix.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE) 17 | if err != nil { 18 | t.Fatalf("Mmap: %v", err) 19 | } 20 | if err := unix.Munmap(b); err != nil { 21 | t.Fatalf("Munmap: %v", err) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/env_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 | 7 | // Unix environment variables. 8 | 9 | package unix 10 | 11 | import "syscall" 12 | 13 | func Getenv(key string) (value string, found bool) { 14 | return syscall.Getenv(key) 15 | } 16 | 17 | func Setenv(key, value string) error { 18 | return syscall.Setenv(key, value) 19 | } 20 | 21 | func Clearenv() { 22 | syscall.Clearenv() 23 | } 24 | 25 | func Environ() []string { 26 | return syscall.Environ() 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_notwindows.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2011 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build linux darwin freebsd openbsd netbsd dragonfly 7 | 8 | package logrus 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | // IsTerminal returns true if stderr's file descriptor is a terminal. 16 | func IsTerminal() bool { 17 | fd := syscall.Stderr 18 | var termios Termios 19 | _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0) 20 | return err == 0 21 | } 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_linux_arm64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build linux 6 | // +build arm64 7 | // +build !gccgo 8 | 9 | #include "textflag.h" 10 | 11 | // Just jump to package syscall's implementation for all these functions. 12 | // The runtime may know about them. 13 | 14 | TEXT ·Syscall(SB),NOSPLIT,$0-56 15 | B syscall·Syscall(SB) 16 | 17 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 18 | B syscall·Syscall6(SB) 19 | 20 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 21 | B syscall·RawSyscall(SB) 22 | 23 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 24 | B syscall·RawSyscall6(SB) 25 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package logrus is a structured logger for Go, completely API compatible with the standard library logger. 3 | 4 | 5 | The simplest way to use Logrus is simply the package-level exported logger: 6 | 7 | package main 8 | 9 | import ( 10 | log "github.com/Sirupsen/logrus" 11 | ) 12 | 13 | func main() { 14 | log.WithFields(log.Fields{ 15 | "animal": "walrus", 16 | "number": 1, 17 | "size": 10, 18 | }).Info("A walrus appears") 19 | } 20 | 21 | Output: 22 | time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10 23 | 24 | For a full guide visit https://github.com/Sirupsen/logrus 25 | */ 26 | package logrus 27 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/writer.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "bufio" 5 | "io" 6 | "runtime" 7 | ) 8 | 9 | func (logger *Logger) Writer() *io.PipeWriter { 10 | reader, writer := io.Pipe() 11 | 12 | go logger.writerScanner(reader) 13 | runtime.SetFinalizer(writer, writerFinalizer) 14 | 15 | return writer 16 | } 17 | 18 | func (logger *Logger) writerScanner(reader *io.PipeReader) { 19 | scanner := bufio.NewScanner(reader) 20 | for scanner.Scan() { 21 | logger.Print(scanner.Text()) 22 | } 23 | if err := scanner.Err(); err != nil { 24 | logger.Errorf("Error while reading from Writer: %s", err) 25 | } 26 | reader.Close() 27 | } 28 | 29 | func writerFinalizer(writer *io.PipeWriter) { 30 | writer.Close() 31 | } 32 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/str.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 | 7 | package unix 8 | 9 | func itoa(val int) string { // do it here rather than with fmt to avoid dependency 10 | if val < 0 { 11 | return "-" + uitoa(uint(-val)) 12 | } 13 | return uitoa(uint(val)) 14 | } 15 | 16 | func uitoa(val uint) string { 17 | var buf [32]byte // big enough for int64 18 | i := len(buf) - 1 19 | for val >= 10 { 20 | buf[i] = byte(val%10 + '0') 21 | i-- 22 | val /= 10 23 | } 24 | buf[i] = byte(val + '0') 25 | return string(buf[i:]) 26 | } 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/race.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin,race linux,race freebsd,race 6 | 7 | package unix 8 | 9 | import ( 10 | "runtime" 11 | "unsafe" 12 | ) 13 | 14 | const raceenabled = true 15 | 16 | func raceAcquire(addr unsafe.Pointer) { 17 | runtime.RaceAcquire(addr) 18 | } 19 | 20 | func raceReleaseMerge(addr unsafe.Pointer) { 21 | runtime.RaceReleaseMerge(addr) 22 | } 23 | 24 | func raceReadRange(addr unsafe.Pointer, len int) { 25 | runtime.RaceReadRange(addr, len) 26 | } 27 | 28 | func raceWriteRange(addr unsafe.Pointer, len int) { 29 | runtime.RaceWriteRange(addr, len) 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/AUTHORS.md: -------------------------------------------------------------------------------- 1 | The Prometheus project was started by Matt T. Proud (emeritus) and 2 | Julius Volz in 2012. 3 | 4 | Maintainers of this repository: 5 | 6 | * Tobias Schmidt 7 | 8 | The following individuals have contributed code to this repository 9 | (listed in alphabetical order): 10 | 11 | * Armen Baghumian 12 | * Bjoern Rabenstein 13 | * David Cournapeau 14 | * Ji-Hoon, Seol 15 | * Jonas Große Sundrup 16 | * Julius Volz 17 | * Matthias Rampke 18 | * Nicky Gerritsen 19 | * Rémi Audebert 20 | * Tobias Schmidt 21 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_windows.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2011 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build windows 7 | 8 | package logrus 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | var kernel32 = syscall.NewLazyDLL("kernel32.dll") 16 | 17 | var ( 18 | procGetConsoleMode = kernel32.NewProc("GetConsoleMode") 19 | ) 20 | 21 | // IsTerminal returns true if stderr's file descriptor is a terminal. 22 | func IsTerminal() bool { 23 | fd := syscall.Stderr 24 | var st uint32 25 | r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(fd), uintptr(unsafe.Pointer(&st)), 0) 26 | return r != 0 && e == 0 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/model/model.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Package model contains core representation of Prometheus client primitives. 15 | package model 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_linux_ppc64x.s: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build linux 6 | // +build ppc64 ppc64le 7 | // +build !gccgo 8 | 9 | #include "textflag.h" 10 | 11 | // 12 | // System calls for ppc64, Linux 13 | // 14 | 15 | // Just jump to package syscall's implementation for all these functions. 16 | // The runtime may know about them. 17 | 18 | TEXT ·Syscall(SB),NOSPLIT,$0-56 19 | BR syscall·Syscall(SB) 20 | 21 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 22 | BR syscall·Syscall6(SB) 23 | 24 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 25 | BR syscall·RawSyscall(SB) 26 | 27 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 28 | BR syscall·RawSyscall6(SB) 29 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_linux_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System calls for arm, Linux 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | B syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | B syscall·Syscall6(SB) 21 | 22 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 23 | B syscall·RawSyscall(SB) 24 | 25 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 26 | B syscall·RawSyscall6(SB) 27 | 28 | TEXT ·seek(SB),NOSPLIT,$0-32 29 | B syscall·seek(SB) 30 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package pbutil provides record length-delimited Protocol Buffer streaming. 16 | package pbutil 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_freebsd_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for ARM, FreeBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | B syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | B syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | B syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | B syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | B syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_netbsd_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for ARM, NetBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | B syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | B syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | B syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | B syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | B syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_darwin_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, Darwin 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_freebsd_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, FreeBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_netbsd_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, NetBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_openbsd_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, OpenBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_darwin_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, Darwin 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-104 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_dragonfly_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, FreeBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-32 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-44 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-56 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-32 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-44 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, FreeBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-104 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_linux_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System calls for AMD64, Linux 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 23 | JMP syscall·RawSyscall(SB) 24 | 25 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 26 | JMP syscall·RawSyscall6(SB) 27 | 28 | TEXT ·gettimeofday(SB),NOSPLIT,$0-16 29 | JMP syscall·gettimeofday(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, NetBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-104 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, OpenBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-104 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, DragonFly 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-64 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-88 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-112 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-64 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-88 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_darwin_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | // +build arm,darwin 7 | 8 | #include "textflag.h" 9 | 10 | // 11 | // System call support for ARM, Darwin 12 | // 13 | 14 | // Just jump to package syscall's implementation for all these functions. 15 | // The runtime may know about them. 16 | 17 | TEXT ·Syscall(SB),NOSPLIT,$0-28 18 | B syscall·Syscall(SB) 19 | 20 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 21 | B syscall·Syscall6(SB) 22 | 23 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 24 | B syscall·Syscall9(SB) 25 | 26 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 27 | B syscall·RawSyscall(SB) 28 | 29 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 30 | B syscall·RawSyscall6(SB) 31 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_darwin_arm64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | // +build arm64,darwin 7 | 8 | #include "textflag.h" 9 | 10 | // 11 | // System call support for AMD64, Darwin 12 | // 13 | 14 | // Just jump to package syscall's implementation for all these functions. 15 | // The runtime may know about them. 16 | 17 | TEXT ·Syscall(SB),NOSPLIT,$0-56 18 | B syscall·Syscall(SB) 19 | 20 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 21 | B syscall·Syscall6(SB) 22 | 23 | TEXT ·Syscall9(SB),NOSPLIT,$0-104 24 | B syscall·Syscall9(SB) 25 | 26 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 27 | B syscall·RawSyscall(SB) 28 | 29 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 30 | B syscall·RawSyscall6(SB) 31 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_limits_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import "testing" 4 | 5 | func TestNewLimits(t *testing.T) { 6 | p, err := FS("fixtures").NewProc(26231) 7 | if err != nil { 8 | t.Fatal(err) 9 | } 10 | 11 | l, err := p.NewLimits() 12 | if err != nil { 13 | t.Fatal(err) 14 | } 15 | 16 | for _, test := range []struct { 17 | name string 18 | want int 19 | have int 20 | }{ 21 | {name: "cpu time", want: -1, have: l.CPUTime}, 22 | {name: "open files", want: 2048, have: l.OpenFiles}, 23 | {name: "msgqueue size", want: 819200, have: l.MsqqueueSize}, 24 | {name: "nice priority", want: 0, have: l.NicePriority}, 25 | {name: "address space", want: -1, have: l.AddressSpace}, 26 | } { 27 | if test.want != test.have { 28 | t.Errorf("want %s %d, have %d", test.name, test.want, test.have) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/flock.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin freebsd openbsd netbsd dragonfly 2 | 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | // +build darwin dragonfly freebsd linux netbsd openbsd 8 | 9 | package unix 10 | 11 | import "unsafe" 12 | 13 | // fcntl64Syscall is usually SYS_FCNTL, but is overridden on 32-bit Linux 14 | // systems by flock_linux_32bit.go to be SYS_FCNTL64. 15 | var fcntl64Syscall uintptr = SYS_FCNTL 16 | 17 | // FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command. 18 | func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error { 19 | _, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(unsafe.Pointer(lk))) 20 | if errno == 0 { 21 | return nil 22 | } 23 | return errno 24 | } 25 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/mksysnum_darwin.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # Copyright 2009 The Go Authors. All rights reserved. 3 | # Use of this source code is governed by a BSD-style 4 | # license that can be found in the LICENSE file. 5 | # 6 | # Generate system call table for Darwin from sys/syscall.h 7 | 8 | use strict; 9 | 10 | if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") { 11 | print STDERR "GOARCH or GOOS not defined in environment\n"; 12 | exit 1; 13 | } 14 | 15 | my $command = "mksysnum_darwin.pl " . join(' ', @ARGV); 16 | 17 | print <){ 29 | if(/^#define\s+SYS_(\w+)\s+([0-9]+)/){ 30 | my $name = $1; 31 | my $num = $2; 32 | $name =~ y/a-z/A-Z/; 33 | print " SYS_$name = $num;" 34 | } 35 | } 36 | 37 | print < 8 | #include 9 | #include 10 | 11 | #define _STRINGIFY2_(x) #x 12 | #define _STRINGIFY_(x) _STRINGIFY2_(x) 13 | #define GOSYM_PREFIX _STRINGIFY_(__USER_LABEL_PREFIX__) 14 | 15 | // Call syscall from C code because the gccgo support for calling from 16 | // Go to C does not support varargs functions. 17 | 18 | struct ret { 19 | uintptr_t r; 20 | uintptr_t err; 21 | }; 22 | 23 | struct ret 24 | gccgoRealSyscall(uintptr_t trap, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7, uintptr_t a8, uintptr_t a9) 25 | { 26 | struct ret r; 27 | 28 | errno = 0; 29 | r.r = syscall(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9); 30 | r.err = errno; 31 | return r; 32 | } 33 | 34 | // Define the use function in C so that it is not inlined. 35 | 36 | extern void use(void *) __asm__ (GOSYM_PREFIX GOPKGPATH ".use") __attribute__((noinline)); 37 | 38 | void 39 | use(void *p __attribute__ ((unused))) 40 | { 41 | } 42 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,openbsd 6 | 7 | package unix 8 | 9 | func Getpagesize() int { return 4096 } 10 | 11 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 12 | 13 | func NsecToTimespec(nsec int64) (ts Timespec) { 14 | ts.Sec = nsec / 1e9 15 | ts.Nsec = nsec % 1e9 16 | return 17 | } 18 | 19 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 20 | 21 | func NsecToTimeval(nsec int64) (tv Timeval) { 22 | nsec += 999 // round up to microsecond 23 | tv.Usec = nsec % 1e9 / 1e3 24 | tv.Sec = nsec / 1e9 25 | return 26 | } 27 | 28 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 29 | k.Ident = uint64(fd) 30 | k.Filter = int16(mode) 31 | k.Flags = uint16(flags) 32 | } 33 | 34 | func (iov *Iovec) SetLen(length int) { 35 | iov.Len = uint64(length) 36 | } 37 | 38 | func (msghdr *Msghdr) SetControllen(length int) { 39 | msghdr.Controllen = uint32(length) 40 | } 41 | 42 | func (cmsg *Cmsghdr) SetLen(length int) { 43 | cmsg.Len = uint32(length) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/model/labelvalue.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "sort" 18 | ) 19 | 20 | // A LabelValue is an associated value for a LabelName. 21 | type LabelValue string 22 | 23 | // LabelValues is a sortable LabelValue slice. It implements sort.Interface. 24 | type LabelValues []LabelValue 25 | 26 | func (l LabelValues) Len() int { 27 | return len(l) 28 | } 29 | 30 | func (l LabelValues) Less(i, j int) bool { 31 | return sort.StringsAreSorted([]string{string(l[i]), string(l[j])}) 32 | } 33 | 34 | func (l LabelValues) Swap(i, j int) { 35 | l[i], l[j] = l[j], l[i] 36 | } 37 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/sockcmsg_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Socket control messages 6 | 7 | package unix 8 | 9 | import "unsafe" 10 | 11 | // UnixCredentials encodes credentials into a socket control message 12 | // for sending to another process. This can be used for 13 | // authentication. 14 | func UnixCredentials(ucred *Ucred) []byte { 15 | b := make([]byte, CmsgSpace(SizeofUcred)) 16 | h := (*Cmsghdr)(unsafe.Pointer(&b[0])) 17 | h.Level = SOL_SOCKET 18 | h.Type = SCM_CREDENTIALS 19 | h.SetLen(CmsgLen(SizeofUcred)) 20 | *((*Ucred)(cmsgData(h))) = *ucred 21 | return b 22 | } 23 | 24 | // ParseUnixCredentials decodes a socket control message that contains 25 | // credentials in a Ucred structure. To receive such a message, the 26 | // SO_PASSCRED option must be enabled on the socket. 27 | func ParseUnixCredentials(m *SocketControlMessage) (*Ucred, error) { 28 | if m.Header.Level != SOL_SOCKET { 29 | return nil, EINVAL 30 | } 31 | if m.Header.Type != SCM_CREDENTIALS { 32 | return nil, EINVAL 33 | } 34 | ucred := *(*Ucred)(unsafe.Pointer(&m.Data[0])) 35 | return &ucred, nil 36 | } 37 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_netbsd_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build 386,netbsd 6 | 7 | package unix 8 | 9 | func Getpagesize() int { return 4096 } 10 | 11 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 12 | 13 | func NsecToTimespec(nsec int64) (ts Timespec) { 14 | ts.Sec = int64(nsec / 1e9) 15 | ts.Nsec = int32(nsec % 1e9) 16 | return 17 | } 18 | 19 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 20 | 21 | func NsecToTimeval(nsec int64) (tv Timeval) { 22 | nsec += 999 // round up to microsecond 23 | tv.Usec = int32(nsec % 1e9 / 1e3) 24 | tv.Sec = int64(nsec / 1e9) 25 | return 26 | } 27 | 28 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 29 | k.Ident = uint32(fd) 30 | k.Filter = uint32(mode) 31 | k.Flags = uint32(flags) 32 | } 33 | 34 | func (iov *Iovec) SetLen(length int) { 35 | iov.Len = uint32(length) 36 | } 37 | 38 | func (msghdr *Msghdr) SetControllen(length int) { 39 | msghdr.Controllen = uint32(length) 40 | } 41 | 42 | func (cmsg *Cmsghdr) SetLen(length int) { 43 | cmsg.Len = uint32(length) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build arm,netbsd 6 | 7 | package unix 8 | 9 | func Getpagesize() int { return 4096 } 10 | 11 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 12 | 13 | func NsecToTimespec(nsec int64) (ts Timespec) { 14 | ts.Sec = int64(nsec / 1e9) 15 | ts.Nsec = int32(nsec % 1e9) 16 | return 17 | } 18 | 19 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 20 | 21 | func NsecToTimeval(nsec int64) (tv Timeval) { 22 | nsec += 999 // round up to microsecond 23 | tv.Usec = int32(nsec % 1e9 / 1e3) 24 | tv.Sec = int64(nsec / 1e9) 25 | return 26 | } 27 | 28 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 29 | k.Ident = uint32(fd) 30 | k.Filter = uint32(mode) 31 | k.Flags = uint32(flags) 32 | } 33 | 34 | func (iov *Iovec) SetLen(length int) { 35 | iov.Len = uint32(length) 36 | } 37 | 38 | func (msghdr *Msghdr) SetControllen(length int) { 39 | msghdr.Controllen = uint32(length) 40 | } 41 | 42 | func (cmsg *Cmsghdr) SetLen(length int) { 43 | cmsg.Len = uint32(length) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_openbsd_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build 386,openbsd 6 | 7 | package unix 8 | 9 | func Getpagesize() int { return 4096 } 10 | 11 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 12 | 13 | func NsecToTimespec(nsec int64) (ts Timespec) { 14 | ts.Sec = int64(nsec / 1e9) 15 | ts.Nsec = int32(nsec % 1e9) 16 | return 17 | } 18 | 19 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 20 | 21 | func NsecToTimeval(nsec int64) (tv Timeval) { 22 | nsec += 999 // round up to microsecond 23 | tv.Usec = int32(nsec % 1e9 / 1e3) 24 | tv.Sec = int64(nsec / 1e9) 25 | return 26 | } 27 | 28 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 29 | k.Ident = uint32(fd) 30 | k.Filter = int16(mode) 31 | k.Flags = uint16(flags) 32 | } 33 | 34 | func (iov *Iovec) SetLen(length int) { 35 | iov.Len = uint32(length) 36 | } 37 | 38 | func (msghdr *Msghdr) SetControllen(length int) { 39 | msghdr.Controllen = uint32(length) 40 | } 41 | 42 | func (cmsg *Cmsghdr) SetLen(length int) { 43 | cmsg.Len = uint32(length) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/hooks.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | // A hook to be fired when logging on the logging levels returned from 4 | // `Levels()` on your implementation of the interface. Note that this is not 5 | // fired in a goroutine or a channel with workers, you should handle such 6 | // functionality yourself if your call is non-blocking and you don't wish for 7 | // the logging calls for levels returned from `Levels()` to block. 8 | type Hook interface { 9 | Levels() []Level 10 | Fire(*Entry) error 11 | } 12 | 13 | // Internal type for storing the hooks on a logger instance. 14 | type LevelHooks map[Level][]Hook 15 | 16 | // Add a hook to an instance of logger. This is called with 17 | // `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface. 18 | func (hooks LevelHooks) Add(hook Hook) { 19 | for _, level := range hook.Levels() { 20 | hooks[level] = append(hooks[level], hook) 21 | } 22 | } 23 | 24 | // Fire all the hooks for the passed level. Used by `entry.log` to fire 25 | // appropriate hooks for a log entry. 26 | func (hooks LevelHooks) Fire(level Level, entry *Entry) error { 27 | for _, hook := range hooks[level] { 28 | if err := hook.Fire(entry); err != nil { 29 | return err 30 | } 31 | } 32 | 33 | return nil 34 | } 35 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,netbsd 6 | 7 | package unix 8 | 9 | func Getpagesize() int { return 4096 } 10 | 11 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 12 | 13 | func NsecToTimespec(nsec int64) (ts Timespec) { 14 | ts.Sec = int64(nsec / 1e9) 15 | ts.Nsec = int64(nsec % 1e9) 16 | return 17 | } 18 | 19 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 20 | 21 | func NsecToTimeval(nsec int64) (tv Timeval) { 22 | nsec += 999 // round up to microsecond 23 | tv.Usec = int32(nsec % 1e9 / 1e3) 24 | tv.Sec = int64(nsec / 1e9) 25 | return 26 | } 27 | 28 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 29 | k.Ident = uint64(fd) 30 | k.Filter = uint32(mode) 31 | k.Flags = uint32(flags) 32 | } 33 | 34 | func (iov *Iovec) SetLen(length int) { 35 | iov.Len = uint64(length) 36 | } 37 | 38 | func (msghdr *Msghdr) SetControllen(length int) { 39 | msghdr.Controllen = uint32(length) 40 | } 41 | 42 | func (cmsg *Cmsghdr) SetLen(length int) { 43 | cmsg.Len = uint32(length) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # Copyright 2009 The Go Authors. All rights reserved. 3 | # Use of this source code is governed by a BSD-style 4 | # license that can be found in the LICENSE file. 5 | # 6 | # Generate system call table for DragonFly from master list 7 | # (for example, /usr/src/sys/kern/syscalls.master). 8 | 9 | use strict; 10 | 11 | if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") { 12 | print STDERR "GOARCH or GOOS not defined in environment\n"; 13 | exit 1; 14 | } 15 | 16 | my $command = "mksysnum_dragonfly.pl " . join(' ', @ARGV); 17 | 18 | print <){ 30 | if(/^([0-9]+)\s+STD\s+({ \S+\s+(\w+).*)$/){ 31 | my $num = $1; 32 | my $proto = $2; 33 | my $name = "SYS_$3"; 34 | $name =~ y/a-z/A-Z/; 35 | 36 | # There are multiple entries for enosys and nosys, so comment them out. 37 | if($name =~ /^SYS_E?NOSYS$/){ 38 | $name = "// $name"; 39 | } 40 | if($name eq 'SYS_SYS_EXIT'){ 41 | $name = 'SYS_EXIT'; 42 | } 43 | 44 | print " $name = $num; // $proto\n"; 45 | } 46 | } 47 | 48 | print <){ 30 | if(/^([0-9]+)\s+STD\s+(NOLOCK\s+)?({ \S+\s+\*?(\w+).*)$/){ 31 | my $num = $1; 32 | my $proto = $3; 33 | my $name = $4; 34 | $name =~ y/a-z/A-Z/; 35 | 36 | # There are multiple entries for enosys and nosys, so comment them out. 37 | if($name =~ /^SYS_E?NOSYS$/){ 38 | $name = "// $name"; 39 | } 40 | if($name eq 'SYS_SYS_EXIT'){ 41 | $name = 'SYS_EXIT'; 42 | } 43 | 44 | print " $name = $num; // $proto\n"; 45 | } 46 | } 47 | 48 | print <= 0 { 43 | t.Fatal("bad math") 44 | } 45 | s := unix.Itoa(i) 46 | f := fmt.Sprint(i) 47 | if s != f { 48 | t.Fatalf("itoa(%d) = %s, want %s", i, s, f) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing to pq 2 | 3 | `pq` has a backlog of pull requests, but contributions are still very 4 | much welcome. You can help with patch review, submitting bug reports, 5 | or adding new functionality. There is no formal style guide, but 6 | please conform to the style of existing code and general Go formatting 7 | conventions when submitting patches. 8 | 9 | ### Patch review 10 | 11 | Help review existing open pull requests by commenting on the code or 12 | proposed functionality. 13 | 14 | ### Bug reports 15 | 16 | We appreciate any bug reports, but especially ones with self-contained 17 | (doesn't depend on code outside of pq), minimal (can't be simplified 18 | further) test cases. It's especially helpful if you can submit a pull 19 | request with just the failing test case (you'll probably want to 20 | pattern it after the tests in 21 | [conn_test.go](https://github.com/lib/pq/blob/master/conn_test.go). 22 | 23 | ### New functionality 24 | 25 | There are a number of pending patches for new functionality, so 26 | additional feature patches will take a while to merge. Still, patches 27 | are generally reviewed based on usefulness and complexity in addition 28 | to time-in-queue, so if you have a knockout idea, take a shot. Feel 29 | free to open an issue discussion your proposed patch beforehand. 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_io.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | ) 8 | 9 | // ProcIO models the content of /proc//io. 10 | type ProcIO struct { 11 | // Chars read. 12 | RChar uint64 13 | // Chars written. 14 | WChar uint64 15 | // Read syscalls. 16 | SyscR uint64 17 | // Write syscalls. 18 | SyscW uint64 19 | // Bytes read. 20 | ReadBytes uint64 21 | // Bytes written. 22 | WriteBytes uint64 23 | // Bytes written, but taking into account truncation. See 24 | // Documentation/filesystems/proc.txt in the kernel sources for 25 | // detailed explanation. 26 | CancelledWriteBytes int64 27 | } 28 | 29 | // NewIO creates a new ProcIO instance from a given Proc instance. 30 | func (p Proc) NewIO() (ProcIO, error) { 31 | pio := ProcIO{} 32 | 33 | f, err := os.Open(p.path("io")) 34 | if err != nil { 35 | return pio, err 36 | } 37 | defer f.Close() 38 | 39 | data, err := ioutil.ReadAll(f) 40 | if err != nil { 41 | return pio, err 42 | } 43 | 44 | ioFormat := "rchar: %d\nwchar: %d\nsyscr: %d\nsyscw: %d\n" + 45 | "read_bytes: %d\nwrite_bytes: %d\n" + 46 | "cancelled_write_bytes: %d\n" 47 | 48 | _, err = fmt.Sscanf(string(data), ioFormat, &pio.RChar, &pio.WChar, &pio.SyscR, 49 | &pio.SyscW, &pio.ReadBytes, &pio.WriteBytes, &pio.CancelledWriteBytes) 50 | if err != nil { 51 | return pio, err 52 | } 53 | 54 | return pio, nil 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/log/log_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package log 15 | 16 | import ( 17 | "bytes" 18 | "regexp" 19 | "testing" 20 | 21 | "github.com/Sirupsen/logrus" 22 | ) 23 | 24 | func TestFileLineLogging(t *testing.T) { 25 | var buf bytes.Buffer 26 | logger.Out = &buf 27 | logger.Formatter = &logrus.TextFormatter{ 28 | DisableColors: true, 29 | } 30 | 31 | // The default logging level should be "info". 32 | Debugln("This debug-level line should not show up in the output.") 33 | Infof("This %s-level line should show up in the output.", "info") 34 | 35 | re := `^time=".*" level=info msg="This info-level line should show up in the output." file="log_test.go" line=33 \n$` 36 | if !regexp.MustCompile(re).Match(buf.Bytes()) { 37 | t.Fatalf("%q did not match expected regex %q", buf.String(), re) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/url_test.go: -------------------------------------------------------------------------------- 1 | package pq 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestSimpleParseURL(t *testing.T) { 8 | expected := "host=hostname.remote" 9 | str, err := ParseURL("postgres://hostname.remote") 10 | if err != nil { 11 | t.Fatal(err) 12 | } 13 | 14 | if str != expected { 15 | t.Fatalf("unexpected result from ParseURL:\n+ %v\n- %v", str, expected) 16 | } 17 | } 18 | 19 | func TestFullParseURL(t *testing.T) { 20 | expected := `dbname=database host=hostname.remote password=top\ secret port=1234 user=username` 21 | str, err := ParseURL("postgres://username:top%20secret@hostname.remote:1234/database") 22 | if err != nil { 23 | t.Fatal(err) 24 | } 25 | 26 | if str != expected { 27 | t.Fatalf("unexpected result from ParseURL:\n+ %s\n- %s", str, expected) 28 | } 29 | } 30 | 31 | func TestInvalidProtocolParseURL(t *testing.T) { 32 | _, err := ParseURL("http://hostname.remote") 33 | switch err { 34 | case nil: 35 | t.Fatal("Expected an error from parsing invalid protocol") 36 | default: 37 | msg := "invalid connection protocol: http" 38 | if err.Error() != msg { 39 | t.Fatalf("Unexpected error message:\n+ %s\n- %s", 40 | err.Error(), msg) 41 | } 42 | } 43 | } 44 | 45 | func TestMinimalURL(t *testing.T) { 46 | cs, err := ParseURL("postgres://") 47 | if err != nil { 48 | t.Fatal(err) 49 | } 50 | 51 | if cs != "" { 52 | t.Fatalf("expected blank connection string, got: %q", cs) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/LICENSE.libyaml: -------------------------------------------------------------------------------- 1 | The following files were ported to Go from C files of libyaml, and thus 2 | are still covered by their original copyright and license: 3 | 4 | apic.go 5 | emitterc.go 6 | parserc.go 7 | readerc.go 8 | scannerc.go 9 | writerc.go 10 | yamlh.go 11 | yamlprivateh.go 12 | 13 | Copyright (c) 2006 Kirill Simonov 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy of 16 | this software and associated documentation files (the "Software"), to deal in 17 | the Software without restriction, including without limitation the rights to 18 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 19 | of the Software, and to permit persons to whom the Software is furnished to do 20 | so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all 23 | copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | -------------------------------------------------------------------------------- /vendor/github.com/beorn7/perks/quantile/bench_test.go: -------------------------------------------------------------------------------- 1 | package quantile 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func BenchmarkInsertTargeted(b *testing.B) { 8 | b.ReportAllocs() 9 | 10 | s := NewTargeted(Targets) 11 | b.ResetTimer() 12 | for i := float64(0); i < float64(b.N); i++ { 13 | s.Insert(i) 14 | } 15 | } 16 | 17 | func BenchmarkInsertTargetedSmallEpsilon(b *testing.B) { 18 | s := NewTargeted(TargetsSmallEpsilon) 19 | b.ResetTimer() 20 | for i := float64(0); i < float64(b.N); i++ { 21 | s.Insert(i) 22 | } 23 | } 24 | 25 | func BenchmarkInsertBiased(b *testing.B) { 26 | s := NewLowBiased(0.01) 27 | b.ResetTimer() 28 | for i := float64(0); i < float64(b.N); i++ { 29 | s.Insert(i) 30 | } 31 | } 32 | 33 | func BenchmarkInsertBiasedSmallEpsilon(b *testing.B) { 34 | s := NewLowBiased(0.0001) 35 | b.ResetTimer() 36 | for i := float64(0); i < float64(b.N); i++ { 37 | s.Insert(i) 38 | } 39 | } 40 | 41 | func BenchmarkQuery(b *testing.B) { 42 | s := NewTargeted(Targets) 43 | for i := float64(0); i < 1e6; i++ { 44 | s.Insert(i) 45 | } 46 | b.ResetTimer() 47 | n := float64(b.N) 48 | for i := float64(0); i < n; i++ { 49 | s.Query(i / n) 50 | } 51 | } 52 | 53 | func BenchmarkQuerySmallEpsilon(b *testing.B) { 54 | s := NewTargeted(TargetsSmallEpsilon) 55 | for i := float64(0); i < 1e6; i++ { 56 | s.Insert(i) 57 | } 58 | b.ResetTimer() 59 | n := float64(b.N) 60 | for i := float64(0); i < n; i++ { 61 | s.Query(i / n) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # Copyright 2009 The Go Authors. All rights reserved. 3 | # Use of this source code is governed by a BSD-style 4 | # license that can be found in the LICENSE file. 5 | # 6 | # Generate system call table for OpenBSD from master list 7 | # (for example, /usr/src/sys/kern/syscalls.master). 8 | 9 | use strict; 10 | 11 | if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") { 12 | print STDERR "GOARCH or GOOS not defined in environment\n"; 13 | exit 1; 14 | } 15 | 16 | my $command = "mksysnum_netbsd.pl " . join(' ', @ARGV); 17 | 18 | print <){ 31 | if($line =~ /^(.*)\\$/) { 32 | # Handle continuation 33 | $line = $1; 34 | $_ =~ s/^\s+//; 35 | $line .= $_; 36 | } else { 37 | # New line 38 | $line = $_; 39 | } 40 | next if $line =~ /\\$/; 41 | if($line =~ /^([0-9]+)\s+((STD)|(NOERR))\s+(RUMP\s+)?({\s+\S+\s*\*?\s*\|(\S+)\|(\S*)\|(\w+).*\s+})(\s+(\S+))?$/) { 42 | my $num = $1; 43 | my $proto = $6; 44 | my $compat = $8; 45 | my $name = "$7_$9"; 46 | 47 | $name = "$7_$11" if $11 ne ''; 48 | $name =~ y/a-z/A-Z/; 49 | 50 | if($compat eq '' || $compat eq '30' || $compat eq '50') { 51 | print " $name = $num; // $proto\n"; 52 | } 53 | } 54 | } 55 | 56 | print < 999){ 29 | # ignore deprecated syscalls that are no longer implemented 30 | # https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h?id=refs/heads/master#n716 31 | return; 32 | } 33 | $name =~ y/a-z/A-Z/; 34 | print " SYS_$name = $num;\n"; 35 | } 36 | 37 | my $prev; 38 | open(GCC, "gcc -E -dD $ARGV[0] |") || die "can't run gcc"; 39 | while(){ 40 | if(/^#define __NR_syscalls\s+/) { 41 | # ignore redefinitions of __NR_syscalls 42 | } 43 | elsif(/^#define __NR_(\w+)\s+([0-9]+)/){ 44 | $prev = $2; 45 | fmt($1, $2); 46 | } 47 | elsif(/^#define __NR3264_(\w+)\s+([0-9]+)/){ 48 | $prev = $2; 49 | fmt($1, $2); 50 | } 51 | elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){ 52 | fmt($1, $prev+$2) 53 | } 54 | } 55 | 56 | print <>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0) 54 | 55 | written = int(writtenOut) 56 | 57 | if e1 != 0 { 58 | err = e1 59 | } 60 | return 61 | } 62 | 63 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 64 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/entry_test.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | func TestEntryWithError(t *testing.T) { 12 | 13 | assert := assert.New(t) 14 | 15 | defer func() { 16 | ErrorKey = "error" 17 | }() 18 | 19 | err := fmt.Errorf("kaboom at layer %d", 4711) 20 | 21 | assert.Equal(err, WithError(err).Data["error"]) 22 | 23 | logger := New() 24 | logger.Out = &bytes.Buffer{} 25 | entry := NewEntry(logger) 26 | 27 | assert.Equal(err, entry.WithError(err).Data["error"]) 28 | 29 | ErrorKey = "err" 30 | 31 | assert.Equal(err, entry.WithError(err).Data["err"]) 32 | 33 | } 34 | 35 | func TestEntryPanicln(t *testing.T) { 36 | errBoom := fmt.Errorf("boom time") 37 | 38 | defer func() { 39 | p := recover() 40 | assert.NotNil(t, p) 41 | 42 | switch pVal := p.(type) { 43 | case *Entry: 44 | assert.Equal(t, "kaboom", pVal.Message) 45 | assert.Equal(t, errBoom, pVal.Data["err"]) 46 | default: 47 | t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal) 48 | } 49 | }() 50 | 51 | logger := New() 52 | logger.Out = &bytes.Buffer{} 53 | entry := NewEntry(logger) 54 | entry.WithField("err", errBoom).Panicln("kaboom") 55 | } 56 | 57 | func TestEntryPanicf(t *testing.T) { 58 | errBoom := fmt.Errorf("boom again") 59 | 60 | defer func() { 61 | p := recover() 62 | assert.NotNil(t, p) 63 | 64 | switch pVal := p.(type) { 65 | case *Entry: 66 | assert.Equal(t, "kaboom true", pVal.Message) 67 | assert.Equal(t, errBoom, pVal.Data["err"]) 68 | default: 69 | t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal) 70 | } 71 | }() 72 | 73 | logger := New() 74 | logger.Out = &bytes.Buffer{} 75 | entry := NewEntry(logger) 76 | entry.WithField("err", errBoom).Panicf("kaboom %v", true) 77 | } 78 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_freebsd_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build 386,freebsd 6 | 7 | package unix 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | func Getpagesize() int { return 4096 } 15 | 16 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 17 | 18 | func NsecToTimespec(nsec int64) (ts Timespec) { 19 | ts.Sec = int32(nsec / 1e9) 20 | ts.Nsec = int32(nsec % 1e9) 21 | return 22 | } 23 | 24 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 25 | 26 | func NsecToTimeval(nsec int64) (tv Timeval) { 27 | nsec += 999 // round up to microsecond 28 | tv.Usec = int32(nsec % 1e9 / 1e3) 29 | tv.Sec = int32(nsec / 1e9) 30 | return 31 | } 32 | 33 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 34 | k.Ident = uint32(fd) 35 | k.Filter = int16(mode) 36 | k.Flags = uint16(flags) 37 | } 38 | 39 | func (iov *Iovec) SetLen(length int) { 40 | iov.Len = uint32(length) 41 | } 42 | 43 | func (msghdr *Msghdr) SetControllen(length int) { 44 | msghdr.Controllen = uint32(length) 45 | } 46 | 47 | func (cmsg *Cmsghdr) SetLen(length int) { 48 | cmsg.Len = uint32(length) 49 | } 50 | 51 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 52 | var writtenOut uint64 = 0 53 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr((*offset)>>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0) 54 | 55 | written = int(writtenOut) 56 | 57 | if e1 != 0 { 58 | err = e1 59 | } 60 | return 61 | } 62 | 63 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 64 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_dragonfly_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build 386,dragonfly 6 | 7 | package unix 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | func Getpagesize() int { return 4096 } 15 | 16 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 17 | 18 | func NsecToTimespec(nsec int64) (ts Timespec) { 19 | ts.Sec = int32(nsec / 1e9) 20 | ts.Nsec = int32(nsec % 1e9) 21 | return 22 | } 23 | 24 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 25 | 26 | func NsecToTimeval(nsec int64) (tv Timeval) { 27 | nsec += 999 // round up to microsecond 28 | tv.Usec = int32(nsec % 1e9 / 1e3) 29 | tv.Sec = int32(nsec / 1e9) 30 | return 31 | } 32 | 33 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 34 | k.Ident = uint32(fd) 35 | k.Filter = int16(mode) 36 | k.Flags = uint16(flags) 37 | } 38 | 39 | func (iov *Iovec) SetLen(length int) { 40 | iov.Len = uint32(length) 41 | } 42 | 43 | func (msghdr *Msghdr) SetControllen(length int) { 44 | msghdr.Controllen = uint32(length) 45 | } 46 | 47 | func (cmsg *Cmsghdr) SetLen(length int) { 48 | cmsg.Len = uint32(length) 49 | } 50 | 51 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 52 | var writtenOut uint64 = 0 53 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr((*offset)>>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0) 54 | 55 | written = int(writtenOut) 56 | 57 | if e1 != 0 { 58 | err = e1 59 | } 60 | return 61 | } 62 | 63 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 64 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # Copyright 2009 The Go Authors. All rights reserved. 3 | # Use of this source code is governed by a BSD-style 4 | # license that can be found in the LICENSE file. 5 | # 6 | # Generate system call table for FreeBSD from master list 7 | # (for example, /usr/src/sys/kern/syscalls.master). 8 | 9 | use strict; 10 | 11 | if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") { 12 | print STDERR "GOARCH or GOOS not defined in environment\n"; 13 | exit 1; 14 | } 15 | 16 | my $command = "mksysnum_freebsd.pl " . join(' ', @ARGV); 17 | 18 | print <){ 30 | if(/^([0-9]+)\s+\S+\s+STD\s+({ \S+\s+(\w+).*)$/){ 31 | my $num = $1; 32 | my $proto = $2; 33 | my $name = "SYS_$3"; 34 | $name =~ y/a-z/A-Z/; 35 | 36 | # There are multiple entries for enosys and nosys, so comment them out. 37 | if($name =~ /^SYS_E?NOSYS$/){ 38 | $name = "// $name"; 39 | } 40 | if($name eq 'SYS_SYS_EXIT'){ 41 | $name = 'SYS_EXIT'; 42 | } 43 | if($name =~ /^SYS_CAP_+/ || $name =~ /^SYS___CAP_+/){ 44 | next 45 | } 46 | 47 | print " $name = $num; // $proto\n"; 48 | 49 | # We keep Capsicum syscall numbers for FreeBSD 50 | # 9-STABLE here because we are not sure whether they 51 | # are mature and stable. 52 | if($num == 513){ 53 | print " SYS_CAP_NEW = 514 // { int cap_new(int fd, uint64_t rights); }\n"; 54 | print " SYS_CAP_GETRIGHTS = 515 // { int cap_getrights(int fd, \\\n"; 55 | print " SYS_CAP_ENTER = 516 // { int cap_enter(void); }\n"; 56 | print " SYS_CAP_GETMODE = 517 // { int cap_getmode(u_int *modep); }\n"; 57 | } 58 | } 59 | } 60 | 61 | print < label: counter: `, m.String(); expected != got { 46 | t.Errorf("expected %q, got %q", expected, got) 47 | } 48 | } 49 | 50 | func decreaseCounter(c *counter) (err error) { 51 | defer func() { 52 | if e := recover(); e != nil { 53 | err = e.(error) 54 | } 55 | }() 56 | c.Add(-1) 57 | return nil 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | install: 33 | go install 34 | 35 | test: install generate-test-pbs 36 | go test 37 | 38 | 39 | generate-test-pbs: 40 | make install 41 | make -C testdata 42 | protoc --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. proto3_proto/proto3.proto 43 | make 44 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_darwin_arm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func Getpagesize() int { return 4096 } 13 | 14 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 15 | 16 | func NsecToTimespec(nsec int64) (ts Timespec) { 17 | ts.Sec = int32(nsec / 1e9) 18 | ts.Nsec = int32(nsec % 1e9) 19 | return 20 | } 21 | 22 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 23 | 24 | func NsecToTimeval(nsec int64) (tv Timeval) { 25 | nsec += 999 // round up to microsecond 26 | tv.Usec = int32(nsec % 1e9 / 1e3) 27 | tv.Sec = int32(nsec / 1e9) 28 | return 29 | } 30 | 31 | //sysnb gettimeofday(tp *Timeval) (sec int32, usec int32, err error) 32 | func Gettimeofday(tv *Timeval) (err error) { 33 | // The tv passed to gettimeofday must be non-nil 34 | // but is otherwise unused. The answers come back 35 | // in the two registers. 36 | sec, usec, err := gettimeofday(tv) 37 | tv.Sec = int32(sec) 38 | tv.Usec = int32(usec) 39 | return err 40 | } 41 | 42 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 43 | k.Ident = uint32(fd) 44 | k.Filter = int16(mode) 45 | k.Flags = uint16(flags) 46 | } 47 | 48 | func (iov *Iovec) SetLen(length int) { 49 | iov.Len = uint32(length) 50 | } 51 | 52 | func (msghdr *Msghdr) SetControllen(length int) { 53 | msghdr.Controllen = uint32(length) 54 | } 55 | 56 | func (cmsg *Cmsghdr) SetLen(length int) { 57 | cmsg.Len = uint32(length) 58 | } 59 | 60 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 61 | var length = uint64(count) 62 | 63 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(*offset>>32), uintptr(unsafe.Pointer(&length)), 0, 0, 0, 0) 64 | 65 | written = int(length) 66 | 67 | if e1 != 0 { 68 | err = e1 69 | } 70 | return 71 | } 72 | 73 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) // sic 74 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/model/sample.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | // Sample is a sample value with a timestamp and a metric. 17 | type Sample struct { 18 | Metric Metric 19 | Value SampleValue 20 | Timestamp Timestamp 21 | } 22 | 23 | // Equal compares first the metrics, then the timestamp, then the value. 24 | func (s *Sample) Equal(o *Sample) bool { 25 | if s == o { 26 | return true 27 | } 28 | 29 | if !s.Metric.Equal(o.Metric) { 30 | return false 31 | } 32 | if !s.Timestamp.Equal(o.Timestamp) { 33 | return false 34 | } 35 | if !s.Value.Equal(o.Value) { 36 | return false 37 | } 38 | 39 | return true 40 | } 41 | 42 | // Samples is a sortable Sample slice. It implements sort.Interface. 43 | type Samples []*Sample 44 | 45 | func (s Samples) Len() int { 46 | return len(s) 47 | } 48 | 49 | // Less compares first the metrics, then the timestamp. 50 | func (s Samples) Less(i, j int) bool { 51 | switch { 52 | case s[i].Metric.Before(s[j].Metric): 53 | return true 54 | case s[j].Metric.Before(s[i].Metric): 55 | return false 56 | case s[i].Timestamp.Before(s[j].Timestamp): 57 | return true 58 | default: 59 | return false 60 | } 61 | } 62 | 63 | func (s Samples) Swap(i, j int) { 64 | s[i], s[j] = s[j], s[i] 65 | } 66 | 67 | // Equal compares two sets of samples and returns true if they are equal. 68 | func (s Samples) Equal(o Samples) bool { 69 | if len(s) != len(o) { 70 | return false 71 | } 72 | 73 | for i, sample := range s { 74 | if !sample.Equal(o[i]) { 75 | return false 76 | } 77 | } 78 | return true 79 | } 80 | -------------------------------------------------------------------------------- /Godeps/Godeps.json: -------------------------------------------------------------------------------- 1 | { 2 | "ImportPath": "github.com/mc2soft/postgresql_exporter", 3 | "GoVersion": "go1.6", 4 | "GodepVersion": "v58", 5 | "Packages": [ 6 | "./..." 7 | ], 8 | "Deps": [ 9 | { 10 | "ImportPath": "bitbucket.org/ww/goautoneg", 11 | "Comment": "null-5", 12 | "Rev": "'75cd24fc2f2c2a2088577d12123ddee5f54e0675'" 13 | }, 14 | { 15 | "ImportPath": "github.com/Sirupsen/logrus", 16 | "Comment": "v0.10.0", 17 | "Rev": "4b6ea7319e214d98c938f12692336f7ca9348d6b" 18 | }, 19 | { 20 | "ImportPath": "github.com/beorn7/perks/quantile", 21 | "Rev": "3ac7bf7a47d159a033b107610db8a1b6575507a4" 22 | }, 23 | { 24 | "ImportPath": "github.com/golang/protobuf/proto", 25 | "Rev": "62e4364d64b32762febb61f2c88c0a29bc49a225" 26 | }, 27 | { 28 | "ImportPath": "github.com/lib/pq", 29 | "Rev": "7175accbed18058468c07811f76440d6e8d7cf19" 30 | }, 31 | { 32 | "ImportPath": "github.com/lib/pq/oid", 33 | "Rev": "7175accbed18058468c07811f76440d6e8d7cf19" 34 | }, 35 | { 36 | "ImportPath": "github.com/matttproud/golang_protobuf_extensions/pbutil", 37 | "Rev": "d0c3fe89de86839aecf2e0579c40ba3bb336a453" 38 | }, 39 | { 40 | "ImportPath": "github.com/prometheus/client_golang/model", 41 | "Comment": "0.7.0", 42 | "Rev": "6dbab8106ed3ed77359ac85d9cf08e30290df864" 43 | }, 44 | { 45 | "ImportPath": "github.com/prometheus/client_golang/prometheus", 46 | "Comment": "0.7.0", 47 | "Rev": "6dbab8106ed3ed77359ac85d9cf08e30290df864" 48 | }, 49 | { 50 | "ImportPath": "github.com/prometheus/client_golang/text", 51 | "Comment": "0.7.0", 52 | "Rev": "6dbab8106ed3ed77359ac85d9cf08e30290df864" 53 | }, 54 | { 55 | "ImportPath": "github.com/prometheus/client_model/go", 56 | "Comment": "model-0.0.2-12-gfa8ad6f", 57 | "Rev": "fa8ad6fec33561be4280a8f0514318c79d7f6cb6" 58 | }, 59 | { 60 | "ImportPath": "github.com/prometheus/log", 61 | "Rev": "9a3136781e1ff7bc42736ba4acb81339b1422551" 62 | }, 63 | { 64 | "ImportPath": "github.com/prometheus/procfs", 65 | "Rev": "406e5b7bfd8201a36e2bb5f7bdae0b03380c2ce8" 66 | }, 67 | { 68 | "ImportPath": "golang.org/x/sys/unix", 69 | "Rev": "20457ee8ea8546920d3f4e19e405da45250dc5a5" 70 | }, 71 | { 72 | "ImportPath": "gopkg.in/yaml.v2", 73 | "Rev": "f7716cbe52baa25d2e9b0d0da546fcf909fc16b4" 74 | } 75 | ] 76 | } 77 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build arm64,darwin 6 | 7 | package unix 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | func Getpagesize() int { return 16384 } 15 | 16 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 17 | 18 | func NsecToTimespec(nsec int64) (ts Timespec) { 19 | ts.Sec = nsec / 1e9 20 | ts.Nsec = nsec % 1e9 21 | return 22 | } 23 | 24 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 25 | 26 | func NsecToTimeval(nsec int64) (tv Timeval) { 27 | nsec += 999 // round up to microsecond 28 | tv.Usec = int32(nsec % 1e9 / 1e3) 29 | tv.Sec = int64(nsec / 1e9) 30 | return 31 | } 32 | 33 | //sysnb gettimeofday(tp *Timeval) (sec int64, usec int32, err error) 34 | func Gettimeofday(tv *Timeval) (err error) { 35 | // The tv passed to gettimeofday must be non-nil 36 | // but is otherwise unused. The answers come back 37 | // in the two registers. 38 | sec, usec, err := gettimeofday(tv) 39 | tv.Sec = sec 40 | tv.Usec = usec 41 | return err 42 | } 43 | 44 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 45 | k.Ident = uint64(fd) 46 | k.Filter = int16(mode) 47 | k.Flags = uint16(flags) 48 | } 49 | 50 | func (iov *Iovec) SetLen(length int) { 51 | iov.Len = uint64(length) 52 | } 53 | 54 | func (msghdr *Msghdr) SetControllen(length int) { 55 | msghdr.Controllen = uint32(length) 56 | } 57 | 58 | func (cmsg *Cmsghdr) SetLen(length int) { 59 | cmsg.Len = uint32(length) 60 | } 61 | 62 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 63 | var length = uint64(count) 64 | 65 | _, _, e1 := Syscall6(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(unsafe.Pointer(&length)), 0, 0) 66 | 67 | written = int(length) 68 | 69 | if e1 != 0 { 70 | err = e1 71 | } 72 | return 73 | } 74 | 75 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) // sic 76 | 77 | // SYS___SYSCTL is used by syscall_bsd.go for all BSDs, but in modern versions 78 | // of darwin/arm64 the syscall is called sysctl instead of __sysctl. 79 | const SYS___SYSCTL = SYS_SYSCTL 80 | -------------------------------------------------------------------------------- /metrics/buffer.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "database/sql" 5 | "errors" 6 | "sync" 7 | 8 | "github.com/prometheus/client_golang/prometheus" 9 | ) 10 | 11 | var ( 12 | bufferMetrics = map[string]metric{ 13 | "buffers_checkpoint": metric{Name: "checkpoint_total", Help: "Number of buffers written during checkpoints"}, 14 | "buffers_clean": metric{Name: "clean_total", Help: "Number of buffers written by the background writer"}, 15 | "maxwritten_clean": metric{Name: "maxwritten_clean_total", Help: "Number of times the background writer stopped a cleaning scan because it had written too many buffers"}, 16 | "buffers_backend": metric{Name: "backend_total", Help: "Number of buffers written directly by a backend"}, 17 | "buffers_backend_fsync": metric{Name: "backend_fsync_total", Help: "Number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)"}, 18 | "buffers_alloc": metric{Name: "alloc_total", Help: "Number of buffers allocated"}, 19 | } 20 | ) 21 | 22 | type BufferMetrics struct { 23 | mutex sync.Mutex 24 | metrics map[string]prometheus.Gauge 25 | } 26 | 27 | func NewBufferMetrics() *BufferMetrics { 28 | return &BufferMetrics{ 29 | metrics: map[string]prometheus.Gauge{}, 30 | } 31 | } 32 | 33 | func (b *BufferMetrics) Scrape(db *sql.DB) error { 34 | b.mutex.Lock() 35 | defer b.mutex.Unlock() 36 | 37 | result, err := getMetrics(db, bufferMetrics, "pg_stat_bgwriter", nil) 38 | if err != nil { 39 | return errors.New("error running table stats query on database: " + err.Error()) 40 | } 41 | 42 | for key, val := range result { 43 | if _, ok := b.metrics[key]; !ok { 44 | b.metrics[key] = prometheus.NewGauge(prometheus.GaugeOpts{ 45 | Namespace: namespace, 46 | Subsystem: "buffers", 47 | Name: bufferMetrics[key].Name, 48 | Help: bufferMetrics[key].Help, 49 | }) 50 | } 51 | 52 | b.metrics[key].Set(val) 53 | } 54 | 55 | return nil 56 | } 57 | 58 | func (b *BufferMetrics) Describe(ch chan<- *prometheus.Desc) { 59 | for _, m := range b.metrics { 60 | m.Describe(ch) 61 | } 62 | } 63 | 64 | func (b *BufferMetrics) Collect(ch chan<- prometheus.Metric) { 65 | for _, m := range b.metrics { 66 | m.Collect(ch) 67 | } 68 | } 69 | 70 | // check interface 71 | var _ Collection = new(BufferMetrics) 72 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_darwin_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build 386,darwin 6 | 7 | package unix 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | func Getpagesize() int { return 4096 } 15 | 16 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 17 | 18 | func NsecToTimespec(nsec int64) (ts Timespec) { 19 | ts.Sec = int32(nsec / 1e9) 20 | ts.Nsec = int32(nsec % 1e9) 21 | return 22 | } 23 | 24 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 25 | 26 | func NsecToTimeval(nsec int64) (tv Timeval) { 27 | nsec += 999 // round up to microsecond 28 | tv.Usec = int32(nsec % 1e9 / 1e3) 29 | tv.Sec = int32(nsec / 1e9) 30 | return 31 | } 32 | 33 | //sysnb gettimeofday(tp *Timeval) (sec int32, usec int32, err error) 34 | func Gettimeofday(tv *Timeval) (err error) { 35 | // The tv passed to gettimeofday must be non-nil 36 | // but is otherwise unused. The answers come back 37 | // in the two registers. 38 | sec, usec, err := gettimeofday(tv) 39 | tv.Sec = int32(sec) 40 | tv.Usec = int32(usec) 41 | return err 42 | } 43 | 44 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 45 | k.Ident = uint32(fd) 46 | k.Filter = int16(mode) 47 | k.Flags = uint16(flags) 48 | } 49 | 50 | func (iov *Iovec) SetLen(length int) { 51 | iov.Len = uint32(length) 52 | } 53 | 54 | func (msghdr *Msghdr) SetControllen(length int) { 55 | msghdr.Controllen = uint32(length) 56 | } 57 | 58 | func (cmsg *Cmsghdr) SetLen(length int) { 59 | cmsg.Len = uint32(length) 60 | } 61 | 62 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 63 | var length = uint64(count) 64 | 65 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(*offset>>32), uintptr(unsafe.Pointer(&length)), 0, 0, 0, 0) 66 | 67 | written = int(length) 68 | 69 | if e1 != 0 { 70 | err = e1 71 | } 72 | return 73 | } 74 | 75 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 76 | 77 | // SYS___SYSCTL is used by syscall_bsd.go for all BSDs, but in modern versions 78 | // of darwin/386 the syscall is called sysctl instead of __sysctl. 79 | const SYS___SYSCTL = SYS_SYSCTL 80 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/example_selfcollector_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus_test 15 | 16 | import ( 17 | "runtime" 18 | 19 | "github.com/golang/protobuf/proto" 20 | 21 | dto "github.com/prometheus/client_model/go" 22 | 23 | "github.com/prometheus/client_golang/prometheus" 24 | ) 25 | 26 | func NewCallbackMetric(desc *prometheus.Desc, callback func() float64) *CallbackMetric { 27 | result := &CallbackMetric{desc: desc, callback: callback} 28 | result.Init(result) // Initialize the SelfCollector. 29 | return result 30 | } 31 | 32 | // TODO: Come up with a better example. 33 | 34 | // CallbackMetric is an example for a user-defined Metric that exports the 35 | // result of a function call as a metric of type "untyped" without any 36 | // labels. It uses SelfCollector to turn the Metric into a Collector so that it 37 | // can be registered with Prometheus. 38 | // 39 | // Note that this example is pretty much academic as the prometheus package 40 | // already provides an UntypedFunc type. 41 | type CallbackMetric struct { 42 | prometheus.SelfCollector 43 | 44 | desc *prometheus.Desc 45 | callback func() float64 46 | } 47 | 48 | func (cm *CallbackMetric) Desc() *prometheus.Desc { 49 | return cm.desc 50 | } 51 | 52 | func (cm *CallbackMetric) Write(m *dto.Metric) error { 53 | m.Untyped = &dto.Untyped{Value: proto.Float64(cm.callback())} 54 | return nil 55 | } 56 | 57 | func ExampleSelfCollector() { 58 | m := NewCallbackMetric( 59 | prometheus.NewDesc( 60 | "runtime_goroutines_count", 61 | "Total number of goroutines that currently exist.", 62 | nil, nil, // No labels, these must be nil. 63 | ), 64 | func() float64 { 65 | return float64(runtime.NumGoroutine()) 66 | }, 67 | ) 68 | prometheus.MustRegister(m) 69 | } 70 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,darwin 6 | 7 | package unix 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) 15 | 16 | func Getpagesize() int { return 4096 } 17 | 18 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 19 | 20 | func NsecToTimespec(nsec int64) (ts Timespec) { 21 | ts.Sec = nsec / 1e9 22 | ts.Nsec = nsec % 1e9 23 | return 24 | } 25 | 26 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 27 | 28 | func NsecToTimeval(nsec int64) (tv Timeval) { 29 | nsec += 999 // round up to microsecond 30 | tv.Usec = int32(nsec % 1e9 / 1e3) 31 | tv.Sec = int64(nsec / 1e9) 32 | return 33 | } 34 | 35 | //sysnb gettimeofday(tp *Timeval) (sec int64, usec int32, err error) 36 | func Gettimeofday(tv *Timeval) (err error) { 37 | // The tv passed to gettimeofday must be non-nil 38 | // but is otherwise unused. The answers come back 39 | // in the two registers. 40 | sec, usec, err := gettimeofday(tv) 41 | tv.Sec = sec 42 | tv.Usec = usec 43 | return err 44 | } 45 | 46 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 47 | k.Ident = uint64(fd) 48 | k.Filter = int16(mode) 49 | k.Flags = uint16(flags) 50 | } 51 | 52 | func (iov *Iovec) SetLen(length int) { 53 | iov.Len = uint64(length) 54 | } 55 | 56 | func (msghdr *Msghdr) SetControllen(length int) { 57 | msghdr.Controllen = uint32(length) 58 | } 59 | 60 | func (cmsg *Cmsghdr) SetLen(length int) { 61 | cmsg.Len = uint32(length) 62 | } 63 | 64 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 65 | var length = uint64(count) 66 | 67 | _, _, e1 := Syscall6(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(unsafe.Pointer(&length)), 0, 0) 68 | 69 | written = int(length) 70 | 71 | if e1 != 0 { 72 | err = e1 73 | } 74 | return 75 | } 76 | 77 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 78 | 79 | // SYS___SYSCTL is used by syscall_bsd.go for all BSDs, but in modern versions 80 | // of darwin/amd64 the syscall is called sysctl instead of __sysctl. 81 | const SYS___SYSCTL = SYS_SYSCTL 82 | -------------------------------------------------------------------------------- /vendor/bitbucket.org/ww/goautoneg/README.txt: -------------------------------------------------------------------------------- 1 | PACKAGE 2 | 3 | package goautoneg 4 | import "bitbucket.org/ww/goautoneg" 5 | 6 | HTTP Content-Type Autonegotiation. 7 | 8 | The functions in this package implement the behaviour specified in 9 | http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html 10 | 11 | Copyright (c) 2011, Open Knowledge Foundation Ltd. 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are 16 | met: 17 | 18 | Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in 23 | the documentation and/or other materials provided with the 24 | distribution. 25 | 26 | Neither the name of the Open Knowledge Foundation Ltd. nor the 27 | names of its contributors may be used to endorse or promote 28 | products derived from this software without specific prior written 29 | permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | 43 | 44 | FUNCTIONS 45 | 46 | func Negotiate(header string, alternatives []string) (content_type string) 47 | Negotiate the most appropriate content_type given the accept header 48 | and a list of alternatives. 49 | 50 | func ParseAccept(header string) (accept []Accept) 51 | Parse an Accept Header string returning a sorted list 52 | of clauses 53 | 54 | 55 | TYPES 56 | 57 | type Accept struct { 58 | Type, SubType string 59 | Q float32 60 | Params map[string]string 61 | } 62 | Structure to represent a clause in an HTTP Accept Header 63 | 64 | 65 | SUBDIRECTORIES 66 | 67 | .hg 68 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/formatter_bench_test.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | "time" 7 | ) 8 | 9 | // smallFields is a small size data set for benchmarking 10 | var smallFields = Fields{ 11 | "foo": "bar", 12 | "baz": "qux", 13 | "one": "two", 14 | "three": "four", 15 | } 16 | 17 | // largeFields is a large size data set for benchmarking 18 | var largeFields = Fields{ 19 | "foo": "bar", 20 | "baz": "qux", 21 | "one": "two", 22 | "three": "four", 23 | "five": "six", 24 | "seven": "eight", 25 | "nine": "ten", 26 | "eleven": "twelve", 27 | "thirteen": "fourteen", 28 | "fifteen": "sixteen", 29 | "seventeen": "eighteen", 30 | "nineteen": "twenty", 31 | "a": "b", 32 | "c": "d", 33 | "e": "f", 34 | "g": "h", 35 | "i": "j", 36 | "k": "l", 37 | "m": "n", 38 | "o": "p", 39 | "q": "r", 40 | "s": "t", 41 | "u": "v", 42 | "w": "x", 43 | "y": "z", 44 | "this": "will", 45 | "make": "thirty", 46 | "entries": "yeah", 47 | } 48 | 49 | var errorFields = Fields{ 50 | "foo": fmt.Errorf("bar"), 51 | "baz": fmt.Errorf("qux"), 52 | } 53 | 54 | func BenchmarkErrorTextFormatter(b *testing.B) { 55 | doBenchmark(b, &TextFormatter{DisableColors: true}, errorFields) 56 | } 57 | 58 | func BenchmarkSmallTextFormatter(b *testing.B) { 59 | doBenchmark(b, &TextFormatter{DisableColors: true}, smallFields) 60 | } 61 | 62 | func BenchmarkLargeTextFormatter(b *testing.B) { 63 | doBenchmark(b, &TextFormatter{DisableColors: true}, largeFields) 64 | } 65 | 66 | func BenchmarkSmallColoredTextFormatter(b *testing.B) { 67 | doBenchmark(b, &TextFormatter{ForceColors: true}, smallFields) 68 | } 69 | 70 | func BenchmarkLargeColoredTextFormatter(b *testing.B) { 71 | doBenchmark(b, &TextFormatter{ForceColors: true}, largeFields) 72 | } 73 | 74 | func BenchmarkSmallJSONFormatter(b *testing.B) { 75 | doBenchmark(b, &JSONFormatter{}, smallFields) 76 | } 77 | 78 | func BenchmarkLargeJSONFormatter(b *testing.B) { 79 | doBenchmark(b, &JSONFormatter{}, largeFields) 80 | } 81 | 82 | func doBenchmark(b *testing.B, formatter Formatter, fields Fields) { 83 | entry := &Entry{ 84 | Time: time.Time{}, 85 | Level: InfoLevel, 86 | Message: "message", 87 | Data: fields, 88 | } 89 | var d []byte 90 | var err error 91 | for i := 0; i < b.N; i++ { 92 | d, err = formatter.Format(entry) 93 | if err != nil { 94 | b.Fatal(err) 95 | } 96 | b.SetBytes(int64(len(d))) 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/size2_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2012 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package proto 33 | 34 | import ( 35 | "testing" 36 | ) 37 | 38 | // This is a separate file and package from size_test.go because that one uses 39 | // generated messages and thus may not be in package proto without having a circular 40 | // dependency, whereas this file tests unexported details of size.go. 41 | 42 | func TestVarintSize(t *testing.T) { 43 | // Check the edge cases carefully. 44 | testCases := []struct { 45 | n uint64 46 | size int 47 | }{ 48 | {0, 1}, 49 | {1, 1}, 50 | {127, 1}, 51 | {128, 2}, 52 | {16383, 2}, 53 | {16384, 3}, 54 | {1<<63 - 1, 9}, 55 | {1 << 63, 10}, 56 | } 57 | for _, tc := range testCases { 58 | size := sizeVarint(tc.n) 59 | if size != tc.size { 60 | t.Errorf("sizeVarint(%d) = %d, want %d", tc.n, size, tc.size) 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/model/labelset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "encoding/json" 18 | "fmt" 19 | "sort" 20 | "strings" 21 | ) 22 | 23 | // A LabelSet is a collection of LabelName and LabelValue pairs. The LabelSet 24 | // may be fully-qualified down to the point where it may resolve to a single 25 | // Metric in the data store or not. All operations that occur within the realm 26 | // of a LabelSet can emit a vector of Metric entities to which the LabelSet may 27 | // match. 28 | type LabelSet map[LabelName]LabelValue 29 | 30 | // Merge is a helper function to non-destructively merge two label sets. 31 | func (l LabelSet) Merge(other LabelSet) LabelSet { 32 | result := make(LabelSet, len(l)) 33 | 34 | for k, v := range l { 35 | result[k] = v 36 | } 37 | 38 | for k, v := range other { 39 | result[k] = v 40 | } 41 | 42 | return result 43 | } 44 | 45 | func (l LabelSet) String() string { 46 | labelStrings := make([]string, 0, len(l)) 47 | for label, value := range l { 48 | labelStrings = append(labelStrings, fmt.Sprintf("%s=%q", label, value)) 49 | } 50 | 51 | switch len(labelStrings) { 52 | case 0: 53 | return "" 54 | default: 55 | sort.Strings(labelStrings) 56 | return fmt.Sprintf("{%s}", strings.Join(labelStrings, ", ")) 57 | } 58 | } 59 | 60 | // MergeFromMetric merges Metric into this LabelSet. 61 | func (l LabelSet) MergeFromMetric(m Metric) { 62 | for k, v := range m { 63 | l[k] = v 64 | } 65 | } 66 | 67 | // UnmarshalJSON implements the json.Unmarshaler interface. 68 | func (l *LabelSet) UnmarshalJSON(b []byte) error { 69 | var m map[LabelName]LabelValue 70 | if err := json.Unmarshal(b, &m); err != nil { 71 | return err 72 | } 73 | // encoding/json only unmarshals maps of the form map[string]T. It treats 74 | // LabelName as a string and does not call its UnmarshalJSON method. 75 | // Thus, we have to replicate the behavior here. 76 | for ln := range m { 77 | if !LabelNameRE.MatchString(string(ln)) { 78 | return fmt.Errorf("%q is not a valid label name", ln) 79 | } 80 | } 81 | *l = LabelSet(m) 82 | return nil 83 | } 84 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/model/timestamp_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "testing" 18 | native_time "time" 19 | ) 20 | 21 | func TestComparators(t *testing.T) { 22 | t1a := TimestampFromUnix(0) 23 | t1b := TimestampFromUnix(0) 24 | t2 := TimestampFromUnix(2*second - 1) 25 | 26 | if !t1a.Equal(t1b) { 27 | t.Fatalf("Expected %s to be equal to %s", t1a, t1b) 28 | } 29 | if t1a.Equal(t2) { 30 | t.Fatalf("Expected %s to not be equal to %s", t1a, t2) 31 | } 32 | 33 | if !t1a.Before(t2) { 34 | t.Fatalf("Expected %s to be before %s", t1a, t2) 35 | } 36 | if t1a.Before(t1b) { 37 | t.Fatalf("Expected %s to not be before %s", t1a, t1b) 38 | } 39 | 40 | if !t2.After(t1a) { 41 | t.Fatalf("Expected %s to be after %s", t2, t1a) 42 | } 43 | if t1b.After(t1a) { 44 | t.Fatalf("Expected %s to not be after %s", t1b, t1a) 45 | } 46 | } 47 | 48 | func TestTimestampConversions(t *testing.T) { 49 | unixSecs := int64(1136239445) 50 | unixNsecs := int64(123456789) 51 | unixNano := unixSecs*1000000000 + unixNsecs 52 | 53 | t1 := native_time.Unix(unixSecs, unixNsecs-unixNsecs%nanosPerTick) 54 | t2 := native_time.Unix(unixSecs, unixNsecs) 55 | 56 | ts := TimestampFromUnixNano(unixNano) 57 | if !ts.Time().Equal(t1) { 58 | t.Fatalf("Expected %s, got %s", t1, ts.Time()) 59 | } 60 | 61 | // Test available precision. 62 | ts = TimestampFromTime(t2) 63 | if !ts.Time().Equal(t1) { 64 | t.Fatalf("Expected %s, got %s", t1, ts.Time()) 65 | } 66 | 67 | if ts.UnixNano() != unixNano-unixNano%nanosPerTick { 68 | t.Fatalf("Expected %d, got %d", unixNano, ts.UnixNano()) 69 | } 70 | } 71 | 72 | func TestDuration(t *testing.T) { 73 | duration := native_time.Second + native_time.Minute + native_time.Hour 74 | goTime := native_time.Unix(1136239445, 0) 75 | 76 | ts := TimestampFromTime(goTime) 77 | if !goTime.Add(duration).Equal(ts.Add(duration).Time()) { 78 | t.Fatalf("Expected %s to be equal to %s", goTime.Add(duration), ts.Add(duration)) 79 | } 80 | 81 | earlier := ts.Add(-duration) 82 | delta := ts.Sub(earlier) 83 | if delta != duration { 84 | t.Fatalf("Expected %s to be equal to %s", delta, duration) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/hook_test.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | type TestHook struct { 10 | Fired bool 11 | } 12 | 13 | func (hook *TestHook) Fire(entry *Entry) error { 14 | hook.Fired = true 15 | return nil 16 | } 17 | 18 | func (hook *TestHook) Levels() []Level { 19 | return []Level{ 20 | DebugLevel, 21 | InfoLevel, 22 | WarnLevel, 23 | ErrorLevel, 24 | FatalLevel, 25 | PanicLevel, 26 | } 27 | } 28 | 29 | func TestHookFires(t *testing.T) { 30 | hook := new(TestHook) 31 | 32 | LogAndAssertJSON(t, func(log *Logger) { 33 | log.Hooks.Add(hook) 34 | assert.Equal(t, hook.Fired, false) 35 | 36 | log.Print("test") 37 | }, func(fields Fields) { 38 | assert.Equal(t, hook.Fired, true) 39 | }) 40 | } 41 | 42 | type ModifyHook struct { 43 | } 44 | 45 | func (hook *ModifyHook) Fire(entry *Entry) error { 46 | entry.Data["wow"] = "whale" 47 | return nil 48 | } 49 | 50 | func (hook *ModifyHook) Levels() []Level { 51 | return []Level{ 52 | DebugLevel, 53 | InfoLevel, 54 | WarnLevel, 55 | ErrorLevel, 56 | FatalLevel, 57 | PanicLevel, 58 | } 59 | } 60 | 61 | func TestHookCanModifyEntry(t *testing.T) { 62 | hook := new(ModifyHook) 63 | 64 | LogAndAssertJSON(t, func(log *Logger) { 65 | log.Hooks.Add(hook) 66 | log.WithField("wow", "elephant").Print("test") 67 | }, func(fields Fields) { 68 | assert.Equal(t, fields["wow"], "whale") 69 | }) 70 | } 71 | 72 | func TestCanFireMultipleHooks(t *testing.T) { 73 | hook1 := new(ModifyHook) 74 | hook2 := new(TestHook) 75 | 76 | LogAndAssertJSON(t, func(log *Logger) { 77 | log.Hooks.Add(hook1) 78 | log.Hooks.Add(hook2) 79 | 80 | log.WithField("wow", "elephant").Print("test") 81 | }, func(fields Fields) { 82 | assert.Equal(t, fields["wow"], "whale") 83 | assert.Equal(t, hook2.Fired, true) 84 | }) 85 | } 86 | 87 | type ErrorHook struct { 88 | Fired bool 89 | } 90 | 91 | func (hook *ErrorHook) Fire(entry *Entry) error { 92 | hook.Fired = true 93 | return nil 94 | } 95 | 96 | func (hook *ErrorHook) Levels() []Level { 97 | return []Level{ 98 | ErrorLevel, 99 | } 100 | } 101 | 102 | func TestErrorHookShouldntFireOnInfo(t *testing.T) { 103 | hook := new(ErrorHook) 104 | 105 | LogAndAssertJSON(t, func(log *Logger) { 106 | log.Hooks.Add(hook) 107 | log.Info("test") 108 | }, func(fields Fields) { 109 | assert.Equal(t, hook.Fired, false) 110 | }) 111 | } 112 | 113 | func TestErrorHookShouldFireOnError(t *testing.T) { 114 | hook := new(ErrorHook) 115 | 116 | LogAndAssertJSON(t, func(log *Logger) { 117 | log.Hooks.Add(hook) 118 | log.Error("test") 119 | }, func(fields Fields) { 120 | assert.Equal(t, hook.Fired, true) 121 | }) 122 | } 123 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/writerc.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | // Set the writer error and return false. 4 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { 5 | emitter.error = yaml_WRITER_ERROR 6 | emitter.problem = problem 7 | return false 8 | } 9 | 10 | // Flush the output buffer. 11 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool { 12 | if emitter.write_handler == nil { 13 | panic("write handler not set") 14 | } 15 | 16 | // Check if the buffer is empty. 17 | if emitter.buffer_pos == 0 { 18 | return true 19 | } 20 | 21 | // If the output encoding is UTF-8, we don't need to recode the buffer. 22 | if emitter.encoding == yaml_UTF8_ENCODING { 23 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { 24 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 25 | } 26 | emitter.buffer_pos = 0 27 | return true 28 | } 29 | 30 | // Recode the buffer into the raw buffer. 31 | var low, high int 32 | if emitter.encoding == yaml_UTF16LE_ENCODING { 33 | low, high = 0, 1 34 | } else { 35 | high, low = 1, 0 36 | } 37 | 38 | pos := 0 39 | for pos < emitter.buffer_pos { 40 | // See the "reader.c" code for more details on UTF-8 encoding. Note 41 | // that we assume that the buffer contains a valid UTF-8 sequence. 42 | 43 | // Read the next UTF-8 character. 44 | octet := emitter.buffer[pos] 45 | 46 | var w int 47 | var value rune 48 | switch { 49 | case octet&0x80 == 0x00: 50 | w, value = 1, rune(octet&0x7F) 51 | case octet&0xE0 == 0xC0: 52 | w, value = 2, rune(octet&0x1F) 53 | case octet&0xF0 == 0xE0: 54 | w, value = 3, rune(octet&0x0F) 55 | case octet&0xF8 == 0xF0: 56 | w, value = 4, rune(octet&0x07) 57 | } 58 | for k := 1; k < w; k++ { 59 | octet = emitter.buffer[pos+k] 60 | value = (value << 6) + (rune(octet) & 0x3F) 61 | } 62 | pos += w 63 | 64 | // Write the character. 65 | if value < 0x10000 { 66 | var b [2]byte 67 | b[high] = byte(value >> 8) 68 | b[low] = byte(value & 0xFF) 69 | emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1]) 70 | } else { 71 | // Write the character using a surrogate pair (check "reader.c"). 72 | var b [4]byte 73 | value -= 0x10000 74 | b[high] = byte(0xD8 + (value >> 18)) 75 | b[low] = byte((value >> 10) & 0xFF) 76 | b[high+2] = byte(0xDC + ((value >> 8) & 0xFF)) 77 | b[low+2] = byte(value & 0xFF) 78 | emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1], b[2], b[3]) 79 | } 80 | } 81 | 82 | // Write the raw buffer. 83 | if err := emitter.write_handler(emitter, emitter.raw_buffer); err != nil { 84 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 85 | } 86 | emitter.buffer_pos = 0 87 | emitter.raw_buffer = emitter.raw_buffer[:0] 88 | return true 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/model/sample_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "sort" 18 | "testing" 19 | ) 20 | 21 | func TestSamplesSort(t *testing.T) { 22 | input := Samples{ 23 | &Sample{ 24 | Metric: Metric{ 25 | MetricNameLabel: "A", 26 | }, 27 | Timestamp: 1, 28 | }, 29 | &Sample{ 30 | Metric: Metric{ 31 | MetricNameLabel: "A", 32 | }, 33 | Timestamp: 2, 34 | }, 35 | &Sample{ 36 | Metric: Metric{ 37 | MetricNameLabel: "C", 38 | }, 39 | Timestamp: 1, 40 | }, 41 | &Sample{ 42 | Metric: Metric{ 43 | MetricNameLabel: "C", 44 | }, 45 | Timestamp: 2, 46 | }, 47 | &Sample{ 48 | Metric: Metric{ 49 | MetricNameLabel: "B", 50 | }, 51 | Timestamp: 1, 52 | }, 53 | &Sample{ 54 | Metric: Metric{ 55 | MetricNameLabel: "B", 56 | }, 57 | Timestamp: 2, 58 | }, 59 | } 60 | 61 | expected := Samples{ 62 | &Sample{ 63 | Metric: Metric{ 64 | MetricNameLabel: "A", 65 | }, 66 | Timestamp: 1, 67 | }, 68 | &Sample{ 69 | Metric: Metric{ 70 | MetricNameLabel: "A", 71 | }, 72 | Timestamp: 2, 73 | }, 74 | &Sample{ 75 | Metric: Metric{ 76 | MetricNameLabel: "B", 77 | }, 78 | Timestamp: 1, 79 | }, 80 | &Sample{ 81 | Metric: Metric{ 82 | MetricNameLabel: "B", 83 | }, 84 | Timestamp: 2, 85 | }, 86 | &Sample{ 87 | Metric: Metric{ 88 | MetricNameLabel: "C", 89 | }, 90 | Timestamp: 1, 91 | }, 92 | &Sample{ 93 | Metric: Metric{ 94 | MetricNameLabel: "C", 95 | }, 96 | Timestamp: 2, 97 | }, 98 | } 99 | 100 | sort.Sort(input) 101 | 102 | for i, actual := range input { 103 | actualFp := actual.Metric.Fingerprint() 104 | expectedFp := expected[i].Metric.Fingerprint() 105 | 106 | if !actualFp.Equal(expectedFp) { 107 | t.Fatalf("%d. Incorrect fingerprint. Got %s; want %s", i, actualFp.String(), expectedFp.String()) 108 | } 109 | 110 | if actual.Timestamp != expected[i].Timestamp { 111 | t.Fatalf("%d. Incorrect timestamp. Got %s; want %s", i, actual.Timestamp, expected[i].Timestamp) 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/message_set_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package proto 33 | 34 | import ( 35 | "bytes" 36 | "testing" 37 | ) 38 | 39 | func TestUnmarshalMessageSetWithDuplicate(t *testing.T) { 40 | // Check that a repeated message set entry will be concatenated. 41 | in := &messageSet{ 42 | Item: []*_MessageSet_Item{ 43 | {TypeId: Int32(12345), Message: []byte("hoo")}, 44 | {TypeId: Int32(12345), Message: []byte("hah")}, 45 | }, 46 | } 47 | b, err := Marshal(in) 48 | if err != nil { 49 | t.Fatalf("Marshal: %v", err) 50 | } 51 | t.Logf("Marshaled bytes: %q", b) 52 | 53 | m := make(map[int32]Extension) 54 | if err := UnmarshalMessageSet(b, m); err != nil { 55 | t.Fatalf("UnmarshalMessageSet: %v", err) 56 | } 57 | ext, ok := m[12345] 58 | if !ok { 59 | t.Fatalf("Didn't retrieve extension 12345; map is %v", m) 60 | } 61 | // Skip wire type/field number and length varints. 62 | got := skipVarint(skipVarint(ext.enc)) 63 | if want := []byte("hoohah"); !bytes.Equal(got, want) { 64 | t.Errorf("Combined extension is %q, want %q", got, want) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 | 7 | // Package unix contains an interface to the low-level operating system 8 | // primitives. OS details vary depending on the underlying system, and 9 | // by default, godoc will display OS-specific documentation for the current 10 | // system. If you want godoc to display OS documentation for another 11 | // system, set $GOOS and $GOARCH to the desired system. For example, if 12 | // you want to view documentation for freebsd/arm on linux/amd64, set $GOOS 13 | // to freebsd and $GOARCH to arm. 14 | // The primary use of this package is inside other packages that provide a more 15 | // portable interface to the system, such as "os", "time" and "net". Use 16 | // those packages rather than this one if you can. 17 | // For details of the functions and data types in this package consult 18 | // the manuals for the appropriate operating system. 19 | // These calls return err == nil to indicate success; otherwise 20 | // err represents an operating system error describing the failure and 21 | // holds a value of type syscall.Errno. 22 | package unix 23 | 24 | import "unsafe" 25 | 26 | // ByteSliceFromString returns a NUL-terminated slice of bytes 27 | // containing the text of s. If s contains a NUL byte at any 28 | // location, it returns (nil, EINVAL). 29 | func ByteSliceFromString(s string) ([]byte, error) { 30 | for i := 0; i < len(s); i++ { 31 | if s[i] == 0 { 32 | return nil, EINVAL 33 | } 34 | } 35 | a := make([]byte, len(s)+1) 36 | copy(a, s) 37 | return a, nil 38 | } 39 | 40 | // BytePtrFromString returns a pointer to a NUL-terminated array of 41 | // bytes containing the text of s. If s contains a NUL byte at any 42 | // location, it returns (nil, EINVAL). 43 | func BytePtrFromString(s string) (*byte, error) { 44 | a, err := ByteSliceFromString(s) 45 | if err != nil { 46 | return nil, err 47 | } 48 | return &a[0], nil 49 | } 50 | 51 | // Single-word zero for use when we need a valid pointer to 0 bytes. 52 | // See mkunix.pl. 53 | var _zero uintptr 54 | 55 | func (ts *Timespec) Unix() (sec int64, nsec int64) { 56 | return int64(ts.Sec), int64(ts.Nsec) 57 | } 58 | 59 | func (tv *Timeval) Unix() (sec int64, nsec int64) { 60 | return int64(tv.Sec), int64(tv.Usec) * 1000 61 | } 62 | 63 | func (ts *Timespec) Nano() int64 { 64 | return int64(ts.Sec)*1e9 + int64(ts.Nsec) 65 | } 66 | 67 | func (tv *Timeval) Nano() int64 { 68 | return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000 69 | } 70 | 71 | // use is a no-op, but the compiler cannot see that it is. 72 | // Calling use(p) ensures that p is kept live until that point. 73 | //go:noescape 74 | func use(p unsafe.Pointer) 75 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_stat_test.go: -------------------------------------------------------------------------------- 1 | package procfs 2 | 3 | import "testing" 4 | 5 | func TestProcStat(t *testing.T) { 6 | p, err := FS("fixtures").NewProc(26231) 7 | if err != nil { 8 | t.Fatal(err) 9 | } 10 | 11 | s, err := p.NewStat() 12 | if err != nil { 13 | t.Fatal(err) 14 | } 15 | 16 | for _, test := range []struct { 17 | name string 18 | want int 19 | have int 20 | }{ 21 | {name: "pid", want: 26231, have: s.PID}, 22 | {name: "user time", want: 1677, have: int(s.UTime)}, 23 | {name: "system time", want: 44, have: int(s.STime)}, 24 | {name: "start time", want: 82375, have: int(s.Starttime)}, 25 | {name: "virtual memory size", want: 56274944, have: s.VSize}, 26 | {name: "resident set size", want: 1981, have: s.RSS}, 27 | } { 28 | if test.want != test.have { 29 | t.Errorf("want %s %d, have %d", test.name, test.want, test.have) 30 | } 31 | } 32 | } 33 | 34 | func TestProcStatComm(t *testing.T) { 35 | s1, err := testProcStat(26231) 36 | if err != nil { 37 | t.Fatal(err) 38 | } 39 | if want, have := "vim", s1.Comm; want != have { 40 | t.Errorf("want comm %s, have %s", want, have) 41 | } 42 | 43 | s2, err := testProcStat(584) 44 | if err != nil { 45 | t.Fatal(err) 46 | } 47 | if want, have := "(a b ) ( c d) ", s2.Comm; want != have { 48 | t.Errorf("want comm %s, have %s", want, have) 49 | } 50 | } 51 | 52 | func TestProcStatVirtualMemory(t *testing.T) { 53 | s, err := testProcStat(26231) 54 | if err != nil { 55 | t.Fatal(err) 56 | } 57 | 58 | if want, have := 56274944, s.VirtualMemory(); want != have { 59 | t.Errorf("want virtual memory %d, have %d", want, have) 60 | } 61 | } 62 | 63 | func TestProcStatResidentMemory(t *testing.T) { 64 | s, err := testProcStat(26231) 65 | if err != nil { 66 | t.Fatal(err) 67 | } 68 | 69 | if want, have := 1981*4096, s.ResidentMemory(); want != have { 70 | t.Errorf("want resident memory %d, have %d", want, have) 71 | } 72 | } 73 | 74 | func TestProcStatStartTime(t *testing.T) { 75 | s, err := testProcStat(26231) 76 | if err != nil { 77 | t.Fatal(err) 78 | } 79 | 80 | time, err := s.StartTime() 81 | if err != nil { 82 | t.Fatal(err) 83 | } 84 | if want, have := 1418184099.75, time; want != have { 85 | t.Errorf("want start time %f, have %f", want, have) 86 | } 87 | } 88 | 89 | func TestProcStatCPUTime(t *testing.T) { 90 | s, err := testProcStat(26231) 91 | if err != nil { 92 | t.Fatal(err) 93 | } 94 | 95 | if want, have := 17.21, s.CPUTime(); want != have { 96 | t.Errorf("want cpu time %f, have %f", want, have) 97 | } 98 | } 99 | 100 | func testProcStat(pid int) (ProcStat, error) { 101 | p, err := FS("fixtures").NewProc(pid) 102 | if err != nil { 103 | return ProcStat{}, err 104 | } 105 | 106 | return p.NewStat() 107 | } 108 | -------------------------------------------------------------------------------- /metrics/custom_query.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "database/sql" 5 | "sync" 6 | 7 | "github.com/prometheus/client_golang/prometheus" 8 | "github.com/prometheus/log" 9 | ) 10 | 11 | type CustomQueryMetrics struct { 12 | mutex sync.Mutex 13 | cq []CustomQuery 14 | } 15 | 16 | func NewCustomQueryMetrics(cq []CustomQuery) *CustomQueryMetrics { 17 | return &CustomQueryMetrics{cq: cq} 18 | } 19 | 20 | func (c *CustomQueryMetrics) Scrape(db *sql.DB) error { 21 | c.mutex.Lock() 22 | defer c.mutex.Unlock() 23 | 24 | for i := range c.cq { 25 | err := c.cq[i].scrape(db) 26 | if err != nil { 27 | return err 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (c *CustomQueryMetrics) Describe(ch chan<- *prometheus.Desc) { 35 | for _, query := range c.cq { 36 | query.describe(ch) 37 | } 38 | } 39 | 40 | func (c *CustomQueryMetrics) Collect(ch chan<- prometheus.Metric) { 41 | for _, query := range c.cq { 42 | query.collect(ch) 43 | } 44 | } 45 | 46 | type CustomQuery struct { 47 | Name string 48 | Help string 49 | Query string 50 | 51 | colsCount int 52 | metric *prometheus.GaugeVec 53 | } 54 | 55 | func (c *CustomQuery) initMetric(rows *sql.Rows) error { 56 | cols, err := rows.Columns() 57 | if err != nil { 58 | return err 59 | } 60 | c.colsCount = len(cols) 61 | 62 | var labelNames []string 63 | if len(cols) > 0 { 64 | labelNames = cols[1:] 65 | } 66 | c.metric = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 67 | Namespace: namespace, 68 | Subsystem: "custom", 69 | Name: c.Name, 70 | Help: c.Help, 71 | }, labelNames) 72 | 73 | log.Infof("Initialized custom metric %s %s", c.Name, c.Query) 74 | 75 | return nil 76 | } 77 | 78 | func (c *CustomQuery) scrape(db *sql.DB) error { 79 | rows, err := db.Query(c.Query) 80 | if err != nil { 81 | return err 82 | } 83 | defer rows.Close() 84 | 85 | if c.metric == nil { 86 | err := c.initMetric(rows) 87 | if err != nil { 88 | return err 89 | } 90 | } 91 | 92 | for rows.Next() { 93 | var count int64 94 | labels := make([]string, c.colsCount-1) 95 | args := make([]interface{}, c.colsCount-1) 96 | for i := range args { 97 | args[i] = &labels[i] 98 | } 99 | args = append([]interface{}{&count}, args...) 100 | 101 | err = rows.Scan(args...) 102 | if err != nil { 103 | return err 104 | } 105 | 106 | c.metric.WithLabelValues(labels...).Set(float64(count)) 107 | } 108 | return nil 109 | } 110 | 111 | func (c *CustomQuery) describe(ch chan<- *prometheus.Desc) { 112 | if c.metric != nil { 113 | c.metric.Describe(ch) 114 | } 115 | } 116 | 117 | func (c *CustomQuery) collect(ch chan<- prometheus.Metric) { 118 | if c.metric != nil { 119 | c.metric.Collect(ch) 120 | } 121 | } 122 | 123 | // check interface 124 | var _ Collection = new(CustomQueryMetrics) 125 | -------------------------------------------------------------------------------- /vendor/github.com/lib/pq/README.md: -------------------------------------------------------------------------------- 1 | # pq - A pure Go postgres driver for Go's database/sql package 2 | 3 | [![Build Status](https://travis-ci.org/lib/pq.png?branch=master)](https://travis-ci.org/lib/pq) 4 | 5 | ## Install 6 | 7 | go get github.com/lib/pq 8 | 9 | ## Docs 10 | 11 | For detailed documentation and basic usage examples, please see the package 12 | documentation at . 13 | 14 | ## Tests 15 | 16 | `go test` is used for testing. A running PostgreSQL server is 17 | required, with the ability to log in. The default database to connect 18 | to test with is "pqgotest," but it can be overridden using environment 19 | variables. 20 | 21 | Example: 22 | 23 | PGHOST=/var/run/postgresql go test github.com/lib/pq 24 | 25 | Optionally, a benchmark suite can be run as part of the tests: 26 | 27 | PGHOST=/var/run/postgresql go test -bench . 28 | 29 | ## Features 30 | 31 | * SSL 32 | * Handles bad connections for `database/sql` 33 | * Scan `time.Time` correctly (i.e. `timestamp[tz]`, `time[tz]`, `date`) 34 | * Scan binary blobs correctly (i.e. `bytea`) 35 | * Package for `hstore` support 36 | * COPY FROM support 37 | * pq.ParseURL for converting urls to connection strings for sql.Open. 38 | * Many libpq compatible environment variables 39 | * Unix socket support 40 | * Notifications: `LISTEN`/`NOTIFY` 41 | 42 | ## Future / Things you can help with 43 | 44 | * Better COPY FROM / COPY TO (see discussion in #181) 45 | 46 | ## Thank you (alphabetical) 47 | 48 | Some of these contributors are from the original library `bmizerany/pq.go` whose 49 | code still exists in here. 50 | 51 | * Andy Balholm (andybalholm) 52 | * Ben Berkert (benburkert) 53 | * Benjamin Heatwole (bheatwole) 54 | * Bill Mill (llimllib) 55 | * Bjørn Madsen (aeons) 56 | * Blake Gentry (bgentry) 57 | * Brad Fitzpatrick (bradfitz) 58 | * Charlie Melbye (cmelbye) 59 | * Chris Bandy (cbandy) 60 | * Chris Walsh (cwds) 61 | * Daniel Farina (fdr) 62 | * Eric Chlebek (echlebek) 63 | * Everyone at The Go Team 64 | * Evan Shaw (edsrzf) 65 | * Ewan Chou (coocood) 66 | * Federico Romero (federomero) 67 | * Fumin (fumin) 68 | * Gary Burd (garyburd) 69 | * Heroku (heroku) 70 | * James Pozdena (jpoz) 71 | * Jason McVetta (jmcvetta) 72 | * Jeremy Jay (pbnjay) 73 | * Joakim Sernbrant (serbaut) 74 | * John Gallagher (jgallagher) 75 | * Joël Stemmer (jstemmer) 76 | * Kamil Kisiel (kisielk) 77 | * Kelly Dunn (kellydunn) 78 | * Keith Rarick (kr) 79 | * Kir Shatrov (kirs) 80 | * Lann Martin (lann) 81 | * Maciek Sakrejda (deafbybeheading) 82 | * Marc Brinkmann (mbr) 83 | * Marko Tiikkaja (johto) 84 | * Matt Newberry (MattNewberry) 85 | * Matt Robenolt (mattrobenolt) 86 | * Martin Olsen (martinolsen) 87 | * Mike Lewis (mikelikespie) 88 | * Nicolas Patry (Narsil) 89 | * Oliver Tonnhofer (olt) 90 | * Patrick Hayes (phayes) 91 | * Paul Hammond (paulhammond) 92 | * Ryan Smith (ryandotsmith) 93 | * Samuel Stauffer (samuel) 94 | * Timothée Peignier (cyberdelia) 95 | * notedit (notedit) 96 | -------------------------------------------------------------------------------- /metrics/slow_query.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "database/sql" 5 | "errors" 6 | "sync" 7 | "time" 8 | 9 | "github.com/prometheus/client_golang/prometheus" 10 | ) 11 | 12 | type SlowQueryMetrics struct { 13 | mutex sync.Mutex 14 | metrics map[string]prometheus.Gauge 15 | milliseconds int64 16 | } 17 | 18 | func NewSlowQueryMetrics(durationToConsiderSlow time.Duration) *SlowQueryMetrics { 19 | 20 | return &SlowQueryMetrics{ 21 | milliseconds: int64(durationToConsiderSlow / time.Millisecond), 22 | metrics: map[string]prometheus.Gauge{ 23 | "slow_queries": prometheus.NewGauge(prometheus.GaugeOpts{ 24 | Namespace: namespace, 25 | Name: "slow_queries_total", 26 | Help: "Number of slow queries", 27 | }), 28 | "slow_select_queries": prometheus.NewGauge(prometheus.GaugeOpts{ 29 | Namespace: namespace, 30 | Name: "slow_select_queries_total", 31 | Help: "Number of slow SELECT queries", 32 | }), 33 | "slow_dml_queries": prometheus.NewGauge(prometheus.GaugeOpts{ 34 | Namespace: namespace, 35 | Name: "slow_dml_queries_total", 36 | Help: "Number of slow data manipulation queries (INSERT, UPDATE, DELETE)", 37 | }), 38 | }, 39 | } 40 | } 41 | 42 | func (s *SlowQueryMetrics) Scrape(db *sql.DB) error { 43 | s.mutex.Lock() 44 | defer s.mutex.Unlock() 45 | 46 | var count float64 47 | err := db.QueryRow( 48 | `SELECT count(*) 49 | FROM monitoring.pg_stat_activity 50 | WHERE state = 'active' AND 51 | NOW() - query_start > ($1 || ' milliseconds')::interval`, 52 | s.milliseconds).Scan(&count) 53 | if err != nil { 54 | return errors.New("error counting slow queries: " + err.Error()) 55 | } 56 | s.metrics["slow_queries"].Set(count) 57 | 58 | err = db.QueryRow( 59 | `SELECT count(*) 60 | FROM monitoring.pg_stat_activity 61 | WHERE state = 'active' AND 62 | NOW() - query_start > ($1 || ' milliseconds' )::interval AND 63 | query ilike 'select%'`, 64 | s.milliseconds).Scan(&count) 65 | if err != nil { 66 | return errors.New("error counting slow select queries: " + err.Error()) 67 | } 68 | s.metrics["slow_select_queries"].Set(count) 69 | 70 | err = db.QueryRow( 71 | `SELECT count(*) 72 | FROM monitoring.pg_stat_activity 73 | WHERE state = 'active' AND 74 | NOW() - query_start > ($1 || ' milliseconds')::interval AND 75 | (query ilike 'insert%' OR query ilike 'update%' OR query ilike 'delete%')`, 76 | s.milliseconds).Scan(&count) 77 | if err != nil { 78 | return errors.New("error counting slow dml queries: " + err.Error()) 79 | } 80 | s.metrics["slow_dml_queries"].Set(count) 81 | 82 | return nil 83 | } 84 | 85 | func (s *SlowQueryMetrics) Describe(ch chan<- *prometheus.Desc) { 86 | for _, m := range s.metrics { 87 | m.Describe(ch) 88 | } 89 | } 90 | 91 | func (s *SlowQueryMetrics) Collect(ch chan<- prometheus.Metric) { 92 | for _, m := range s.metrics { 93 | m.Collect(ch) 94 | } 95 | } 96 | 97 | // check interface 98 | var _ Collection = new(SlowQueryMetrics) 99 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/sorter.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | import ( 4 | "reflect" 5 | "unicode" 6 | ) 7 | 8 | type keyList []reflect.Value 9 | 10 | func (l keyList) Len() int { return len(l) } 11 | func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } 12 | func (l keyList) Less(i, j int) bool { 13 | a := l[i] 14 | b := l[j] 15 | ak := a.Kind() 16 | bk := b.Kind() 17 | for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() { 18 | a = a.Elem() 19 | ak = a.Kind() 20 | } 21 | for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() { 22 | b = b.Elem() 23 | bk = b.Kind() 24 | } 25 | af, aok := keyFloat(a) 26 | bf, bok := keyFloat(b) 27 | if aok && bok { 28 | if af != bf { 29 | return af < bf 30 | } 31 | if ak != bk { 32 | return ak < bk 33 | } 34 | return numLess(a, b) 35 | } 36 | if ak != reflect.String || bk != reflect.String { 37 | return ak < bk 38 | } 39 | ar, br := []rune(a.String()), []rune(b.String()) 40 | for i := 0; i < len(ar) && i < len(br); i++ { 41 | if ar[i] == br[i] { 42 | continue 43 | } 44 | al := unicode.IsLetter(ar[i]) 45 | bl := unicode.IsLetter(br[i]) 46 | if al && bl { 47 | return ar[i] < br[i] 48 | } 49 | if al || bl { 50 | return bl 51 | } 52 | var ai, bi int 53 | var an, bn int64 54 | for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ { 55 | an = an*10 + int64(ar[ai]-'0') 56 | } 57 | for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ { 58 | bn = bn*10 + int64(br[bi]-'0') 59 | } 60 | if an != bn { 61 | return an < bn 62 | } 63 | if ai != bi { 64 | return ai < bi 65 | } 66 | return ar[i] < br[i] 67 | } 68 | return len(ar) < len(br) 69 | } 70 | 71 | // keyFloat returns a float value for v if it is a number/bool 72 | // and whether it is a number/bool or not. 73 | func keyFloat(v reflect.Value) (f float64, ok bool) { 74 | switch v.Kind() { 75 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 76 | return float64(v.Int()), true 77 | case reflect.Float32, reflect.Float64: 78 | return v.Float(), true 79 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 80 | return float64(v.Uint()), true 81 | case reflect.Bool: 82 | if v.Bool() { 83 | return 1, true 84 | } 85 | return 0, true 86 | } 87 | return 0, false 88 | } 89 | 90 | // numLess returns whether a < b. 91 | // a and b must necessarily have the same kind. 92 | func numLess(a, b reflect.Value) bool { 93 | switch a.Kind() { 94 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 95 | return a.Int() < b.Int() 96 | case reflect.Float32, reflect.Float64: 97 | return a.Float() < b.Float() 98 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 99 | return a.Uint() < b.Uint() 100 | case reflect.Bool: 101 | return !a.Bool() && b.Bool() 102 | } 103 | panic("not a number") 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/push.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Copyright (c) 2013, The Prometheus Authors 15 | // All rights reserved. 16 | // 17 | // Use of this source code is governed by a BSD-style license that can be found 18 | // in the LICENSE file. 19 | 20 | package prometheus 21 | 22 | // Push triggers a metric collection by the default registry and pushes all 23 | // collected metrics to the Pushgateway specified by addr. See the Pushgateway 24 | // documentation for detailed implications of the job and instance 25 | // parameter. instance can be left empty. You can use just host:port or ip:port 26 | // as url, in which case 'http://' is added automatically. You can also include 27 | // the schema in the URL. However, do not include the '/metrics/jobs/...' part. 28 | // 29 | // Note that all previously pushed metrics with the same job and instance will 30 | // be replaced with the metrics pushed by this call. (It uses HTTP method 'PUT' 31 | // to push to the Pushgateway.) 32 | func Push(job, instance, url string) error { 33 | return defRegistry.Push(job, instance, url, "PUT") 34 | } 35 | 36 | // PushAdd works like Push, but only previously pushed metrics with the same 37 | // name (and the same job and instance) will be replaced. (It uses HTTP method 38 | // 'POST' to push to the Pushgateway.) 39 | func PushAdd(job, instance, url string) error { 40 | return defRegistry.Push(job, instance, url, "POST") 41 | } 42 | 43 | // PushCollectors works like Push, but it does not collect from the default 44 | // registry. Instead, it collects from the provided collectors. It is a 45 | // convenient way to push only a few metrics. 46 | func PushCollectors(job, instance, url string, collectors ...Collector) error { 47 | return pushCollectors(job, instance, url, "PUT", collectors...) 48 | } 49 | 50 | // PushAddCollectors works like PushAdd, but it does not collect from the 51 | // default registry. Instead, it collects from the provided collectors. It is a 52 | // convenient way to push only a few metrics. 53 | func PushAddCollectors(job, instance, url string, collectors ...Collector) error { 54 | return pushCollectors(job, instance, url, "POST", collectors...) 55 | } 56 | 57 | func pushCollectors(job, instance, url, method string, collectors ...Collector) error { 58 | r := newRegistry() 59 | for _, collector := range collectors { 60 | if _, err := r.Register(collector); err != nil { 61 | return err 62 | } 63 | } 64 | return r.Push(job, instance, url, method) 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/go_collector_test.go: -------------------------------------------------------------------------------- 1 | package prometheus 2 | 3 | import ( 4 | "runtime" 5 | "testing" 6 | "time" 7 | 8 | dto "github.com/prometheus/client_model/go" 9 | ) 10 | 11 | func TestGoCollector(t *testing.T) { 12 | var ( 13 | c = NewGoCollector() 14 | ch = make(chan Metric) 15 | waitc = make(chan struct{}) 16 | closec = make(chan struct{}) 17 | old = -1 18 | ) 19 | defer close(closec) 20 | 21 | go func() { 22 | c.Collect(ch) 23 | go func(c <-chan struct{}) { 24 | <-c 25 | }(closec) 26 | <-waitc 27 | c.Collect(ch) 28 | }() 29 | 30 | for { 31 | select { 32 | case metric := <-ch: 33 | switch m := metric.(type) { 34 | // Attention, this also catches Counter... 35 | case Gauge: 36 | pb := &dto.Metric{} 37 | m.Write(pb) 38 | if pb.GetGauge() == nil { 39 | continue 40 | } 41 | 42 | if old == -1 { 43 | old = int(pb.GetGauge().GetValue()) 44 | close(waitc) 45 | continue 46 | } 47 | 48 | if diff := int(pb.GetGauge().GetValue()) - old; diff != 1 { 49 | // TODO: This is flaky in highly concurrent situations. 50 | t.Errorf("want 1 new goroutine, got %d", diff) 51 | } 52 | 53 | return 54 | } 55 | case <-time.After(1 * time.Second): 56 | t.Fatalf("expected collect timed out") 57 | } 58 | } 59 | } 60 | 61 | func TestGCCollector(t *testing.T) { 62 | var ( 63 | c = NewGoCollector() 64 | ch = make(chan Metric) 65 | waitc = make(chan struct{}) 66 | closec = make(chan struct{}) 67 | oldGC uint64 68 | oldPause float64 69 | ) 70 | defer close(closec) 71 | 72 | go func() { 73 | c.Collect(ch) 74 | // force GC 75 | runtime.GC() 76 | <-waitc 77 | c.Collect(ch) 78 | }() 79 | 80 | first := true 81 | for { 82 | select { 83 | case metric := <-ch: 84 | switch m := metric.(type) { 85 | case *constSummary, *value: 86 | pb := &dto.Metric{} 87 | m.Write(pb) 88 | if pb.GetSummary() == nil { 89 | continue 90 | } 91 | 92 | if len(pb.GetSummary().Quantile) != 5 { 93 | t.Errorf("expected 4 buckets, got %d", len(pb.GetSummary().Quantile)) 94 | } 95 | for idx, want := range []float64{0.0, 0.25, 0.5, 0.75, 1.0} { 96 | if *pb.GetSummary().Quantile[idx].Quantile != want { 97 | t.Errorf("bucket #%d is off, got %f, want %f", idx, *pb.GetSummary().Quantile[idx].Quantile, want) 98 | } 99 | } 100 | if first { 101 | first = false 102 | oldGC = *pb.GetSummary().SampleCount 103 | oldPause = *pb.GetSummary().SampleSum 104 | close(waitc) 105 | continue 106 | } 107 | if diff := *pb.GetSummary().SampleCount - oldGC; diff != 1 { 108 | t.Errorf("want 1 new garbage collection run, got %d", diff) 109 | } 110 | if diff := *pb.GetSummary().SampleSum - oldPause; diff <= 0 { 111 | t.Errorf("want moar pause, got %f", diff) 112 | } 113 | return 114 | } 115 | case <-time.After(1 * time.Second): 116 | t.Fatalf("expected collect timed out") 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package pbutil 16 | 17 | import ( 18 | "encoding/binary" 19 | "errors" 20 | "io" 21 | 22 | "github.com/golang/protobuf/proto" 23 | ) 24 | 25 | var errInvalidVarint = errors.New("invalid varint32 encountered") 26 | 27 | // ReadDelimited decodes a message from the provided length-delimited stream, 28 | // where the length is encoded as 32-bit varint prefix to the message body. 29 | // It returns the total number of bytes read and any applicable error. This is 30 | // roughly equivalent to the companion Java API's 31 | // MessageLite#parseDelimitedFrom. As per the reader contract, this function 32 | // calls r.Read repeatedly as required until exactly one message including its 33 | // prefix is read and decoded (or an error has occurred). The function never 34 | // reads more bytes from the stream than required. The function never returns 35 | // an error if a message has been read and decoded correctly, even if the end 36 | // of the stream has been reached in doing so. In that case, any subsequent 37 | // calls return (0, io.EOF). 38 | func ReadDelimited(r io.Reader, m proto.Message) (n int, err error) { 39 | // Per AbstractParser#parsePartialDelimitedFrom with 40 | // CodedInputStream#readRawVarint32. 41 | headerBuf := make([]byte, binary.MaxVarintLen32) 42 | var bytesRead, varIntBytes int 43 | var messageLength uint64 44 | for varIntBytes == 0 { // i.e. no varint has been decoded yet. 45 | if bytesRead >= len(headerBuf) { 46 | return bytesRead, errInvalidVarint 47 | } 48 | // We have to read byte by byte here to avoid reading more bytes 49 | // than required. Each read byte is appended to what we have 50 | // read before. 51 | newBytesRead, err := r.Read(headerBuf[bytesRead : bytesRead+1]) 52 | if newBytesRead == 0 { 53 | if err != nil { 54 | return bytesRead, err 55 | } 56 | // A Reader should not return (0, nil), but if it does, 57 | // it should be treated as no-op (according to the 58 | // Reader contract). So let's go on... 59 | continue 60 | } 61 | bytesRead += newBytesRead 62 | // Now present everything read so far to the varint decoder and 63 | // see if a varint can be decoded already. 64 | messageLength, varIntBytes = proto.DecodeVarint(headerBuf[:bytesRead]) 65 | } 66 | 67 | messageBuf := make([]byte, messageLength) 68 | newBytesRead, err := io.ReadFull(r, messageBuf) 69 | bytesRead += newBytesRead 70 | if err != nil { 71 | return bytesRead, err 72 | } 73 | 74 | return bytesRead, proto.Unmarshal(messageBuf, m) 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/model/fingerprinting.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "fmt" 18 | "strconv" 19 | ) 20 | 21 | // Fingerprint provides a hash-capable representation of a Metric. 22 | // For our purposes, FNV-1A 64-bit is used. 23 | type Fingerprint uint64 24 | 25 | func (f Fingerprint) String() string { 26 | return fmt.Sprintf("%016x", uint64(f)) 27 | } 28 | 29 | // Less implements sort.Interface. 30 | func (f Fingerprint) Less(o Fingerprint) bool { 31 | return f < o 32 | } 33 | 34 | // Equal implements sort.Interface. 35 | func (f Fingerprint) Equal(o Fingerprint) bool { 36 | return f == o 37 | } 38 | 39 | // LoadFromString transforms a string representation into a Fingerprint. 40 | func (f *Fingerprint) LoadFromString(s string) error { 41 | num, err := strconv.ParseUint(s, 16, 64) 42 | if err != nil { 43 | return err 44 | } 45 | *f = Fingerprint(num) 46 | return nil 47 | } 48 | 49 | // Fingerprints represents a collection of Fingerprint subject to a given 50 | // natural sorting scheme. It implements sort.Interface. 51 | type Fingerprints []Fingerprint 52 | 53 | // Len implements sort.Interface. 54 | func (f Fingerprints) Len() int { 55 | return len(f) 56 | } 57 | 58 | // Less implements sort.Interface. 59 | func (f Fingerprints) Less(i, j int) bool { 60 | return f[i] < f[j] 61 | } 62 | 63 | // Swap implements sort.Interface. 64 | func (f Fingerprints) Swap(i, j int) { 65 | f[i], f[j] = f[j], f[i] 66 | } 67 | 68 | // FingerprintSet is a set of Fingerprints. 69 | type FingerprintSet map[Fingerprint]struct{} 70 | 71 | // Equal returns true if both sets contain the same elements (and not more). 72 | func (s FingerprintSet) Equal(o FingerprintSet) bool { 73 | if len(s) != len(o) { 74 | return false 75 | } 76 | 77 | for k := range s { 78 | if _, ok := o[k]; !ok { 79 | return false 80 | } 81 | } 82 | 83 | return true 84 | } 85 | 86 | // Intersection returns the elements contained in both sets. 87 | func (s FingerprintSet) Intersection(o FingerprintSet) FingerprintSet { 88 | myLength, otherLength := len(s), len(o) 89 | if myLength == 0 || otherLength == 0 { 90 | return FingerprintSet{} 91 | } 92 | 93 | subSet := s 94 | superSet := o 95 | 96 | if otherLength < myLength { 97 | subSet = o 98 | superSet = s 99 | } 100 | 101 | out := FingerprintSet{} 102 | 103 | for k := range subSet { 104 | if _, ok := superSet[k]; ok { 105 | out[k] = struct{}{} 106 | } 107 | } 108 | 109 | return out 110 | } 111 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/example_memstats_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus_test 15 | 16 | import ( 17 | "runtime" 18 | 19 | "github.com/prometheus/client_golang/prometheus" 20 | ) 21 | 22 | var ( 23 | allocDesc = prometheus.NewDesc( 24 | prometheus.BuildFQName("", "memstats", "alloc_bytes"), 25 | "bytes allocated and still in use", 26 | nil, nil, 27 | ) 28 | totalAllocDesc = prometheus.NewDesc( 29 | prometheus.BuildFQName("", "memstats", "total_alloc_bytes"), 30 | "bytes allocated (even if freed)", 31 | nil, nil, 32 | ) 33 | numGCDesc = prometheus.NewDesc( 34 | prometheus.BuildFQName("", "memstats", "num_gc_total"), 35 | "number of GCs run", 36 | nil, nil, 37 | ) 38 | ) 39 | 40 | // MemStatsCollector is an example for a custom Collector that solves the 41 | // problem of feeding into multiple metrics at the same time. The 42 | // runtime.ReadMemStats should happen only once, and then the results need to be 43 | // fed into a number of separate Metrics. In this example, only a few of the 44 | // values reported by ReadMemStats are used. For each, there is a Desc provided 45 | // as a var, so the MemStatsCollector itself needs nothing else in the 46 | // struct. Only the methods need to be implemented. 47 | type MemStatsCollector struct{} 48 | 49 | // Describe just sends the three Desc objects for the Metrics we intend to 50 | // collect. 51 | func (_ MemStatsCollector) Describe(ch chan<- *prometheus.Desc) { 52 | ch <- allocDesc 53 | ch <- totalAllocDesc 54 | ch <- numGCDesc 55 | } 56 | 57 | // Collect does the trick by calling ReadMemStats once and then constructing 58 | // three different Metrics on the fly. 59 | func (_ MemStatsCollector) Collect(ch chan<- prometheus.Metric) { 60 | var ms runtime.MemStats 61 | runtime.ReadMemStats(&ms) 62 | ch <- prometheus.MustNewConstMetric( 63 | allocDesc, 64 | prometheus.GaugeValue, 65 | float64(ms.Alloc), 66 | ) 67 | ch <- prometheus.MustNewConstMetric( 68 | totalAllocDesc, 69 | prometheus.GaugeValue, 70 | float64(ms.TotalAlloc), 71 | ) 72 | ch <- prometheus.MustNewConstMetric( 73 | numGCDesc, 74 | prometheus.CounterValue, 75 | float64(ms.NumGC), 76 | ) 77 | // To avoid new allocations on each collection, you could also keep 78 | // metric objects around and return the same objects each time, just 79 | // with new values set. 80 | } 81 | 82 | func ExampleCollector_memstats() { 83 | prometheus.MustRegister(&MemStatsCollector{}) 84 | // Since we are dealing with custom Collector implementations, it might 85 | // be a good idea to enable the collect checks in the registry. 86 | prometheus.EnableCollectChecks(true) 87 | } 88 | --------------------------------------------------------------------------------