Skip to content

Commit

Permalink
* Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer committed Aug 1, 2016
0 parents commit 0dadff6
Show file tree
Hide file tree
Showing 13 changed files with 873 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.build
*.tar.gz
*-stamp
*.iml
.idea
build
.gradle
vendor
33 changes: 33 additions & 0 deletions CurrentStatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

type CurrentStatus struct {
Code int `json:"code"`
ErrorCode int `json:"error_code"`
Message string `json:"message"`
Data CurrentStatusData `json:"data"`
}

type CurrentStatusData struct {
Monitors []CurrentStatusMonitor `json:"monitors"`
MonitorGroups []CurrentStatusMonitorGroup `json:"monitor_groups"`
}

type CurrentStatusMonitorGroup struct {
Id string `json:"group_id"`
Name string `json:"group_name"`
Status int `json:"status"`
Monitors []CurrentStatusMonitor `json:"monitors"`
}

type CurrentStatusMonitor struct {
Id string `json:"monitor_id"`
Name string `json:"name"`
Type string `json:"monitor_type"`
Status int `json:"status"`
Locations []CurrentStatusLocation `json:"locations"`
}

type CurrentStatusLocation struct {
Name string `json:"location_name"`
Status int `json:"status"`
}
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
https-enabler
The MIT License (MIT)

Copyright (c) echocat

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.
120 changes: 120 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# site24x7 Exporter

site24x7 exporter for prometheus.io, written in go.

## Get it

