Skip to content

Commit

Permalink
feat: apache exporter (#1059)
Browse files Browse the repository at this point in the history
* feat: apache exporter

* chore: add license and readme
  • Loading branch information
kongfei605 authored Sep 21, 2024
1 parent fe22938 commit e84b8f4
Show file tree
Hide file tree
Showing 6 changed files with 730 additions and 0 deletions.
1 change: 1 addition & 0 deletions agent/metrics_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// auto registry
_ "flashcat.cloud/categraf/inputs/aliyun"
_ "flashcat.cloud/categraf/inputs/apache"
_ "flashcat.cloud/categraf/inputs/appdynamics"
_ "flashcat.cloud/categraf/inputs/arp_packet"
_ "flashcat.cloud/categraf/inputs/bind"
Expand Down
9 changes: 9 additions & 0 deletions conf/input.apache/apache.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[instances]]

# https://statuslist.app/apache/apache-status-page-simple-setup-guide/
# scrape_uri = "http://localhost/server-status/?auto"
# host_override = ""
# insecure = false
# custom_headers = {}
# level: debug,info,warn,error
# log_level = "info"
21 changes: 21 additions & 0 deletions inputs/apache/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 neezgee

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions inputs/apache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
forked from [apache/README.md](https://github.com/Lusitaniae/apache_exporter/tree/master/README.md)

```
[[instances]]
## apache 如何设置server-status页面 https://statuslist.app/apache/apache-status-page-simple-setup-guide/
## 这里填写apache server-status页面的地址
# scrape_uri = "http://localhost/server-status/?auto"
## 是否覆盖host
# host_override = ""
## 是否跳过https证书验证
# insecure = false
## 自定义请求header
# custom_headers = {}
## 日志级别
# level: debug,info,warn,error
# log_level = "info"
```
100 changes: 100 additions & 0 deletions inputs/apache/apache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package apache

import (
"fmt"
"log"

"github.com/prometheus/common/promlog"

"flashcat.cloud/categraf/config"
"flashcat.cloud/categraf/inputs"
"flashcat.cloud/categraf/inputs/apache/exporter"
"flashcat.cloud/categraf/types"
)

const inputName = "apache"

type Apache struct {
config.PluginConfig
Instances []*Instance `toml:"instances"`
}

type Instance struct {
config.InstanceConfig
LogLevel string `toml:"log_level"`
exporter.Config

e *exporter.Exporter
}

var _ inputs.Input = new(Apache)
var _ inputs.SampleGatherer = new(Instance)
var _ inputs.InstancesGetter = new(Apache)

func init() {
inputs.Add(inputName, func() inputs.Input {
return &Apache{}
})
}

func (a *Apache) Clone() inputs.Input {
return &Apache{}
}

func (a *Apache) Name() string {
return inputName
}

func (a *Apache) GetInstances() []inputs.Instance {
ret := make([]inputs.Instance, len(a.Instances))
for i := 0; i < len(a.Instances); i++ {
ret[i] = a.Instances[i]
}
return ret
}

func (a *Apache) Drop() {

for _, i := range a.Instances {
if i == nil {
continue
}

if i.e != nil {
i.e.Close()
}
}
}

func (ins *Instance) Init() error {
if len(ins.ScrapeURI) == 0 {
return types.ErrInstancesEmpty
}

if len(ins.LogLevel) == 0 {
ins.LogLevel = "info"
}
promlogConfig := &promlog.Config{
Level: &promlog.AllowedLevel{},
}
promlogConfig.Level.Set(ins.LogLevel)
logger := promlog.New(promlogConfig)
e, err := exporter.New(logger, &ins.Config)

if err != nil {
return fmt.Errorf("could not instantiate mongodb lag exporter: %w", err)
}

ins.e = e
return nil

}

func (ins *Instance) Gather(slist *types.SampleList) {

// collect
err := inputs.Collect(ins.e, slist)
if err != nil {
log.Println("E! failed to collect metrics:", err)
}
}
Loading

0 comments on commit e84b8f4

Please sign in to comment.