├── Gopkg.lock ├── Gopkg.toml ├── main.go └── vendor └── github.com ├── coreos └── go-systemd │ ├── .travis.yml │ ├── CONTRIBUTING.md │ ├── DCO │ ├── Gopkg.toml │ ├── Jenkinsfile │ ├── LICENSE │ ├── NOTICE │ ├── README.md │ ├── activation │ ├── common_test.go │ ├── files.go │ ├── files_test.go │ ├── listeners.go │ ├── listeners_test.go │ ├── packetconns.go │ └── packetconns_test.go │ ├── code-of-conduct.md │ ├── daemon │ ├── sdnotify.go │ ├── sdnotify_test.go │ ├── watchdog.go │ └── watchdog_test.go │ ├── dbus │ ├── dbus.go │ ├── dbus_test.go │ ├── methods.go │ ├── methods_test.go │ ├── properties.go │ ├── set.go │ ├── set_test.go │ ├── subscription.go │ ├── subscription_set.go │ ├── subscription_set_test.go │ └── subscription_test.go │ ├── examples │ └── activation │ │ ├── activation.go │ │ ├── httpserver │ │ ├── README.md │ │ ├── hello.service │ │ ├── hello.socket │ │ └── httpserver.go │ │ ├── listen.go │ │ └── udpconn.go │ ├── fixtures │ ├── enable-disable.service │ ├── mask-unmask.service │ ├── reload.service │ ├── start-failed.service │ ├── start-stop.service │ ├── subscribe-events-set.service │ └── subscribe-events.service │ ├── journal │ ├── journal.go │ └── journal_test.go │ ├── login1 │ ├── dbus.go │ └── dbus_test.go │ ├── machine1 │ ├── dbus.go │ └── dbus_test.go │ ├── scripts │ ├── jenkins │ │ └── periodic-go-systemd-builder.sh │ └── travis │ │ └── pr-test.sh │ ├── sdjournal │ ├── functions.go │ ├── functions_test.go │ ├── journal.go │ ├── journal_test.go │ └── read.go │ ├── test │ ├── unit │ ├── deserialize.go │ ├── deserialize_test.go │ ├── end_to_end_test.go │ ├── escape.go │ ├── escape_test.go │ ├── option.go │ ├── option_test.go │ ├── serialize.go │ └── serialize_test.go │ └── util │ ├── util.go │ ├── util_cgo.go │ ├── util_stub.go │ └── util_test.go ├── godbus └── dbus │ ├── .travis.yml │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── MAINTAINERS │ ├── README.markdown │ ├── _examples │ ├── bluetooth_introspect.go │ ├── eavesdrop.go │ ├── introspect.go │ ├── list-names.go │ ├── notification.go │ ├── prop.go │ ├── server.go │ ├── signal.go │ └── tcp_conn.go │ ├── auth.go │ ├── auth_anonymous.go │ ├── auth_external.go │ ├── auth_sha1.go │ ├── call.go │ ├── conn.go │ ├── conn_darwin.go │ ├── conn_other.go │ ├── conn_test.go │ ├── conn_unix.go │ ├── conn_windows.go │ ├── dbus.go │ ├── decoder.go │ ├── decoder_test.go │ ├── default_handler.go │ ├── doc.go │ ├── encoder.go │ ├── encoder_test.go │ ├── examples_test.go │ ├── export.go │ ├── export_test.go │ ├── go.mod │ ├── homedir.go │ ├── homedir_dynamic.go │ ├── homedir_static.go │ ├── introspect │ ├── call.go │ ├── introspect.go │ └── introspectable.go │ ├── message.go │ ├── object.go │ ├── object_test.go │ ├── prop │ └── prop.go │ ├── proto_test.go │ ├── server_interfaces.go │ ├── server_interfaces_test.go │ ├── sig.go │ ├── sig_test.go │ ├── store_test.go │ ├── transport_darwin.go │ ├── transport_generic.go │ ├── transport_nonce_tcp.go │ ├── transport_nonce_tcp_test.go │ ├── transport_tcp.go │ ├── transport_tcp_test.go │ ├── transport_unix.go │ ├── transport_unix_test.go │ ├── transport_unixcred_dragonfly.go │ ├── transport_unixcred_freebsd.go │ ├── transport_unixcred_linux.go │ ├── transport_unixcred_openbsd.go │ ├── variant.go │ ├── variant_lexer.go │ ├── variant_parser.go │ └── variant_test.go └── influxdata └── influxdb1-client ├── LICENSE ├── README.md ├── example_test.go ├── influxdb.go ├── influxdb_test.go ├── models ├── inline_fnv.go ├── inline_fnv_test.go ├── inline_strconv_parse.go ├── inline_strconv_parse_test.go ├── points.go ├── points_internal_test.go ├── points_test.go ├── rows.go ├── statistic.go ├── statistic_test.go ├── time.go └── uint_support.go ├── pkg └── escape │ ├── bytes.go │ ├── bytes_test.go │ ├── strings.go │ └── strings_test.go └── v2 ├── client.go ├── client_test.go ├── example_test.go └── udp.go /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/coreos/go-systemd" 6 | packages = ["dbus"] 7 | revision = "9002847aa1425fb6ac49077c0a630b3b67e0fbfd" 8 | version = "v18" 9 | 10 | [[projects]] 11 | name = "github.com/godbus/dbus" 12 | packages = ["."] 13 | revision = "2ff6f7ffd60f0f2410b3105864bdd12c7894f844" 14 | version = "v5.0.1" 15 | 16 | [[projects]] 17 | branch = "master" 18 | name = "github.com/influxdata/influxdb1-client" 19 | packages = [".","models","pkg/escape"] 20 | revision = "16c852ea613fa2d42fcdccc9a8b0802a8bdc6140" 21 | 22 | [solve-meta] 23 | analyzer-name = "dep" 24 | analyzer-version = 1 25 | inputs-digest = "9ad969b63f11194a738d29560e4c3bc8b213fd8024d36ad567de352343f5ba50" 26 | solver-name = "gps-cdcl" 27 | solver-version = 1 28 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | 2 | # Gopkg.toml example 3 | # 4 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 5 | # for detailed Gopkg.toml documentation. 6 | # 7 | # required = ["github.com/user/thing/cmd/thing"] 8 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 9 | # 10 | # [[constraint]] 11 | # name = "github.com/user/project" 12 | # version = "1.0.0" 13 | # 14 | # [[constraint]] 15 | # name = "github.com/user/project2" 16 | # branch = "dev" 17 | # source = "github.com/myfork/project2" 18 | # 19 | # [[override]] 20 | # name = "github.com/x/y" 21 | # version = "2.4.0" 22 | 23 | 24 | [[constraint]] 25 | name = "github.com/coreos/go-systemd" 26 | version = "18.0.0" 27 | 28 | [[constraint]] 29 | branch = "master" 30 | name = "github.com/influxdata/influxdb1-client" 31 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/url" 7 | "os" 8 | "time" 9 | 10 | "github.com/coreos/go-systemd/dbus" 11 | 12 | client "github.com/influxdata/influxdb1-client" 13 | ) 14 | 15 | func main() { 16 | 17 | conn, err := dbus.New() 18 | 19 | var influxClient *client.Client = initInflux() 20 | 21 | // Ensuring that the connection is closed at some point. 22 | defer conn.Close() 23 | 24 | if err != nil { 25 | fmt.Println("Could not create a new connection object.") 26 | return 27 | } 28 | 29 | // Subscribing to systemd dbus events. 30 | err = conn.Subscribe() 31 | 32 | if err != nil { 33 | fmt.Println("Could not subscribe to the bus.") 34 | return 35 | } 36 | 37 | updateCh := make(chan *dbus.PropertiesUpdate, 256) 38 | errCh := make(chan error, 256) 39 | 40 | // Properties (signals here) changes will be saved to those objects. 41 | conn.SetPropertiesSubscriber(updateCh, errCh) 42 | 43 | for { 44 | select { 45 | case update := <-updateCh: 46 | 47 | var points []client.Point = getPoint(update) 48 | 49 | influxClient.Write(client.BatchPoints{ 50 | Points: points, 51 | Database: "systemd", 52 | RetentionPolicy: "autogen", 53 | Precision: "ms", 54 | WriteConsistency: "any", 55 | }) 56 | 57 | case err := <-errCh: 58 | fmt.Println(err) 59 | } 60 | } 61 | } 62 | 63 | func getPoint(properties *dbus.PropertiesUpdate) []client.Point { 64 | 65 | activeState := properties.Changed["ActiveState"].String() 66 | 67 | var point client.Point = client.Point{ 68 | Measurement: "services", 69 | Tags: map[string]string{ 70 | "service": properties.UnitName, 71 | }, 72 | Fields: map[string]interface{}{ 73 | "state": activeState, 74 | "value": getStateValue(activeState), 75 | }, 76 | // Need to use the timestamp provided by dbus.. 77 | Time: time.Now(), 78 | Precision: "ms", 79 | } 80 | 81 | points := [1]client.Point{point} 82 | 83 | return points[0:1] 84 | 85 | } 86 | 87 | func initInflux() *client.Client { 88 | 89 | host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086)) 90 | if err != nil { 91 | log.Fatal(err) 92 | } 93 | 94 | conf := client.Config{ 95 | URL: *host, 96 | Username: os.Getenv("admin"), 97 | Password: os.Getenv("admin"), 98 | } 99 | 100 | influxConnection, err := client.NewClient(conf) 101 | 102 | if err != nil { 103 | fmt.Println("Error building a new client for InfluxDB.") 104 | } 105 | 106 | return influxConnection 107 | } 108 | 109 | // active (1), reloading, inactive (0), failed (-1), activating, deactivating 110 | func getStateValue(state string) int { 111 | 112 | switch state { 113 | case "\"failed\"": 114 | return -1 115 | case "\"inactive\"": 116 | return 0 117 | case "\"active\"": 118 | return 1 119 | case "\"reloading\"": 120 | return 2 121 | case "\"activating\"": 122 | return 4 123 | case "\"deactivating\"": 124 | return 5 125 | default: 126 | panic("Unhandled dbus active state value") 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | sudo: required 3 | services: 4 | - docker 5 | 6 | language: go 7 | go: 8 | - "1.7.x" 9 | - "1.10.x" 10 | - "1.11.x" 11 | go_import_path: github.com/coreos/go-systemd 12 | 13 | env: 14 | global: 15 | - IMPORTPATH=github.com/coreos/go-systemd 16 | - GOPATH=/opt 17 | - DEP_BINDIR=/tmp 18 | - BUILD_DIR=/opt/src/github.com/coreos/go-systemd 19 | matrix: 20 | - DOCKER_BASE=ubuntu:16.04 21 | - DOCKER_BASE=ubuntu:18.04 22 | - DOCKER_BASE=debian:stretch 23 | 24 | before_install: 25 | - sudo apt-get -qq update 26 | - sudo apt-get install -y libsystemd-journal-dev libsystemd-daemon-dev 27 | - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | INSTALL_DIRECTORY=${DEP_BINDIR} sh 28 | - ${DEP_BINDIR}/dep ensure -v 29 | - docker pull ${DOCKER_BASE} 30 | - docker run --privileged -e GOPATH=${GOPATH} --cidfile=/tmp/cidfile ${DOCKER_BASE} /bin/bash -c "apt-get update && apt-get install -y sudo build-essential git golang dbus libsystemd-dev libpam-systemd systemd-container" 31 | - docker commit `cat /tmp/cidfile` go-systemd/container-tests 32 | - rm -f /tmp/cidfile 33 | 34 | install: 35 | - docker run -d --cidfile=/tmp/cidfile --privileged -e GOPATH=${GOPATH} -v ${PWD}:${BUILD_DIR} go-systemd/container-tests /bin/systemd --system 36 | 37 | script: 38 | - ./scripts/travis/pr-test.sh go_fmt 39 | - ./scripts/travis/pr-test.sh build_source 40 | - ./scripts/travis/pr-test.sh build_tests 41 | - docker exec `cat /tmp/cidfile` /bin/bash -c "cd ${BUILD_DIR} && ./scripts/travis/pr-test.sh run_tests" 42 | - ./scripts/travis/pr-test.sh go_vet 43 | - ./scripts/travis/pr-test.sh license_check 44 | 45 | after_script: 46 | - docker kill `cat /tmp/cidfile` 47 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | CoreOS projects are [Apache 2.0 licensed](LICENSE) and accept contributions via 4 | GitHub pull requests. This document outlines some of the conventions on 5 | development workflow, commit message formatting, contact points and other 6 | resources to make it easier to get your contribution accepted. 7 | 8 | # Certificate of Origin 9 | 10 | By contributing to this project you agree to the Developer Certificate of 11 | Origin (DCO). This document was created by the Linux Kernel community and is a 12 | simple statement that you, as a contributor, have the legal right to make the 13 | contribution. See the [DCO](DCO) file for details. 14 | 15 | # Email and Chat 16 | 17 | The project currently uses the general CoreOS email list and IRC channel: 18 | - Email: [coreos-dev](https://groups.google.com/forum/#!forum/coreos-dev) 19 | - IRC: #[coreos](irc://irc.freenode.org:6667/#coreos) IRC channel on freenode.org 20 | 21 | Please avoid emailing maintainers found in the MAINTAINERS file directly. They 22 | are very busy and read the mailing lists. 23 | 24 | ## Getting Started 25 | 26 | - Fork the repository on GitHub 27 | - Read the [README](README.md) for build and test instructions 28 | - Play with the project, submit bugs, submit patches! 29 | 30 | ## Contribution Flow 31 | 32 | This is a rough outline of what a contributor's workflow looks like: 33 | 34 | - Create a topic branch from where you want to base your work (usually master). 35 | - Make commits of logical units. 36 | - Make sure your commit messages are in the proper format (see below). 37 | - Push your changes to a topic branch in your fork of the repository. 38 | - Make sure the tests pass, and add any new tests as appropriate. 39 | - Submit a pull request to the original repository. 40 | 41 | Thanks for your contributions! 42 | 43 | ### Coding Style 44 | 45 | CoreOS projects written in Go follow a set of style guidelines that we've documented 46 | [here](https://github.com/coreos/docs/tree/master/golang). Please follow them when 47 | working on your contributions. 48 | 49 | ### Format of the Commit Message 50 | 51 | We follow a rough convention for commit messages that is designed to answer two 52 | questions: what changed and why. The subject line should feature the what and 53 | the body of the commit should describe the why. 54 | 55 | ``` 56 | scripts: add the test-cluster command 57 | 58 | this uses tmux to setup a test cluster that you can easily kill and 59 | start for debugging. 60 | 61 | Fixes #38 62 | ``` 63 | 64 | The format can be described more formally as follows: 65 | 66 | ``` 67 | : 68 | 69 | 70 | 71 |