Ejemplo n.º 1
0
    def __init__(self, lock_file_path=None, last_record_path=None):
        """
            1) Open the syslog for writing
            2) Allocate an instance of API class
            3) Set defaults on member variables
        :return:
        """
        syslog.openlog(logoption=(syslog.LOG_PID | syslog.LOG_INFO), facility=syslog.LOG_USER)
        logging.basicConfig(level=logging.DEBUG)
        self.api = tspapi.API()

        # Set our application id from the environment variable
        self.app_id = os.environ['TSI_APP_ID']

        if lock_file_path is not None:
            self.lock_file_path = lock_file_path
        else:
            raise ValueError("Lock file path not specified")

        if last_record_path is not None:
            self.last_record_path = last_record_path
        else:
            raise ValueError("Lock file path not specified")

        self.host = None
        self.user = None
        self.password = None
        self.database = None
        self.connection = None
        self.table = None

        self.get_db_config()
#
#      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.
#
import tspapi
from datetime import datetime

# The following assumes the following environment variables are set
# export TSP_EMAIL='*****@*****.**'
# export TSP_API_TOKEN=<your api token>
api = tspapi.API()

# Create a measurement and let the timestamp by sent by the API:
api.measurement_create(metric='MY_METRIC', source='MySource', value=3.14)

# Create a measurement and set the timestamp
api.measurement_create(metric='MY_METRIC',
                       source='MySource',
                       value=9.80665,
                       timestamp=datetime.now())

# Create a measurement with properties
properties = {"app_id": "myapp"}
api.measurement_create(metric='MY_METRIC',
                       source='MySource',
                       value=22.7,