created docker-prometheus compose file and edited the Prometheus yml file
This commit is contained in:
64
prom/storage/metric/labelpair.go
Normal file
64
prom/storage/metric/labelpair.go
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright 2013 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric
|
||||
|
||||
import (
|
||||
clientmodel "github.com/prometheus/client_golang/model"
|
||||
)
|
||||
|
||||
// LabelPair pairs a name with a value.
|
||||
type LabelPair struct {
|
||||
Name clientmodel.LabelName
|
||||
Value clientmodel.LabelValue
|
||||
}
|
||||
|
||||
// Equal returns true iff both the Name and the Value of this LabelPair and o
|
||||
// are equal.
|
||||
func (l *LabelPair) Equal(o *LabelPair) bool {
|
||||
switch {
|
||||
case l.Name != o.Name:
|
||||
return false
|
||||
case l.Value != o.Value:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// LabelPairs is a sortable slice of LabelPair pointers. It implements
|
||||
// sort.Interface.
|
||||
type LabelPairs []*LabelPair
|
||||
|
||||
func (l LabelPairs) Len() int {
|
||||
return len(l)
|
||||
}
|
||||
|
||||
func (l LabelPairs) Less(i, j int) bool {
|
||||
switch {
|
||||
case l[i].Name > l[j].Name:
|
||||
return false
|
||||
case l[i].Name < l[j].Name:
|
||||
return true
|
||||
case l[i].Value > l[j].Value:
|
||||
return false
|
||||
case l[i].Value < l[j].Value:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (l LabelPairs) Swap(i, j int) {
|
||||
l[i], l[j] = l[j], l[i]
|
||||
}
|
83
prom/storage/metric/labelpair_test.go
Normal file
83
prom/storage/metric/labelpair_test.go
Normal file
@ -0,0 +1,83 @@
|
||||
// Copyright 2013 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testLabelPairs(t testing.TB) {
|
||||
var scenarios = []struct {
|
||||
in LabelPairs
|
||||
out LabelPairs
|
||||
}{
|
||||
{
|
||||
in: LabelPairs{
|
||||
{
|
||||
Name: "AAA",
|
||||
Value: "aaa",
|
||||
},
|
||||
},
|
||||
out: LabelPairs{
|
||||
{
|
||||
Name: "AAA",
|
||||
Value: "aaa",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
in: LabelPairs{
|
||||
{
|
||||
Name: "aaa",
|
||||
Value: "aaa",
|
||||
},
|
||||
{
|
||||
Name: "ZZZ",
|
||||
Value: "aaa",
|
||||
},
|
||||
},
|
||||
out: LabelPairs{
|
||||
{
|
||||
Name: "ZZZ",
|
||||
Value: "aaa",
|
||||
},
|
||||
{
|
||||
Name: "aaa",
|
||||
Value: "aaa",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, scenario := range scenarios {
|
||||
sort.Sort(scenario.in)
|
||||
|
||||
for j, expected := range scenario.out {
|
||||
if !expected.Equal(scenario.in[j]) {
|
||||
t.Errorf("%d.%d expected %s, got %s", i, j, expected, scenario.in[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelPairs(t *testing.T) {
|
||||
testLabelPairs(t)
|
||||
}
|
||||
|
||||
func BenchmarkLabelPairs(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testLabelPairs(b)
|
||||
}
|
||||
}
|
105
prom/storage/metric/matcher.go
Normal file
105
prom/storage/metric/matcher.go
Normal file
@ -0,0 +1,105 @@
|
||||
// Copyright 2014 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
clientmodel "github.com/prometheus/client_golang/model"
|
||||
)
|
||||
|
||||
// MatchType is an enum for label matching types.
|
||||
type MatchType int
|
||||
|
||||
// Possible MatchTypes.
|
||||
const (
|
||||
Equal MatchType = iota
|
||||
NotEqual
|
||||
RegexMatch
|
||||
RegexNoMatch
|
||||
)
|
||||
|
||||
func (m MatchType) String() string {
|
||||
typeToStr := map[MatchType]string{
|
||||
Equal: "=",
|
||||
NotEqual: "!=",
|
||||
RegexMatch: "=~",
|
||||
RegexNoMatch: "!~",
|
||||
}
|
||||
if str, ok := typeToStr[m]; ok {
|
||||
return str
|
||||
}
|
||||
panic("unknown match type")
|
||||
}
|
||||
|
||||
// LabelMatchers is a slice of LabelMatcher objects.
|
||||
type LabelMatchers []*LabelMatcher
|
||||
|
||||
// LabelMatcher models the matching of a label.
|
||||
type LabelMatcher struct {
|
||||
Type MatchType
|
||||
Name clientmodel.LabelName
|
||||
Value clientmodel.LabelValue
|
||||
re *regexp.Regexp
|
||||
}
|
||||
|
||||
// NewLabelMatcher returns a LabelMatcher object ready to use.
|
||||
func NewLabelMatcher(matchType MatchType, name clientmodel.LabelName, value clientmodel.LabelValue) (*LabelMatcher, error) {
|
||||
m := &LabelMatcher{
|
||||
Type: matchType,
|
||||
Name: name,
|
||||
Value: value,
|
||||
}
|
||||
if matchType == RegexMatch || matchType == RegexNoMatch {
|
||||
re, err := regexp.Compile(string(value))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.re = re
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m *LabelMatcher) String() string {
|
||||
return fmt.Sprintf("%s%s%q", m.Name, m.Type, m.Value)
|
||||
}
|
||||
|
||||
// Match returns true if the label matcher matches the supplied label value.
|
||||
func (m *LabelMatcher) Match(v clientmodel.LabelValue) bool {
|
||||
switch m.Type {
|
||||
case Equal:
|
||||
return m.Value == v
|
||||
case NotEqual:
|
||||
return m.Value != v
|
||||
case RegexMatch:
|
||||
return m.re.MatchString(string(v))
|
||||
case RegexNoMatch:
|
||||
return !m.re.MatchString(string(v))
|
||||
default:
|
||||
panic("invalid match type")
|
||||
}
|
||||
}
|
||||
|
||||
// Filter takes a list of label values and returns all label values which match
|
||||
// the label matcher.
|
||||
func (m *LabelMatcher) Filter(in clientmodel.LabelValues) clientmodel.LabelValues {
|
||||
out := clientmodel.LabelValues{}
|
||||
for _, v := range in {
|
||||
if m.Match(v) {
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
55
prom/storage/metric/sample.go
Normal file
55
prom/storage/metric/sample.go
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright 2013 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
clientmodel "github.com/prometheus/client_golang/model"
|
||||
)
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (s SamplePair) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf("[%s, \"%s\"]", s.Timestamp.String(), strconv.FormatFloat(float64(s.Value), 'f', -1, 64))), nil
|
||||
}
|
||||
|
||||
// SamplePair pairs a SampleValue with a Timestamp.
|
||||
type SamplePair struct {
|
||||
Timestamp clientmodel.Timestamp
|
||||
Value clientmodel.SampleValue
|
||||
}
|
||||
|
||||
// Equal returns true if this SamplePair and o have equal Values and equal
|
||||
// Timestamps.
|
||||
func (s *SamplePair) Equal(o *SamplePair) bool {
|
||||
if s == o {
|
||||
return true
|
||||
}
|
||||
|
||||
return s.Value.Equal(o.Value) && s.Timestamp.Equal(o.Timestamp)
|
||||
}
|
||||
|
||||
func (s *SamplePair) String() string {
|
||||
return fmt.Sprintf("SamplePair at %s of %s", s.Timestamp, s.Value)
|
||||
}
|
||||
|
||||
// Values is a slice of SamplePairs.
|
||||
type Values []SamplePair
|
||||
|
||||
// Interval describes the inclusive interval between two Timestamps.
|
||||
type Interval struct {
|
||||
OldestInclusive clientmodel.Timestamp
|
||||
NewestInclusive clientmodel.Timestamp
|
||||
}
|
Reference in New Issue
Block a user