63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
// Copyright 2015 Google Inc. All Rights Reserved.
|
|
//
|
|
// 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 collector
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"time"
|
|
|
|
"github.com/google/cadvisor/info/v1"
|
|
)
|
|
|
|
type GenericCollector struct {
|
|
//name of the collector
|
|
name string
|
|
|
|
//holds information extracted from the config file for a collector
|
|
configFile Config
|
|
}
|
|
|
|
//Returns a new collector using the information extracted from the configfile
|
|
func NewCollector(collectorName string, configfile string) (*GenericCollector, error) {
|
|
configFile, err := ioutil.ReadFile(configfile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var configInJSON Config
|
|
err = json.Unmarshal(configFile, &configInJSON)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
//TODO : Add checks for validity of config file (eg : Accurate JSON fields)
|
|
|
|
return &GenericCollector{
|
|
name: collectorName, configFile: configInJSON,
|
|
}, nil
|
|
}
|
|
|
|
//Returns name of the collector
|
|
func (collector *GenericCollector) Name() string {
|
|
return collector.name
|
|
}
|
|
|
|
//Returns collected metrics and the next collection time of the collector
|
|
func (collector *GenericCollector) Collect() (time.Time, []v1.Metric, error) {
|
|
//TO BE IMPLEMENTED
|
|
return time.Now(), nil, nil
|
|
}
|