-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Read target data details * Save meta data * Dump all metrics for defined jobs * Add gitgub automation * Update read me
- Loading branch information
Showing
15 changed files
with
682 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Go 1.x | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.14 | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
if [ -f Gopkg.toml ]; then | ||
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
dep ensure | ||
fi | ||
- name: Build | ||
run: go build -v -ldflags="-X 'main.Version=0.0.1' -X 'main.Branch=$(git rev-parse --short HEAD)' -X 'main.BuildDate=$(date -Is)' -X main.BuildUser='$(id -u -n)'" . | ||
|
||
- name: Test | ||
run: go test -v . | ||
|
||
- name: Show Data | ||
run: ./prometehus_export --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Release Go Binaries | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
#env: | ||
# CMD_PATH: ./cmd/vt2geojson | ||
|
||
|
||
jobs: | ||
releases-matrix: | ||
name: Release Matrix | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
goos: [linux, windows, darwin] | ||
goarch: [amd64, arm64] | ||
exclude: | ||
# windows/arm64 and darwin/arm64 seems useless | ||
- goarch: arm64 | ||
goos: darwin | ||
- goarch: arm64 | ||
goos: windows | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set APP_VERSION env | ||
run: echo ::set-env name=APP_VERSION::$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) | ||
- name: Set BUILD_TIME env | ||
run: echo ::set-env name=BUILD_TIME::$(date) | ||
- name: Environment Printer | ||
uses: managedkaos/[email protected] | ||
|
||
- uses: wangyoucao577/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
goos: ${{ matrix.goos }} | ||
goarch: ${{ matrix.goarch }} | ||
pre_command: go get -v ./... | ||
# project_path: "${{ env.CMD_PATH }}" | ||
build_flags: -v | ||
ldflags: -X "main.Version=${{ env.APP_VERSION }}" -X "main.BuildDate=${{ env.BUILD_TIME }}" -X main.Branch=${{ github.sha }} -X main.Revision=${{ github.ref }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
# Prometheus Export | ||
Dump data from prometheus to JSON file | ||
Dump data from prometheus to JSON files. | ||
|
||
Program dump all metrics for selected jobs into JSON files. | ||
|
||
## Configuration | ||
|
||
Program has config file. | ||
```yaml | ||
server: perftcl2.perflab.zoomint.com | ||
path: ./dump | ||
days: 2 | ||
jobs: | ||
- node_exporter_zqm | ||
- cucm_monitor | ||
``` | ||
- **server** - FQDN or IP address of prometheus server | ||
- **path** - Path for store export data | ||
- **days** - Number of day to exports (1-60) | ||
- **jobs** - limit data only for target jobs. If omitted or empty mean export all jobs | ||
## Line parameters | ||
- **--config.show** - show actual configuration and exit | ||
- **--config.file=cfg.yml** - define config file, defaul is cfg.yml | ||
- **--path=./dump** - overwrite path defined in config file | ||
- **--server=IP** - FQDN or IP address of prometheus server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"github.com/go-kit/kit/log/level" | ||
"io/ioutil" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
const UriFormat = "http://%s:9090/api/v1/%s" | ||
|
||
func getFormUri(uri string) (data []byte, err error) { | ||
uri = fmt.Sprintf(UriFormat, config.Server, uri) | ||
_ = level.Info(logger).Log("msg", "read data from server ", "uri", uri) | ||
req, err := http.NewRequest("GET", uri, nil) | ||
if err != nil { | ||
_ = level.Error(logger).Log("msg", "problem create request for uri "+uri, "error", err) | ||
return nil, err | ||
} | ||
return finishApiRequest(req) | ||
} | ||
|
||
//func postFromUri(uri string, body []byte) (data []byte, err error) { | ||
// uri = fmt.Sprintf(UriFormat, config.Server, uri) | ||
// _ = level.Info(logger).Log("msg", "post and read data from server ", "uri", uri) | ||
// req, err := http.NewRequest("POST", uri, bytes.NewBuffer(body)) | ||
// if err != nil { | ||
// _ = level.Error(logger).Log("msg", "problem create request for uri "+uri, "error", err) | ||
// return nil, err | ||
// } | ||
// return finishApiRequest(req) | ||
//} | ||
|
||
func finishApiRequest(req *http.Request) (data []byte, err error) { | ||
tr := &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
} | ||
client := &http.Client{Timeout: time.Duration(connectionTimeout) * time.Second, Transport: tr} | ||
_ = level.Debug(logger).Log("msg", "try read data from uri") | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
_ = level.Error(logger).Log("msg", "problem get data from server", "error", err) | ||
return nil, err | ||
} | ||
defer func() { _ = resp.Body.Close() }() | ||
bodies, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
_ = level.Error(logger).Log("msg", "problem read data from response", "error", err) | ||
return nil, err | ||
} | ||
_ = level.Debug(logger).Log("msg", "success read "+string(len(bodies))+" bytes from uri") | ||
return bodies, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/go-kit/kit/log/level" | ||
) | ||
|
||
type errorType string | ||
|
||
type ApiResponse struct { | ||
Status string `json:"status"` | ||
Data *json.RawMessage `json:"data,omitempty"` | ||
ErrorType errorType `json:"errorType,omitempty"` | ||
Error string `json:"error,omitempty"` | ||
Warnings []string `json:"warnings,omitempty"` | ||
Response []byte | ||
} | ||
|
||
func GetApiData(uri string) (*ApiResponse, error) { | ||
data, err := getFormUri(uri) | ||
if err != nil { | ||
_ = level.Error(logger).Log("msg", "problem collect targets details") | ||
return nil, err | ||
} | ||
var api ApiResponse | ||
if err := json.Unmarshal(data, &api); err != nil { | ||
return nil, err | ||
} | ||
api.Response = make([]byte, len(data)) | ||
copy(api.Response, data) | ||
return &api, nil | ||
} | ||
|
||
func (a *ApiResponse) statusSuccess() bool { | ||
return a.Status == "success" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
server: perftcl2.perflab.zoomint.com | ||
path: ./dump | ||
days: 2 | ||
jobs: | ||
- node_exporter_zqm | ||
- cucm_monitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.