Download your version from the [releases page](https://github.com/echocat/site24x7_exporter/releases/latest). For older version see [archive page](https://github.com/echocat/site24x7_exporter/releases).

Example:
```bash
sudo curl -SL https://github.com/echocat/site24x7_exporter/releases/download/v0.1.0/site24x7_exporter-linux-amd64 \
> /usr/bin/site24x7_exporter
sudo chmod +x /usr/bin/site24x7_exporter
```

## Use it

### Usage

```
Usage: site24x7_exporter <flags>
Flags:
-site24x7.timeout duration
Timeout for trying to get stats from site24x7. (default 5s)
-site24x7.token string
Token to access the API of site24x7.
See: https://www.site24x7.com/app/client#/admin/developer/api
-web.listen-address string
Address to listen on for web interface and telemetry. (default ":9112")
-web.telemetry-path string
Path under which to expose metrics. (default "/metrics")
-web.tls-cert string
Path to PEM file that conains the certificate (and optionally also the private key in PEM format).
This should include the whole certificate chain.
If provided: The web socket will be a HTTPS socket.
If not provided: Only HTTP.
-web.tls-client-ca string
Path to PEM file that conains the CAs that are trused for client connections.
If provided: Connecting clients should present a certificate signed by one of this CAs.
If not provided: Every client will be accepted.
-web.tls-private-key string
Path to PEM file that contains the private key (if not contained in web.tls-cert file).
```

### Examples

```bash
# Simply start the exporter with your token and listen on 0.0.0.0:9112
site24x7_exporter -site24x7.token=mySecrectToken

# Start the exporter with your token and listen on 0.0.0.0:9112
# ...it also secures the connector via SSL
site24x7_exporter -listen.address=:8443 \
-web.tls-cert=my.server.com.pem

# Simply start the exporter with your token and listen on 0.0.0.0:9112
# ...secures the connector via SSL
# ...and requires client certificates signed by your authority
site24x7_exporter -listen.address=:8443 \
-web.tls-cert=my.server.com.pem \
-web.tls-client-ca=ca.pem
```

## Build it

### Precondition

For building site24x7_exporter there is only:

1. a compatible operating system (Linux, Windows or Mac OS X)
2. and a working [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) installation required.

There is no need for a working and installed Go installation (or anything else). The build system will download every dependency and build it if necessary.

> **Hint:** The Go runtime build by the build system will be placed under ``~/.go/sdk``.
### Run build process

On Linux and Mac OS X:
```bash
# Build binaries (includes test)
./gradlew build

# Run tests (but do not build binaries)
./gradlew test

# Build binaries and release it on GitHub
# Environment variable GITHUB_TOKEN is required
./gradlew build githubRelease
```

On Windows:
```bash
# Build binaries (includes test)
gradlew build

# Run tests (but do not build binaries)
gradlew test

# Build binaries and release it on GitHub
# Environment variable GITHUB_TOKEN is required
gradlew build githubRelease
```

### Build artifacts

* Compiled and lined binaries can be found under ``./build/out/site24x7_exporter-*``

## Contributing

site24x7_exporter is an open source project of [echocat](https://echocat.org).
So if you want to make this project even better, you can contribute to this project on [Github](https://github.com/echocat/site24x7_exporter)
by [fork us](https://github.com/echocat/site24x7_exporter/fork).

If you commit code to this project you have to accept that this code will be released under the [license](#license) of this project.


## License

See [LICENSE](LICENSE) file.
84 changes: 84 additions & 0 deletions Status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package main

import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
)

type Status struct {
CurrentStatus *CurrentStatus
}

func NewStatusFor(currentStatus *CurrentStatus) *Status {
return &Status{
CurrentStatus: currentStatus,
}
}

func (instance *Status) Describe(ch chan<- *prometheus.Desc) {
ch <- instance.Desc()
}

func (instance *Status) Desc() *prometheus.Desc {
return prometheus.NewDesc(
fmt.Sprintf("%s.monitor.status", namespace),
"Was is the status of the target monitor?",
[]string{},
prometheus.Labels{},
)
}

func (instance *Status) Collect(ch chan<- prometheus.Metric) {
for _, monitor := range (*instance).CurrentStatus.Data.Monitors {
element := &StatusElement{
Parent: instance,
Monitor: monitor,
}
ch <- element
}
for _, monitorGroup := range (*instance).CurrentStatus.Data.MonitorGroups {
for _, monitor := range monitorGroup.Monitors {
element := &StatusElement{
Parent: instance,
MonitorGroup: monitorGroup,
Monitor: monitor,
}
ch <- element
}
}
}

type StatusElement struct {
Parent *Status
MonitorGroup CurrentStatusMonitorGroup
Monitor CurrentStatusMonitor
}

func (instance *StatusElement) Write(out *dto.Metric) error {
out.Counter = &dto.Counter{Value: proto.Float64(float64(instance.Monitor.Status))}
label := []*dto.LabelPair{
labelPairFor("monitorId", instance.Monitor.Id),
labelPairFor("monitorDisplayName", instance.Monitor.Name),
}
if instance.MonitorGroup.Id != "" {
label = append(label,
labelPairFor("monitorGroupId", instance.MonitorGroup.Id),
labelPairFor("monitorGroupDisplayName", instance.MonitorGroup.Name),
)
}
out.Label = label
return nil
}

func (instance *StatusElement) Desc() *prometheus.Desc {
return instance.Parent.Desc()
}

func labelPairFor(name string, value string) *dto.LabelPair {
return &dto.LabelPair{
Name: &name,
Value: &value,
}
}
44 changes: 44 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id "org.echocat.golang" version "0.1.2"
id "co.riiid.gradle" version "0.4.2"
}

final name = 'site24x7_exporter'
group 'github.com/echocat/site24x7_exporter'
version '0.1.0'

dependencies {
build 'github.com/prometheus/client_golang'
build 'github.com/beorn7/perks'
build 'github.com/golang/protobuf'
build 'github.com/prometheus/client_model'
build 'github.com/prometheus/common'
build 'github.com/prometheus/procfs'
build 'github.com/matttproud/golang_protobuf_extensions'
}
golang {
build {
useTemporaryGopath = true
definitions = [
"main.name" : name,
"main.version" : version,
"main.group" : group,
]
}
}

github {
owner = 'echocat'
repo = name
token = "${System.getenv('GITHUB_TOKEN')}"
tagName = "v${version}"
targetCommitish = 'master'
name = version
assets = [
'build/out/site24x7_exporter-darwin-amd64',
'build/out/site24x7_exporter-linux-386',
'build/out/site24x7_exporter-linux-amd64',
'build/out/site24x7_exporter-windows-386.exe',
'build/out/site24x7_exporter-windows-amd64.exe',
]
}
Loading

0 comments on commit 0dadff6

Please sign in to comment.